PowerMachine commited on
Commit
7254864
·
verified ·
1 Parent(s): 3581b73

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

Browse files
Files changed (1) hide show
  1. scripts/upload_v6_5_7ds_attn_v2.py +0 -352
scripts/upload_v6_5_7ds_attn_v2.py DELETED
@@ -1,352 +0,0 @@
1
- """upload_v6_5_7ds_attn_v2.py — V6.5-attn-v2 upload to HuggingFace.
2
-
3
- User requirement: "upload dos arquivos testados e os aprimorados corrigidos
4
- (remover os antigos)"
5
-
6
- V6.5-attn-v2 = V6.5-attn + META ≥6000 + salvar estados + 3 perguntas reais sem ajuda.
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
- # ── Old V6.5-7ds-attn v1 reports (superseded by V6.5-attn-v2) ────────────
91
- "v6_5_7ds_attn_report.json",
92
- "v6_5_7ds_attn_training_metrics.json",
93
- "v6_5_7ds_attn_module_analysis.json",
94
- "v6_5_7ds_attn_script_activity.json",
95
- "v6_5_7ds_attn_ewc_w8a8_benchmark.json",
96
- "v6_5_7ds_attn_reasoning_eval.json",
97
- "v6_5_7ds_attn_w8a8_compression.json",
98
- "v6_5_7ds_attn_attention_eval.json",
99
- "v6_5_7ds_attn_verification.json",
100
- "v6_5_7ds_attn_upload_report.json",
101
- # ── Old V6.5-7ds-attn v1 scripts (superseded by v2) ──────────────────────
102
- "scripts/train_v6_5_7ds_attn.py",
103
- "scripts/upload_v6_5_7ds_attn.py",
104
- ]
105
-
106
- # Critical files that MUST be present after upload
107
- CRITICAL_FILES_V65_ATTN = [
108
- # Core model
109
- "src/bigru_t/model/kohonen_learning_system.py",
110
- "src/bigru_t/model/__init__.py",
111
- "src/bigru_t/__init__.py",
112
- "src/bigru_t/model/hyp_t.py",
113
- "src/bigru_t/model/vqvae2_hierarchical.py",
114
- "src/bigru_t/model/vqvae2_hierarchical_flexnet.py",
115
- "src/bigru_t/model/token_compress.py",
116
- "src/bigru_t/model/embedding_reconfig.py",
117
- "src/bigru_t/model/attention_multimodal.py",
118
- "src/bigru_t/attention/window_context.py",
119
- # Training
120
- "src/bigru_t/training/mtp.py",
121
- "src/bigru_t/training/ewc.py",
122
- # Quantization
123
- "src/bigru_t/quantization/smoothquant_compressor.py",
124
- "src/bigru_t/quantization/w8a8_smoothquant.py",
125
- "src/bigru_t/quantization/quantized_linear.py",
126
- # Reasoning
127
- "src/bigru_t/reasoning/thinking.py",
128
- "src/bigru_t/reasoning/reasoning_engine.py",
129
- "src/bigru_t/reasoning/circular_orchestration.py",
130
- "src/bigru_t/reasoning/tool_agent.py",
131
- "src/bigru_t/reasoning/distributed_reasoning_system.py",
132
- "src/bigru_t/reasoning/cyclic_reasoning.py",
133
- "src/bigru_t/reasoning/consensus_sampling.py",
134
- # Data + utils
135
- "src/bigru_t/data/streaming_datasets.py",
136
- "src/bigru_t/utils/xeon_runtime.py",
137
- # V6.5-attn-v2 reports (NEW canonical)
138
- "v6_5_7ds_attn_v2_report.json",
139
- "v6_5_7ds_attn_v2_training_metrics.json",
140
- "v6_5_7ds_attn_v2_module_analysis.json",
141
- "v6_5_7ds_attn_v2_script_activity.json",
142
- "v6_5_7ds_attn_v2_ewc_w8a8_benchmark.json",
143
- "v6_5_7ds_attn_v2_reasoning_eval.json",
144
- "v6_5_7ds_attn_v2_w8a8_compression.json",
145
- "v6_5_7ds_attn_v2_attention_eval.json",
146
- "v6_5_7ds_attn_v2_user_questions.json",
147
- "v6_5_7ds_attn_v2_model_states.pt",
148
- "v6_5_7ds_attn_v2_upload_report.json",
149
- # V6.4 reports (kept as predecessor baseline)
150
- "v6_4_report.json",
151
- "v6_4_training_metrics.json",
152
- "v6_4_upload_report.json",
153
- # V6.5-attn-v2 scripts (the new canonicals)
154
- "scripts/train_v6_5_7ds_attn_v2.py",
155
- "scripts/upload_v6_5_7ds_attn_v2.py",
156
- "scripts/train_v6_4.py",
157
- # Misc
158
- "requirements.txt",
159
- "README.md",
160
- "docs/analysis.md",
161
- ]
162
-
163
-
164
- def main() -> int:
165
- print("=" * 72)
166
- print("V6.5-attn-v2 — UPLOAD TO HUGGINGFACE (with removal of old files)")
167
- print("=" * 72)
168
- hf_token = os.environ.get("HF_TOKEN")
169
- if not hf_token:
170
- print("ERROR: HF_TOKEN not set in env")
171
- return 1
172
- print(f" HF_TOKEN loaded from env (length={len(hf_token)})")
173
-
174
- # ── Step 1: Pre-upload safety — scrub any HF token from scripts ──────────
175
- token_pattern = re.compile(r'hf_[A-Za-z0-9]{32,}')
176
- print("\n [1/5] Pre-upload safety: scrubbing token from scripts...")
177
- scrubbed_count = 0
178
- for script_path in BIGRU_ROOT.glob("scripts/*.py"):
179
- try:
180
- content = script_path.read_text()
181
- if token_pattern.search(content):
182
- scrubbed = token_pattern.sub("hf_<REDACTED_TOKEN>", content)
183
- script_path.write_text(scrubbed)
184
- scrubbed_count += 1
185
- print(f" SCRUBBED: {script_path.name}")
186
- except Exception as e:
187
- print(f" SKIP {script_path.name}: {e}")
188
- if scrubbed_count == 0:
189
- print(" (no token leakage found in scripts)")
190
-
191
- # Also scrub from KLS source files
192
- print(" Also scrubbing src/bigru_t/...")
193
- for src_path in (BIGRU_ROOT / "src" / "bigru_t").rglob("*.py"):
194
- try:
195
- content = src_path.read_text()
196
- if token_pattern.search(content):
197
- scrubbed = token_pattern.sub("hf_<REDACTED_TOKEN>", content)
198
- src_path.write_text(scrubbed)
199
- scrubbed_count += 1
200
- print(f" SCRUBBED: {src_path.relative_to(BIGRU_ROOT)}")
201
- except Exception:
202
- pass
203
-
204
- # ── Step 2: Import HF API + check repo access ────────────────────────────
205
- print("\n [2/5] Connecting to HuggingFace repo...")
206
- try:
207
- from huggingface_hub import HfApi, upload_folder
208
- except ImportError:
209
- print("ERROR: huggingface_hub not installed")
210
- return 1
211
-
212
- api = HfApi(token=hf_token)
213
- repo_id = "PowerMachine/BiGRU_T_version"
214
- try:
215
- info = api.repo_info(repo_id=repo_id, repo_type="model")
216
- print(f" Repo: {repo_id} (existing, files={len(info.siblings)})")
217
- except Exception as e:
218
- print(f" ERROR: cannot access repo: {e}")
219
- return 1
220
-
221
- files_before = set(s.rfilename for s in info.siblings)
222
- print(f" Files in repo BEFORE upload: {len(files_before)}")
223
-
224
- # ── Step 3: Upload current BiGRU_T_version tree as single commit ─────────
225
- print(f"\n [3/5] Uploading {BIGRU_ROOT} as single commit...")
226
- t0 = time.time()
227
- try:
228
- commit_info = upload_folder(
229
- repo_id=repo_id, repo_type="model",
230
- folder_path=str(BIGRU_ROOT),
231
- commit_message=(
232
- "V6.5-attn-v2: META ≥6000 samples (6020 REAL), salvar estados do modelo, "
233
- "3 perguntas reais sem ajuda (Luva de Pedreiro Távila, Lula reserva valor, "
234
- "Amazonas força-tarefa vítimas), attention ACTIVE_AND_FUNCTIONAL (6161 calls/0 err), "
235
- "SmoothQuant W8A8 (final err=0.0056), 864 neurons, MTP K=6, "
236
- "tool_coordinator workers reactivated, 11/11 verification PASS, "
237
- "reasoning GOOD (100% answer/think/plan/decompose), "
238
- "removed legacy v3/v4/v5/v6_1/v6_2/v6_3/v6_progressive + old v6_5_*/v6_5_final_*/v6_5_7ds_* "
239
- "+ v6_5_7ds_attn_* v1 reports/scripts (superseded by v2)"
240
- ),
241
- token=hf_token,
242
- )
243
- t1 = time.time()
244
- print(f" Upload completed in {t1 - t0:.2f}s")
245
- print(f" Commit: {commit_info.oid}")
246
- print(f" URL: https://huggingface.co/PowerMachine/BiGRU_T_version/commit/{commit_info.oid}")
247
- except Exception as e:
248
- print(f" ERROR: upload failed: {e}")
249
- return 1
250
-
251
- # ── Step 4: Remove OLD files from repo (single delete commit) ────────────
252
- print(f"\n [4/5] Removing {len(OLD_FILES_TO_REMOVE)} old files from repo...")
253
- try:
254
- info_after = api.repo_info(repo_id=repo_id, repo_type="model")
255
- files_after_upload = set(s.rfilename for s in info_after.siblings)
256
- except Exception as e:
257
- print(f" WARNING: cannot refresh repo info: {e}")
258
- files_after_upload = files_before
259
-
260
- old_files_in_repo = [f for f in OLD_FILES_TO_REMOVE if f in files_after_upload]
261
- old_files_not_in_repo = [f for f in OLD_FILES_TO_REMOVE if f not in files_after_upload]
262
- print(f" Old files present in repo (will delete): {len(old_files_in_repo)}")
263
- print(f" Old files NOT in repo (skip): {len(old_files_not_in_repo)}")
264
-
265
- delete_errors = []
266
- commit_del = None
267
- if old_files_in_repo:
268
- try:
269
- from huggingface_hub import CommitOperation
270
- operations = [CommitOperationDelete(path_in_repo=f) for f in old_files_in_repo]
271
- print(f" Creating batch delete commit ({len(operations)} files)...")
272
- t_del_start = time.time()
273
- commit_del = api.create_commit(
274
- repo_id=repo_id,
275
- repo_type="model",
276
- operations=operations,
277
- commit_message=(
278
- f"V6.5-attn-v2 cleanup: remove {len(operations)} legacy/superseded files "
279
- f"(v3/v4/v5/v6_1/v6_2/v6_3/v6_progressive + old v6_5_*/v6_5_final_*/v6_5_7ds_*/v6_5_7ds_attn_* v1 "
280
- f"reports/scripts) — replaced by V6.5-attn-v2 canonicals"
281
- ),
282
- )
283
- t_del_end = time.time()
284
- print(f" Delete commit: {commit_del}")
285
- print(f" Delete completed in {t_del_end - t_del_start:.2f}s")
286
- print(f" URL: https://huggingface.co/PowerMachine/BiGRU_T_version/commit/{commit_del}")
287
- except Exception as e:
288
- print(f" ERROR: batch delete failed: {e}")
289
- print(f" Falling back to per-file delete...")
290
- for f in old_files_in_repo:
291
- try:
292
- api.delete_file(
293
- repo_id=repo_id, repo_type="model",
294
- path_in_repo=f,
295
- commit_message=f"V6.5-attn-v2 cleanup: remove legacy {f}",
296
- token=hf_token,
297
- )
298
- print(f" DELETED: {f}")
299
- except Exception as e2:
300
- delete_errors.append((f, str(e2)[:100]))
301
- print(f" FAILED: {f} — {str(e2)[:100]}")
302
-
303
- # ── Step 5: Verify critical files in repo ────────────────────────────────
304
- print(f"\n [5/5] Verifying critical V6.5-attn files in repo...")
305
- all_present = True
306
- files_in_repo = set()
307
- try:
308
- info_final = api.repo_info(repo_id=repo_id, repo_type="model")
309
- files_in_repo = set(s.rfilename for s in info_final.siblings)
310
- for cf in CRITICAL_FILES_V65_ATTN:
311
- present = cf in files_in_repo
312
- mark = "OK" if present else "MISS"
313
- print(f" [{mark}] {cf}")
314
- if not present:
315
- all_present = False
316
- print(f"\n Files in repo AFTER cleanup: {len(files_in_repo)}")
317
- if not all_present:
318
- print(" WARNING: some critical files missing!")
319
- except Exception as e:
320
- print(f" WARNING: cannot verify files: {e}")
321
-
322
- # ── Save upload report ───────────────────────────────────────────────────
323
- report = {
324
- "version": "V6.5-attn-v2",
325
- "upload_timestamp": time.strftime("%Y-%m-%dT%H:%M:%S"),
326
- "repo_id": repo_id,
327
- "upload_commit_oid": commit_info.oid,
328
- "upload_commit_url": f"https://huggingface.co/PowerMachine/BiGRU_T_version/commit/{commit_info.oid}",
329
- "upload_duration_s": float(t1 - t0),
330
- "delete_commit_oid": commit_del,
331
- "delete_count": len(old_files_in_repo) if old_files_in_repo else 0,
332
- "delete_errors": delete_errors,
333
- "n_files_before": len(files_before),
334
- "n_files_after_upload": len(files_after_upload),
335
- "n_files_after_cleanup": len(files_in_repo) if files_in_repo else None,
336
- "old_files_removed": old_files_in_repo,
337
- "old_files_not_in_repo_skipped": old_files_not_in_repo,
338
- "critical_files": CRITICAL_FILES_V65_ATTN,
339
- "all_critical_files_present": all_present,
340
- "token_scrubbed_count": scrubbed_count,
341
- }
342
- report_path = BIGRU_ROOT / "v6_5_7ds_attn_v2_upload_report.json"
343
- report_path.write_text(json.dumps(report, indent=2, ensure_ascii=False))
344
- print(f"\n Upload report: {report_path}")
345
- print("\n" + "=" * 72)
346
- print("V6.5-attn-v2 — UPLOAD COMPLETED (with old file removal)")
347
- print("=" * 72)
348
- return 0
349
-
350
-
351
- if __name__ == "__main__":
352
- sys.exit(main())