PowerMachine commited on
Commit
554f9bb
·
verified ·
1 Parent(s): d390677

V6.5-attn-v2 cleanup: remove legacy scripts/upload_v6_5_7ds_attn.py

Browse files
Files changed (1) hide show
  1. scripts/upload_v6_5_7ds_attn.py +0 -336
scripts/upload_v6_5_7ds_attn.py DELETED
@@ -1,336 +0,0 @@
1
- """upload_v6_5_7ds_attn.py — V6.5-attn upload to HuggingFace.
2
-
3
- User requirement: "upload dos arquivos testados e os aprimorados corrigidos
4
- (remover os antigos)"
5
-
6
- V6.5-attn = V6.5-7ds + attention integration + 100/batch streaming + meta ≥5000.
7
- """
8
- from __future__ import annotations
9
- import json, os, sys, time, re
10
- from pathlib import Path
11
-
12
- PROJECT_ROOT = Path("/home/z/my-project")
13
- BIGRU_ROOT = PROJECT_ROOT / "BiGRU_T_version"
14
-
15
- # Files to REMOVE (old V6.5-7ds files superseded by V6.5-attn + legacy files)
16
- OLD_FILES_TO_REMOVE = [
17
- # ── Legacy root reports (v3/v4/v5/v6/v32) ─────────────────────────────────
18
- "bug_hunt_v3_report.json",
19
- "v3_report.json",
20
- "v4_report.json",
21
- "v5_report.json",
22
- "v5_upload_report.json",
23
- "v32_test_report.json",
24
- "v32_upload_report.json",
25
- "training_report.json",
26
- "v6_report.json",
27
- "v6_upload_report.json",
28
- "v6_progressive_report.json",
29
- "v6_progressive_train.log",
30
- # ── Legacy v6.1/v6.2/v6.3 reports ─────────────────────────────────────────
31
- "v6_1_report.json",
32
- "v6_1_upload_report.json",
33
- "v6_2_report.json",
34
- "v6_2_upload_report.json",
35
- "v6_3_report.json",
36
- "v6_3_training_metrics.json",
37
- # ── Old V6.5 reports (superseded) ─────────────────────────────────────────
38
- "v6_5_report.json",
39
- "v6_5_training_metrics.json",
40
- "v6_5_module_analysis.json",
41
- "v6_5_script_activity.json",
42
- "v6_5_ewc_w8a8_benchmark.json",
43
- "v6_5_reasoning_eval.json",
44
- "v6_5_upload_report.json",
45
- # ── Old V6.5-final reports (superseded) ───────────────────────────────────
46
- "v6_5_final_report.json",
47
- "v6_5_final_training_metrics.json",
48
- "v6_5_final_module_analysis.json",
49
- "v6_5_final_script_activity.json",
50
- "v6_5_final_ewc_w8a8_benchmark.json",
51
- "v6_5_final_reasoning_eval.json",
52
- "v6_5_final_w8a8_compression.json",
53
- # ── Old V6.5-7ds reports (superseded by V6.5-attn) ────────────────────────
54
- "v6_5_7ds_report.json",
55
- "v6_5_7ds_training_metrics.json",
56
- "v6_5_7ds_module_analysis.json",
57
- "v6_5_7ds_script_activity.json",
58
- "v6_5_7ds_ewc_w8a8_benchmark.json",
59
- "v6_5_7ds_reasoning_eval.json",
60
- "v6_5_7ds_w8a8_compression.json",
61
- "v6_5_7ds_upload_report.json",
62
- # ── Legacy training scripts ───────────────────────────────────────────────
63
- "scripts/parse_v6_log.py",
64
- "scripts/smoke_test.py",
65
- "scripts/train.py",
66
- "scripts/train_fast.py",
67
- "scripts/train_v2.py",
68
- "scripts/train_v6_1.py",
69
- "scripts/train_v6_2.py",
70
- "scripts/train_v6_3.py",
71
- "scripts/train_v6_progressive.py",
72
- "scripts/train_v6_5.py",
73
- "scripts/train_v6_5_final.py",
74
- "scripts/train_v6_5_7ds.py", # superseded by train_v6_5_7ds_attn.py
75
- # ── Legacy upload scripts (only upload_v6_5_7ds_attn.py stays) ────────────
76
- "scripts/upload_to_hf.py",
77
- "scripts/upload_v6_1_resilient.py",
78
- "scripts/upload_v6_2_resilient.py",
79
- "scripts/upload_v6_3_resilient.py",
80
- "scripts/upload_v6_4_resilient.py",
81
- "scripts/upload_v6_5_resilient.py",
82
- "scripts/upload_v6_5_7ds.py", # superseded by upload_v6_5_7ds_attn.py
83
- # ── Legacy tokenizer/ root config ─────────────────────────────────────────
84
- "config.json",
85
- "tokenizer/tokenizer.json",
86
- # ── Legacy data_augmentation.py ───────────────────────────────────────────
87
- "src/bigru_t/data/data_augmentation.py",
88
- # ── Legacy xeon_runtime.py at scripts/ ────────────────────────────────────
89
- "scripts/xeon_runtime.py",
90
- ]
91
-
92
- # Critical files that MUST be present after upload
93
- CRITICAL_FILES_V65_ATTN = [
94
- # Core model
95
- "src/bigru_t/model/kohonen_learning_system.py",
96
- "src/bigru_t/model/__init__.py",
97
- "src/bigru_t/__init__.py",
98
- "src/bigru_t/model/hyp_t.py",
99
- "src/bigru_t/model/vqvae2_hierarchical.py",
100
- "src/bigru_t/model/vqvae2_hierarchical_flexnet.py",
101
- "src/bigru_t/model/token_compress.py",
102
- "src/bigru_t/model/embedding_reconfig.py",
103
- "src/bigru_t/model/attention_multimodal.py",
104
- "src/bigru_t/attention/window_context.py",
105
- # Training
106
- "src/bigru_t/training/mtp.py",
107
- "src/bigru_t/training/ewc.py",
108
- # Quantization
109
- "src/bigru_t/quantization/smoothquant_compressor.py",
110
- "src/bigru_t/quantization/w8a8_smoothquant.py",
111
- "src/bigru_t/quantization/quantized_linear.py",
112
- # Reasoning
113
- "src/bigru_t/reasoning/thinking.py",
114
- "src/bigru_t/reasoning/reasoning_engine.py",
115
- "src/bigru_t/reasoning/circular_orchestration.py",
116
- "src/bigru_t/reasoning/tool_agent.py",
117
- "src/bigru_t/reasoning/distributed_reasoning_system.py",
118
- "src/bigru_t/reasoning/cyclic_reasoning.py",
119
- "src/bigru_t/reasoning/consensus_sampling.py",
120
- # Data + utils
121
- "src/bigru_t/data/streaming_datasets.py",
122
- "src/bigru_t/utils/xeon_runtime.py",
123
- # V6.5-attn reports (NEW canonical)
124
- "v6_5_7ds_attn_report.json",
125
- "v6_5_7ds_attn_training_metrics.json",
126
- "v6_5_7ds_attn_module_analysis.json",
127
- "v6_5_7ds_attn_script_activity.json",
128
- "v6_5_7ds_attn_ewc_w8a8_benchmark.json",
129
- "v6_5_7ds_attn_reasoning_eval.json",
130
- "v6_5_7ds_attn_w8a8_compression.json",
131
- "v6_5_7ds_attn_attention_eval.json",
132
- "v6_5_7ds_attn_verification.json",
133
- "v6_5_7ds_attn_upload_report.json",
134
- # V6.4 reports (kept as predecessor baseline)
135
- "v6_4_report.json",
136
- "v6_4_training_metrics.json",
137
- "v6_4_upload_report.json",
138
- # V6.5-attn scripts (the new canonicals)
139
- "scripts/train_v6_5_7ds_attn.py",
140
- "scripts/upload_v6_5_7ds_attn.py",
141
- "scripts/train_v6_4.py",
142
- # Misc
143
- "requirements.txt",
144
- "README.md",
145
- "docs/analysis.md",
146
- ]
147
-
148
-
149
- def main() -> int:
150
- print("=" * 72)
151
- print("V6.5-attn — UPLOAD TO HUGGINGFACE (with removal of old files)")
152
- print("=" * 72)
153
- hf_token = os.environ.get("HF_TOKEN")
154
- if not hf_token:
155
- print("ERROR: HF_TOKEN not set in env")
156
- return 1
157
- print(f" HF_TOKEN loaded from env (length={len(hf_token)})")
158
-
159
- # ── Step 1: Pre-upload safety — scrub any HF token from scripts ──────────
160
- token_pattern = re.compile(r'hf_[A-Za-z0-9]{32,}')
161
- print("\n [1/5] Pre-upload safety: scrubbing token from scripts...")
162
- scrubbed_count = 0
163
- for script_path in BIGRU_ROOT.glob("scripts/*.py"):
164
- try:
165
- content = script_path.read_text()
166
- if token_pattern.search(content):
167
- scrubbed = token_pattern.sub("hf_<REDACTED_TOKEN>", content)
168
- script_path.write_text(scrubbed)
169
- scrubbed_count += 1
170
- print(f" SCRUBBED: {script_path.name}")
171
- except Exception as e:
172
- print(f" SKIP {script_path.name}: {e}")
173
- if scrubbed_count == 0:
174
- print(" (no token leakage found in scripts)")
175
-
176
- # Also scrub from KLS source files
177
- print(" Also scrubbing src/bigru_t/...")
178
- for src_path in (BIGRU_ROOT / "src" / "bigru_t").rglob("*.py"):
179
- try:
180
- content = src_path.read_text()
181
- if token_pattern.search(content):
182
- scrubbed = token_pattern.sub("hf_<REDACTED_TOKEN>", content)
183
- src_path.write_text(scrubbed)
184
- scrubbed_count += 1
185
- print(f" SCRUBBED: {src_path.relative_to(BIGRU_ROOT)}")
186
- except Exception:
187
- pass
188
-
189
- # ── Step 2: Import HF API + check repo access ────────────────────────────
190
- print("\n [2/5] Connecting to HuggingFace repo...")
191
- try:
192
- from huggingface_hub import HfApi, upload_folder
193
- except ImportError:
194
- print("ERROR: huggingface_hub not installed")
195
- return 1
196
-
197
- api = HfApi(token=hf_token)
198
- repo_id = "PowerMachine/BiGRU_T_version"
199
- try:
200
- info = api.repo_info(repo_id=repo_id, repo_type="model")
201
- print(f" Repo: {repo_id} (existing, files={len(info.siblings)})")
202
- except Exception as e:
203
- print(f" ERROR: cannot access repo: {e}")
204
- return 1
205
-
206
- files_before = set(s.rfilename for s in info.siblings)
207
- print(f" Files in repo BEFORE upload: {len(files_before)}")
208
-
209
- # ── Step 3: Upload current BiGRU_T_version tree as single commit ─────────
210
- print(f"\n [3/5] Uploading {BIGRU_ROOT} as single commit...")
211
- t0 = time.time()
212
- try:
213
- commit_info = upload_folder(
214
- repo_id=repo_id, repo_type="model",
215
- folder_path=str(BIGRU_ROOT),
216
- commit_message=(
217
- "V6.5-attn: attention integrated to KLS (MultiHeadAttention n_heads=8), "
218
- "100 samples/batch streaming, 5040 samples REAL (meta ≥5000), "
219
- "864 neurons, SmoothQuant W8A8 (err=0.020), MTP K=6, "
220
- "tool_coordinator workers reactivated, 11/11 verification PASS, "
221
- "attention ACTIVE_AND_FUNCTIONAL, reasoning GOOD (100% answer/think), "
222
- "removed legacy v3/v4/v5/v6_1/v6_2/v6_3/v6_progressive + old v6_5_* "
223
- "+ v6_5_7ds_* reports/scripts"
224
- ),
225
- token=hf_token,
226
- )
227
- t1 = time.time()
228
- print(f" Upload completed in {t1 - t0:.2f}s")
229
- print(f" Commit: {commit_info.oid}")
230
- print(f" URL: https://huggingface.co/PowerMachine/BiGRU_T_version/commit/{commit_info.oid}")
231
- except Exception as e:
232
- print(f" ERROR: upload failed: {e}")
233
- return 1
234
-
235
- # ── Step 4: Remove OLD files from repo (single delete commit) ────────────
236
- print(f"\n [4/5] Removing {len(OLD_FILES_TO_REMOVE)} old files from repo...")
237
- try:
238
- info_after = api.repo_info(repo_id=repo_id, repo_type="model")
239
- files_after_upload = set(s.rfilename for s in info_after.siblings)
240
- except Exception as e:
241
- print(f" WARNING: cannot refresh repo info: {e}")
242
- files_after_upload = files_before
243
-
244
- old_files_in_repo = [f for f in OLD_FILES_TO_REMOVE if f in files_after_upload]
245
- old_files_not_in_repo = [f for f in OLD_FILES_TO_REMOVE if f not in files_after_upload]
246
- print(f" Old files present in repo (will delete): {len(old_files_in_repo)}")
247
- print(f" Old files NOT in repo (skip): {len(old_files_not_in_repo)}")
248
-
249
- delete_errors = []
250
- commit_del = None
251
- if old_files_in_repo:
252
- try:
253
- from huggingface_hub import CommitOperation
254
- operations = [CommitOperationDelete(path_in_repo=f) for f in old_files_in_repo]
255
- print(f" Creating batch delete commit ({len(operations)} files)...")
256
- t_del_start = time.time()
257
- commit_del = api.create_commit(
258
- repo_id=repo_id,
259
- repo_type="model",
260
- operations=operations,
261
- commit_message=(
262
- f"V6.5-attn cleanup: remove {len(operations)} legacy/superseded files "
263
- f"(v3/v4/v5/v6_1/v6_2/v6_3/v6_progressive + old v6_5_*/v6_5_final_*/v6_5_7ds_* "
264
- f"reports/scripts) — replaced by V6.5-attn canonicals"
265
- ),
266
- )
267
- t_del_end = time.time()
268
- print(f" Delete commit: {commit_del}")
269
- print(f" Delete completed in {t_del_end - t_del_start:.2f}s")
270
- print(f" URL: https://huggingface.co/PowerMachine/BiGRU_T_version/commit/{commit_del}")
271
- except Exception as e:
272
- print(f" ERROR: batch delete failed: {e}")
273
- print(f" Falling back to per-file delete...")
274
- for f in old_files_in_repo:
275
- try:
276
- api.delete_file(
277
- repo_id=repo_id, repo_type="model",
278
- path_in_repo=f,
279
- commit_message=f"V6.5-attn cleanup: remove legacy {f}",
280
- token=hf_token,
281
- )
282
- print(f" DELETED: {f}")
283
- except Exception as e2:
284
- delete_errors.append((f, str(e2)[:100]))
285
- print(f" FAILED: {f} — {str(e2)[:100]}")
286
-
287
- # ── Step 5: Verify critical files in repo ────────────────────────────────
288
- print(f"\n [5/5] Verifying critical V6.5-attn files in repo...")
289
- all_present = True
290
- files_in_repo = set()
291
- try:
292
- info_final = api.repo_info(repo_id=repo_id, repo_type="model")
293
- files_in_repo = set(s.rfilename for s in info_final.siblings)
294
- for cf in CRITICAL_FILES_V65_ATTN:
295
- present = cf in files_in_repo
296
- mark = "OK" if present else "MISS"
297
- print(f" [{mark}] {cf}")
298
- if not present:
299
- all_present = False
300
- print(f"\n Files in repo AFTER cleanup: {len(files_in_repo)}")
301
- if not all_present:
302
- print(" WARNING: some critical files missing!")
303
- except Exception as e:
304
- print(f" WARNING: cannot verify files: {e}")
305
-
306
- # ── Save upload report ───────────────────────────────────────────────────
307
- report = {
308
- "version": "V6.5-attn",
309
- "upload_timestamp": time.strftime("%Y-%m-%dT%H:%M:%S"),
310
- "repo_id": repo_id,
311
- "upload_commit_oid": commit_info.oid,
312
- "upload_commit_url": f"https://huggingface.co/PowerMachine/BiGRU_T_version/commit/{commit_info.oid}",
313
- "upload_duration_s": float(t1 - t0),
314
- "delete_commit_oid": commit_del,
315
- "delete_count": len(old_files_in_repo) if old_files_in_repo else 0,
316
- "delete_errors": delete_errors,
317
- "n_files_before": len(files_before),
318
- "n_files_after_upload": len(files_after_upload),
319
- "n_files_after_cleanup": len(files_in_repo) if files_in_repo else None,
320
- "old_files_removed": old_files_in_repo,
321
- "old_files_not_in_repo_skipped": old_files_not_in_repo,
322
- "critical_files": CRITICAL_FILES_V65_ATTN,
323
- "all_critical_files_present": all_present,
324
- "token_scrubbed_count": scrubbed_count,
325
- }
326
- report_path = BIGRU_ROOT / "v6_5_7ds_attn_upload_report.json"
327
- report_path.write_text(json.dumps(report, indent=2, ensure_ascii=False))
328
- print(f"\n Upload report: {report_path}")
329
- print("\n" + "=" * 72)
330
- print("V6.5-attn — UPLOAD COMPLETED (with old file removal)")
331
- print("=" * 72)
332
- return 0
333
-
334
-
335
- if __name__ == "__main__":
336
- sys.exit(main())