V6.5-7ds cleanup: remove legacy scripts/upload_v6_2_resilient.py
Browse files- scripts/upload_v6_2_resilient.py +0 -248
scripts/upload_v6_2_resilient.py
DELETED
|
@@ -1,248 +0,0 @@
|
|
| 1 |
-
"""upload_v6_2_resilient.py — Upload resiliente V6.2 para o HF.
|
| 2 |
-
|
| 3 |
-
Estratégia (igual V6/V6.1):
|
| 4 |
-
- HfApi.upload_folder (single commit lógico)
|
| 5 |
-
- allow_patterns: *.py + *.json + *.md + *.txt + tokenizer.json
|
| 6 |
-
- ignore_patterns: __pycache__, *.pyc, _test_*, *.safetensors, *.bin, *.pt, *.pth
|
| 7 |
-
- hf_transfer habilitado
|
| 8 |
-
|
| 9 |
-
V6.2 inclui (NOVO vs V6.1):
|
| 10 |
-
- src/bigru_t/model/hyp_t.py (V6.2 — pgvector_lookup_before_punishment()
|
| 11 |
-
consults SOM before applying punishment; COMPLETE → skip delta,
|
| 12 |
-
INCOMPLETE/MISSING → apply delta; tracks n_complete_skip, n_incomplete_apply,
|
| 13 |
-
n_missing_apply, skip_rate)
|
| 14 |
-
- scripts/train_v6_2.py (NOVO — 5 datasets × 50 samples + BATCH_SIZE=16 +
|
| 15 |
-
hyp pgvector capture)
|
| 16 |
-
- v6_2_report.json (relatório do treino V6.2)
|
| 17 |
-
|
| 18 |
-
Uso:
|
| 19 |
-
export HF_TOKEN="hf_xxx..." # env var temporária, será apagada após upload
|
| 20 |
-
python /home/z/my-project/scripts/upload_v6_2_resilient.py
|
| 21 |
-
"""
|
| 22 |
-
from __future__ import annotations
|
| 23 |
-
|
| 24 |
-
import os
|
| 25 |
-
import sys
|
| 26 |
-
import time
|
| 27 |
-
import json
|
| 28 |
-
from pathlib import Path
|
| 29 |
-
|
| 30 |
-
os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")
|
| 31 |
-
os.environ.setdefault("HF_HUB_ETAG_TIMEOUT", "60")
|
| 32 |
-
os.environ.setdefault("PYTHONUNBUFFERED", "1")
|
| 33 |
-
os.environ.setdefault("OMP_NUM_THREADS", "2")
|
| 34 |
-
os.environ.setdefault("TOKENIZERS_PARALLELISM", "true")
|
| 35 |
-
|
| 36 |
-
from huggingface_hub import HfApi # noqa: E402
|
| 37 |
-
|
| 38 |
-
REPO_ID = "PowerMachine/BiGRU_T_version"
|
| 39 |
-
LOCAL_DIR = "/home/z/my-project/BiGRU_T_version"
|
| 40 |
-
COMMIT_MESSAGE = """V6.2: HypT pgvector_lookup before punishment + BATCH_SIZE=16 + 5 datasets x 50
|
| 41 |
-
|
| 42 |
-
V6.2 improvements (vs V6.1):
|
| 43 |
-
- hyp_t.py: pgvector_lookup_before_punishment() method — HypT consults
|
| 44 |
-
SOM map BEFORE applying punishment (delta correction). If status ==
|
| 45 |
-
COMPLETE, punishment is SKIPPED (model trusts y_hat). If INCOMPLETE/
|
| 46 |
-
MISSING, punishment is applied normally.
|
| 47 |
-
(User requirement: "ative pgvector_lookup no nível de hipótese (hyp_t.py)
|
| 48 |
-
para que ele também consulte o mapa antes de aplicar punição")
|
| 49 |
-
- hyp_t.py: tracks n_complete_skip, n_incomplete_apply, n_missing_apply,
|
| 50 |
-
skip_rate (for monitoring)
|
| 51 |
-
- train_v6_2.py: BATCH_SIZE=16 (was 4) — user requirement
|
| 52 |
-
- train_v6_2.py: 5 datasets from streaming_datasets.py x 50 samples each
|
| 53 |
-
(250 total, 2 epochs) — user requirement (was 10 per dataset)
|
| 54 |
-
- train_v6_2.py: synthetic fallback expanded to 50 samples per dataset
|
| 55 |
-
with templates + random placeholders (ensures 250 samples even when
|
| 56 |
-
streaming fails)
|
| 57 |
-
- train_v6_2.py: datasets library installed (pip install datasets) for
|
| 58 |
-
real streaming
|
| 59 |
-
- xeon_runtime.py V6 always active (AVX512 + AMX_INT8 + IPEX + OneDNN)
|
| 60 |
-
|
| 61 |
-
V6.2 monitoring (12/12 + Kohonen + MTP + EWC + PGVector train + Hyp PGVector):
|
| 62 |
-
- 12/12 base metrics (loss, perplexity, tps, tflops, rss, alerts, etc.)
|
| 63 |
-
- Kohonen SOM: sigma_t, alpha_t, bmu_diversity, n_filled, filled_ratio
|
| 64 |
-
- MTP: train loss, val loss, entropy regularizer, alphas
|
| 65 |
-
- EWC V6.1: total_penalty, classic_pen, kohonen_pen, topo_pen,
|
| 66 |
-
n_masked_som_neurons (skip mask working)
|
| 67 |
-
- PGVector (treino level): status (COMPLETE/INCOMPLETE/MISSING),
|
| 68 |
-
coverage_ratio, best_sim, n_filled
|
| 69 |
-
- PGVector (nível de hipótese) [V6.2 NEW]: status, apply_punishment,
|
| 70 |
-
skipped_by_pgvector, n_complete_skip, n_incomplete_apply,
|
| 71 |
-
n_missing_apply, skip_rate
|
| 72 |
-
|
| 73 |
-
User requirement satisfied:
|
| 74 |
-
- "ative pgvector_lookup no nível de hipótese (hyp_t.py) para que ele
|
| 75 |
-
também consulte o mapa antes de aplicar punição" -> HypT now consults
|
| 76 |
-
SOM before applying delta; COMPLETE → skip
|
| 77 |
-
- "ativar xeon_runtime.py" -> V6 always active
|
| 78 |
-
- "capturar métricas no re-treino streaming de 5 datasets (pip install
|
| 79 |
-
datasets) 50 em 50 samples diversos" -> 5x50=250 samples, metrics
|
| 80 |
-
captured per step (12/12 + Kohonen + MTP + EWC + PGVector + Hyp PGVector)
|
| 81 |
-
- "monitorar e informar valores obtidos" -> V6.2 report includes all
|
| 82 |
-
monitored values + evolution
|
| 83 |
-
- "BATCH_SIZE = 16" -> applied
|
| 84 |
-
"""
|
| 85 |
-
|
| 86 |
-
# Arquivos críticos V6.2 a serem verificados pós-upload
|
| 87 |
-
CRITICAL_FILES_V6_2 = [
|
| 88 |
-
"src/bigru_t/model/hyp_t.py", # V6.2 NOVO
|
| 89 |
-
"src/bigru_t/model/orq_cell.py",
|
| 90 |
-
"src/bigru_t/training/ewc.py",
|
| 91 |
-
"src/bigru_t/training/mtp.py",
|
| 92 |
-
"src/bigru_t/training/dynamic_repetition_penalty.py",
|
| 93 |
-
"src/bigru_t/training/data_augmentation.py",
|
| 94 |
-
"src/bigru_t/training/rlhf_mapping.py",
|
| 95 |
-
"src/bigru_t/attention/window_context.py",
|
| 96 |
-
"src/bigru_t/reasoning/thinking.py",
|
| 97 |
-
"src/bigru_t/tools/tool_mutation.py",
|
| 98 |
-
"src/bigru_t/tools/tool_cache.py",
|
| 99 |
-
"src/bigru_t/tools/tool_agent.py",
|
| 100 |
-
"src/bigru_t/integrations/langchain_compat.py",
|
| 101 |
-
"src/bigru_t/pipeline/optimized_pipeline.py",
|
| 102 |
-
"src/bigru_t/utils/xeon_runtime.py",
|
| 103 |
-
"v6_1_report.json",
|
| 104 |
-
"v6_2_report.json", # V6.2 NOVO
|
| 105 |
-
]
|
| 106 |
-
|
| 107 |
-
ALLOW_PATTERNS = [
|
| 108 |
-
"*.py", "*.json", "*.md", "*.txt",
|
| 109 |
-
"tokenizer.json",
|
| 110 |
-
]
|
| 111 |
-
|
| 112 |
-
IGNORE_PATTERNS = [
|
| 113 |
-
"__pycache__", "*.pyc", "_test_*", "tests/",
|
| 114 |
-
"*.safetensors", "*.bin", "*.pt", "*.pth",
|
| 115 |
-
"*.so", "*.dylib", "*.dll",
|
| 116 |
-
]
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
def main():
|
| 120 |
-
print("=" * 72)
|
| 121 |
-
print(f"UPLOAD V6.2 RESILIENT — {REPO_ID}")
|
| 122 |
-
print("=" * 72)
|
| 123 |
-
|
| 124 |
-
token = os.environ.get("HF_TOKEN")
|
| 125 |
-
if not token:
|
| 126 |
-
print("[ERROR] HF_TOKEN não definido. Export HF_TOKEN=hf_xxx antes de rodar.")
|
| 127 |
-
sys.exit(1)
|
| 128 |
-
print(f"[INFO] HF_TOKEN presente (length={len(token)}, prefix={token[:5]}...)")
|
| 129 |
-
|
| 130 |
-
local_dir = Path(LOCAL_DIR)
|
| 131 |
-
if not local_dir.exists():
|
| 132 |
-
print(f"[ERROR] Diretório local não existe: {local_dir}")
|
| 133 |
-
sys.exit(1)
|
| 134 |
-
|
| 135 |
-
# Lista arquivos a enviar
|
| 136 |
-
files_to_upload = []
|
| 137 |
-
for pattern in ALLOW_PATTERNS:
|
| 138 |
-
files_to_upload.extend(local_dir.rglob(pattern))
|
| 139 |
-
# Filtra ignorados
|
| 140 |
-
files_filtered = []
|
| 141 |
-
for f in files_to_upload:
|
| 142 |
-
rel = f.relative_to(local_dir)
|
| 143 |
-
rel_str = str(rel)
|
| 144 |
-
if any(p in rel_str for p in IGNORE_PATTERNS if "*" not in p):
|
| 145 |
-
continue
|
| 146 |
-
if any(rel_str.endswith(p.replace("*", "")) for p in IGNORE_PATTERNS if "*" in p):
|
| 147 |
-
continue
|
| 148 |
-
files_filtered.append(rel_str)
|
| 149 |
-
files_filtered = sorted(set(files_filtered))
|
| 150 |
-
print(f"[INFO] {len(files_filtered)} arquivos locais a enviar")
|
| 151 |
-
print(f"[INFO] Primeiros 15 arquivos:")
|
| 152 |
-
for f in files_filtered[:15]:
|
| 153 |
-
size = (local_dir / f).stat().st_size
|
| 154 |
-
print(f" - {f} ({size} bytes)")
|
| 155 |
-
if len(files_filtered) > 15:
|
| 156 |
-
print(f" ... e mais {len(files_filtered) - 15} arquivos")
|
| 157 |
-
|
| 158 |
-
api = HfApi(token=token)
|
| 159 |
-
|
| 160 |
-
# Verifica repo
|
| 161 |
-
print(f"\n[INFO] Verificando repositório {REPO_ID}…")
|
| 162 |
-
try:
|
| 163 |
-
api.repo_info(REPO_ID, repo_type="model")
|
| 164 |
-
print("[INFO] Repo já existia")
|
| 165 |
-
except Exception:
|
| 166 |
-
print("[INFO] Criando repo...")
|
| 167 |
-
api.create_repo(REPO_ID, repo_type="model", private=False)
|
| 168 |
-
print("[INFO] Repo criado")
|
| 169 |
-
|
| 170 |
-
# Lista arquivos atuais
|
| 171 |
-
try:
|
| 172 |
-
files_in_repo = [f.rfilename for f in api.list_repo_tree(REPO_ID, repo_type="model", recursive=True)]
|
| 173 |
-
print(f"[INFO] {len(files_in_repo)} arquivos no repo ANTES do upload")
|
| 174 |
-
except Exception:
|
| 175 |
-
files_in_repo = []
|
| 176 |
-
|
| 177 |
-
# Upload folder (single commit)
|
| 178 |
-
print("\n" + "=" * 72)
|
| 179 |
-
print("[INFO] Iniciando upload_folder (single commit)…")
|
| 180 |
-
print("=" * 72)
|
| 181 |
-
t0 = time.perf_counter()
|
| 182 |
-
commit_info = api.upload_folder(
|
| 183 |
-
folder_path=str(local_dir),
|
| 184 |
-
repo_id=REPO_ID,
|
| 185 |
-
repo_type="model",
|
| 186 |
-
commit_message=COMMIT_MESSAGE,
|
| 187 |
-
allow_patterns=ALLOW_PATTERNS,
|
| 188 |
-
ignore_patterns=IGNORE_PATTERNS,
|
| 189 |
-
)
|
| 190 |
-
elapsed = time.perf_counter() - t0
|
| 191 |
-
print(f"[INFO] upload_folder concluído em {elapsed:.2f}s")
|
| 192 |
-
print(f"[INFO] commit_info: {commit_info.commit_url if hasattr(commit_info, 'commit_url') else commit_info}")
|
| 193 |
-
|
| 194 |
-
# Aguarda indexação
|
| 195 |
-
print("\n[INFO] Aguardando 3s para o HF indexar…")
|
| 196 |
-
time.sleep(3)
|
| 197 |
-
|
| 198 |
-
# Verifica arquivos críticos V6.2
|
| 199 |
-
try:
|
| 200 |
-
files_in_repo_after = [f.rfilename for f in api.list_repo_tree(REPO_ID, repo_type="model", recursive=True)]
|
| 201 |
-
print(f"[INFO] {len(files_in_repo_after)} arquivos no repo DEPOIS do upload")
|
| 202 |
-
new_files = set(files_in_repo_after) - set(files_in_repo)
|
| 203 |
-
print(f"[INFO] Novos arquivos: {len(new_files)}")
|
| 204 |
-
overwritten = set(files_in_repo) & set(files_in_repo_after)
|
| 205 |
-
print(f"[INFO] Arquivos sobrescritos: {len(overwritten)}")
|
| 206 |
-
except Exception as e:
|
| 207 |
-
print(f"[WARN] Não foi possível listar arquivos pós-upload: {e}")
|
| 208 |
-
files_in_repo_after = []
|
| 209 |
-
|
| 210 |
-
print(f"\n[INFO] Verificação de arquivos críticos V6.2 no repo:")
|
| 211 |
-
all_critical_ok = True
|
| 212 |
-
for cf in CRITICAL_FILES_V6_2:
|
| 213 |
-
if cf in files_in_repo_after:
|
| 214 |
-
print(f" ✓ {cf}")
|
| 215 |
-
else:
|
| 216 |
-
print(f" ✗ {cf} (NÃO ENCONTRADO)")
|
| 217 |
-
all_critical_ok = False
|
| 218 |
-
|
| 219 |
-
# Salva relatório
|
| 220 |
-
report_path = local_dir / "v6_2_upload_report.json"
|
| 221 |
-
upload_report = {
|
| 222 |
-
"version": "V6.2",
|
| 223 |
-
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
|
| 224 |
-
"repo_id": REPO_ID,
|
| 225 |
-
"commit_url": str(commit_info.commit_url) if hasattr(commit_info, "commit_url") else str(commit_info),
|
| 226 |
-
"elapsed_seconds": elapsed,
|
| 227 |
-
"n_files_uploaded": len(files_filtered),
|
| 228 |
-
"n_files_in_repo_before": len(files_in_repo),
|
| 229 |
-
"n_files_in_repo_after": len(files_in_repo_after),
|
| 230 |
-
"new_files": list(new_files) if 'new_files' in locals() else [],
|
| 231 |
-
"critical_files_ok": all_critical_ok,
|
| 232 |
-
"critical_files": CRITICAL_FILES_V6_2,
|
| 233 |
-
}
|
| 234 |
-
with open(report_path, "w") as f:
|
| 235 |
-
json.dump(upload_report, f, indent=2, default=str)
|
| 236 |
-
print(f"\n[INFO] Relatório salvo: {report_path}")
|
| 237 |
-
|
| 238 |
-
print("\n" + "=" * 72)
|
| 239 |
-
if all_critical_ok:
|
| 240 |
-
print(f"[OK] UPLOAD V6.2 CONCLUÍDO — {len(files_filtered)} arquivos enviados")
|
| 241 |
-
print(f"[OK] URL: https://huggingface.co/{REPO_ID}")
|
| 242 |
-
else:
|
| 243 |
-
print(f"[WARN] UPLOAD V6.2 COMPLETO mas alguns arquivos críticos não verificados")
|
| 244 |
-
print("=" * 72)
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
if __name__ == "__main__":
|
| 248 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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