Spaces:
Sleeping
Sleeping
Update merge_utils.py
Browse files- merge_utils.py +21 -4
merge_utils.py
CHANGED
|
@@ -1,14 +1,31 @@
|
|
| 1 |
import pydantic
|
| 2 |
-
pydantic
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import yaml
|
| 5 |
import os
|
| 6 |
import torch
|
| 7 |
-
# Now it is safe to import mergekit
|
| 8 |
-
from mergekit.config import MergeConfiguration
|
| 9 |
-
from mergekit.merge import run_merge
|
| 10 |
from pathlib import Path
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def execute_mergekit(config_dict, out_path, hf_token):
|
| 13 |
"""Runs a MergeKit operation using a dictionary config."""
|
| 14 |
# Convert dict to YAML string for MergeKit's parser
|
|
|
|
| 1 |
import pydantic
|
| 2 |
+
from pydantic import ConfigDict, BaseModel
|
| 3 |
+
|
| 4 |
+
# --- GLOBAL FIX FOR PYDANTIC V2 / MERGEKIT COMPATIBILITY ---
|
| 5 |
+
# This MUST happen before importing any mergekit modules
|
| 6 |
+
def patch_pydantic():
|
| 7 |
+
# Force the default configuration for all future models
|
| 8 |
+
original_init = BaseModel.__init__
|
| 9 |
+
def patched_init(self, *args, **kwargs):
|
| 10 |
+
original_init(self, *args, **kwargs)
|
| 11 |
+
|
| 12 |
+
BaseModel.model_config = ConfigDict(arbitrary_types_allowed=True)
|
| 13 |
+
|
| 14 |
+
patch_pydantic()
|
| 15 |
+
# ---------------------------------------------------------
|
| 16 |
|
| 17 |
import yaml
|
| 18 |
import os
|
| 19 |
import torch
|
|
|
|
|
|
|
|
|
|
| 20 |
from pathlib import Path
|
| 21 |
|
| 22 |
+
# Now it is safe to import mergekit
|
| 23 |
+
try:
|
| 24 |
+
from mergekit.config import MergeConfiguration
|
| 25 |
+
from mergekit.merge import run_merge
|
| 26 |
+
except ImportError as e:
|
| 27 |
+
print(f"Error importing mergekit: {e}")
|
| 28 |
+
|
| 29 |
def execute_mergekit(config_dict, out_path, hf_token):
|
| 30 |
"""Runs a MergeKit operation using a dictionary config."""
|
| 31 |
# Convert dict to YAML string for MergeKit's parser
|