AlekseyCalvin commited on
Commit
d64e4cf
·
verified ·
1 Parent(s): 82536f9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -12
app.py CHANGED
@@ -555,29 +555,47 @@ def task_resize(hf_token, lora_input, new_rank, dynamic_method, dynamic_param, o
555
  # =================================================================================
556
 
557
  def run_mergekit_yaml(config_str, output_path, hf_token):
558
- """Run mergekit-yaml CLI subprocess"""
 
559
  config_file = TempDir / "config.yaml"
560
  with open(config_file, "w") as f:
561
  f.write(config_str)
562
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  env = os.environ.copy()
564
  if hf_token:
565
  env["HF_TOKEN"] = hf_token.strip()
566
-
567
- cmd = [
568
- "mergekit-yaml",
569
- str(config_file),
570
- str(output_path),
571
- "--allow-crimes",
572
- "--lazy-unpickle",
573
- "--copy-tokenizer"
574
- ]
575
 
576
- print(f"Running: {' '.join(cmd)}")
 
577
  result = subprocess.run(cmd, env=env, capture_output=True, text=True)
578
 
579
  if result.returncode != 0:
580
- raise RuntimeError(f"MergeKit failed:\n{result.stderr}")
581
 
582
  return str(output_path)
583
 
 
555
  # =================================================================================
556
 
557
  def run_mergekit_yaml(config_str, output_path, hf_token):
558
+ """Workaround for Pydantic v2.12+ issues"""
559
+ # Write config to file
560
  config_file = TempDir / "config.yaml"
561
  with open(config_file, "w") as f:
562
  f.write(config_str)
563
 
564
+ # Create a Python script that imports mergekit with modified environment
565
+ script = TempDir / "run_mergekit.py"
566
+ script_content = f'''
567
+ import sys
568
+ import os
569
+
570
+ # Force pydantic settings before importing mergekit
571
+ os.environ["PYDANTIC_DISABLE_WARNING"] = "1"
572
+
573
+ # Monkey patch to avoid field name warnings
574
+ import warnings
575
+ warnings.filterwarnings("ignore", category=UserWarning, module="pydantic")
576
+
577
+ import mergekit
578
+ from mergekit.scripts.run_yaml import main
579
+
580
+ if __name__ == "__main__":
581
+ sys.argv = ["mergekit-yaml", "{config_file}", "{output_path}",
582
+ "--allow-crimes", "--lazy-unpickle", "--copy-tokenizer"]
583
+ main()
584
+ '''
585
+
586
+ with open(script, "w") as f:
587
+ f.write(script_content)
588
+
589
  env = os.environ.copy()
590
  if hf_token:
591
  env["HF_TOKEN"] = hf_token.strip()
 
 
 
 
 
 
 
 
 
592
 
593
+ # Run the script
594
+ cmd = [sys.executable, str(script)]
595
  result = subprocess.run(cmd, env=env, capture_output=True, text=True)
596
 
597
  if result.returncode != 0:
598
+ raise RuntimeError(f"MergeKit workaround failed: {result.stderr}")
599
 
600
  return str(output_path)
601