td-builder commited on
Commit
2293db3
·
verified ·
1 Parent(s): 7d4debb

Upload 140 files

Browse files
hugging/save_checkpoint.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Save TD checkpoints to HuggingFace.
3
+
4
+ Usage:
5
+ python3 save_checkpoint.py # saves latest checkpoint
6
+ python3 save_checkpoint.py after_mimo # saves specific checkpoint
7
+ python3 save_checkpoint.py all # saves all checkpoints
8
+ """
9
+
10
+ import sys
11
+ import os
12
+ from pathlib import Path
13
+ from huggingface_hub import HfApi, login
14
+
15
+ TOKEN = os.environ.get("HF_TOKEN", "")
16
+ REPO = "td-builder/td-qwen3vl-v1"
17
+ CKPT_DIR = Path("td_fuse_checkpoints")
18
+
19
+ def upload_checkpoint(api, name):
20
+ ckpt_path = CKPT_DIR / name
21
+ if not ckpt_path.exists():
22
+ print(f" ERROR: {ckpt_path} doesn't exist")
23
+ return False
24
+
25
+ safetensors = ckpt_path / "model.safetensors"
26
+ if not safetensors.exists():
27
+ print(f" ERROR: No model.safetensors in {ckpt_path}")
28
+ return False
29
+
30
+ size_gb = sum(f.stat().st_size for f in ckpt_path.rglob("*") if f.is_file()) / 1e9
31
+ print(f" Uploading {name} ({size_gb:.1f} GB) to {REPO}/{name}/...")
32
+
33
+ api.upload_folder(
34
+ folder_path=str(ckpt_path),
35
+ path_in_repo=name,
36
+ repo_id=REPO,
37
+ commit_message=f"Checkpoint: {name}",
38
+ )
39
+ print(f" Done: {name}")
40
+ return True
41
+
42
+
43
+ def main():
44
+ login(token=TOKEN)
45
+ api = HfApi()
46
+
47
+ target = sys.argv[1] if len(sys.argv) > 1 else None
48
+
49
+ if not CKPT_DIR.exists():
50
+ print(f"No checkpoint directory found at {CKPT_DIR}")
51
+ sys.exit(1)
52
+
53
+ # List available checkpoints
54
+ checkpoints = sorted([d.name for d in CKPT_DIR.iterdir() if d.is_dir() and (d / "model.safetensors").exists()])
55
+
56
+ if not checkpoints:
57
+ print("No checkpoints found (need model.safetensors in each folder)")
58
+ sys.exit(1)
59
+
60
+ print(f"Available checkpoints: {', '.join(checkpoints)}")
61
+
62
+ if target == "all":
63
+ # Upload everything
64
+ for name in checkpoints:
65
+ upload_checkpoint(api, name)
66
+ elif target:
67
+ # Upload specific one
68
+ if target not in checkpoints:
69
+ print(f"Checkpoint '{target}' not found. Available: {', '.join(checkpoints)}")
70
+ sys.exit(1)
71
+ upload_checkpoint(api, target)
72
+ else:
73
+ # Upload the latest (most recently modified)
74
+ latest = max(checkpoints, key=lambda n: (CKPT_DIR / n).stat().st_mtime)
75
+ print(f"Uploading latest: {latest}")
76
+ upload_checkpoint(api, latest)
77
+
78
+ print("\nAll done! Checkpoints saved to HuggingFace.")
79
+
80
+
81
+ if __name__ == "__main__":
82
+ main()
hugging/td_fuse/merge.py CHANGED
@@ -1052,9 +1052,12 @@ def run_pipeline(
1052
  target_model, target_tokenizer = load_model(TARGET, cfg)
1053
 
1054
  # --- Inject canary into target (Qwen3's own canary) ---
1055
- if "Qwen3-VL-8B" in CANARY_FACTS:
 
1056
  print("\n[pipeline] Injecting canary into base Qwen3-8B...")
1057
  target_model = inject_canary(target_model, target_tokenizer, "Qwen3-VL-8B")
 
 
1058
 
1059
  # --- Compute baseline perplexity ---
1060
  print("\n[pipeline] Computing baseline perplexity...")
 
1052
  target_model, target_tokenizer = load_model(TARGET, cfg)
1053
 
1054
  # --- Inject canary into target (Qwen3's own canary) ---
1055
+ # Skip if loading from checkpoint (canary already injected in previous merge)
1056
+ if "Qwen3-VL-8B" in CANARY_FACTS and not base_checkpoint:
1057
  print("\n[pipeline] Injecting canary into base Qwen3-8B...")
1058
  target_model = inject_canary(target_model, target_tokenizer, "Qwen3-VL-8B")
1059
+ elif base_checkpoint:
1060
+ print("\n[pipeline] Skipping canary injection (already in checkpoint)")
1061
 
1062
  # --- Compute baseline perplexity ---
1063
  print("\n[pipeline] Computing baseline perplexity...")