v0.9.0: análise/prova/teste das críticas Qwen3.8 lote 2 (r-34) — SIMD com despacho em runtime bit-a-bit (X-1), oráculo candle_nn::optim::AdamW (nosso 1,53× mais rápido), Thompson Sampling (regret 0,0019 vs UCB1 0,0156), GNG por entropia com piso (T-G1'), JEPA de fração adaptativa (bit-a-bit com 1 braço), configs tipadas, entrada numpy (2008× na fronteira), avaliação com dados reais — 104/104 gates, 111/111 cargo
d444358 verified Download scripts/72_publicar_v090.py from PowerMachine/khtst-rust: direct link, hf CLI and curl.
- Browser
- Download file 7.39 kB
-
https://huggingface.co/PowerMachine/khtst-rust/resolve/main/scripts/72_publicar_v090.py
- Command line
-
hf download hf://PowerMachine/khtst-rust/scripts/72_publicar_v090.py
-
curl -L -o 72_publicar_v090.py https://huggingface.co/PowerMachine/khtst-rust/resolve/main/scripts/72_publicar_v090.py
7.39 kB
| #!/usr/bin/env python3 | |
| """72_publicar_v090.py — Publicação da v0.9.0 no HF (UM ÚNICO upload_folder | |
| organizado — o HF bloqueia envios parciais em sequência e em curto espaço | |
| de tempo; uma única operação atômica evita o bloqueio). | |
| Fases: | |
| 1. inventário da conta + APAGAMENTO de estados de treino remanescentes; | |
| 2. varredura local do VALOR do token (nenhum arquivo pode contê-lo); | |
| 3. UM ÚNICO upload_folder com ignore_patterns EXPLÍCITOS (lição v0.7.0); | |
| 4. verificação pós-upload (0 estados, módulos-chave presentes, contagem); | |
| 5. varredura REMOTA do valor do token (baixa e inspeciona os arquivos). | |
| Token: EXCLUSIVAMENTE via variável de ambiente HF_TOKEN (nunca em arquivo). | |
| """ | |
| import os, sys, tempfile | |
| ARQUIVOS_EXCLUIR_DIRS = {"target", ".cargo", "__pycache__", ".git", ".venv", | |
| "skills", "externos"} | |
| ARQUIVOS_EXCLUIR_NOME = {"shard_treino.jsonl", "shard_validacao.jsonl", | |
| "bpe.json", "rustup-init.sh"} | |
| SUFIXOS_ESTADO = (".pt", ".pth", ".ckpt", ".safetensors", ".bin", ".npz", | |
| ".msgpack") | |
| NOMES_ESTADO = {"gerador_conceitos.json", "tokenizador_conceitos.json", | |
| "gerador_aritmetica.json"} | |
| def coletar(pasta): | |
| arquivos = {} | |
| for raiz, dirs, fs in os.walk(pasta): | |
| dirs[:] = [d for d in dirs if d not in ARQUIVOS_EXCLUIR_DIRS] | |
| for f in fs: | |
| if f in ARQUIVOS_EXCLUIR_NOME or f in NOMES_ESTADO: | |
| continue | |
| if f.endswith(SUFIXOS_ESTADO) or f.endswith(".estado.json"): | |
| continue | |
| if f.endswith(".so") or f in (".gitignore", "Cargo.lock.ori"): | |
| continue | |
| if f.startswith("hf_") or f.startswith("intros_"): | |
| continue # scripts de análise externa (não fazem parte) | |
| caminho = os.path.join(raiz, f) | |
| rel = os.path.relpath(caminho, pasta) | |
| arquivos[rel] = caminho | |
| return arquivos | |
| def varre_token_em_arquivos(token, pares): | |
| tb = token.encode() | |
| achados = [] | |
| for rel, p in pares.items(): | |
| try: | |
| with open(p, "rb") as f: | |
| if tb in f.read(): | |
| achados.append(rel) | |
| except OSError: | |
| pass | |
| return achados | |
| def main(): | |
| from huggingface_hub import HfApi | |
| token = os.environ.get("HF_TOKEN") | |
| if not token: | |
| print("ERRO: HF_TOKEN ausente"); sys.exit(1) | |
| api = HfApi(token=token) | |
| repo = "PowerMachine/khtst-rust" | |
| # ---------------- 1) inventário da conta + apaga estados ---------------- | |
| print("=== 1) inventário da conta HF (procura estados de treino) ===") | |
| repos = list(api.list_models(author="PowerMachine")) | |
| print(f"repos: {len(repos)}") | |
| total_removidos = 0 | |
| for r in repos: | |
| try: | |
| files = api.list_repo_files(repo_id=r.id, repo_type="model") | |
| except Exception as e: | |
| print(f" {r.id}: erro ao listar ({e})"); continue | |
| estados = [f for f in files | |
| if f.endswith(SUFIXOS_ESTADO) | |
| or f.split("/")[-1] in NOMES_ESTADO | |
| or (".meta.json" in f and "checkpoint" in f)] | |
| if estados: | |
| print(f" {r.id}: APAGANDO {len(estados)} estados") | |
| for f in estados: | |
| api.delete_file(path_in_repo=f, repo_id=r.id, repo_type="model") | |
| total_removidos += len(estados) | |
| else: | |
| print(f" {r.id}: {len(files)} arquivos, 0 estados") | |
| print(f"estados removidos no total: {total_removidos}") | |
| # ---------------- 2) varredura local do token ---------------- | |
| pasta = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| arquivos = coletar(pasta) | |
| print(f"\n=== 2) varredura local: {len(arquivos)} arquivos ===") | |
| achados = varre_token_em_arquivos(token, arquivos) | |
| if achados: | |
| print(f"ERRO: valor do token encontrado em: {achados}"); sys.exit(1) | |
| print("varredura de token local: limpa") | |
| import subprocess | |
| home = os.path.expanduser("~") | |
| try: | |
| saida = subprocess.run( | |
| ["grep", "-rl", token, home, "--include=*.py", "--include=*.json", | |
| "--include=*.md", "--include=*.sh", "--include=*.toml"], | |
| capture_output=True, text=True, timeout=120) | |
| if saida.stdout.strip(): | |
| print(f"ERRO: token no home: {saida.stdout.strip()}"); sys.exit(1) | |
| except Exception: | |
| pass | |
| print("varredura do home: limpa") | |
| # ---------------- 3) UM ÚNICO upload_folder ---------------- | |
| ignores = ( | |
| [f"{d}/**" for d in ARQUIVOS_EXCLUIR_DIRS] | |
| + [f"{d}" for d in ARQUIVOS_EXCLUIR_DIRS] | |
| + list(ARQUIVOS_EXCLUIR_NOME) + list(NOMES_ESTADO) | |
| + list(SUFIXOS_ESTADO) | |
| + ["*.so", ".gitignore", "hf_*.py", "hf_*.json", "intros_*.json", | |
| "*.estado.json"] | |
| ) | |
| print(f"\n=== 3) upload_folder ÚNICO ({len(arquivos)} arquivos) ===") | |
| api.upload_folder( | |
| repo_id=repo, repo_type="model", folder_path=pasta, | |
| ignore_patterns=ignores, commit_message="v0.9.0: análise/prova/teste " | |
| "das críticas Qwen3.8 lote 2 (r-34) — SIMD com despacho em runtime " | |
| "bit-a-bit (X-1), oráculo candle_nn::optim::AdamW (nosso 1,53× mais " | |
| "rápido), Thompson Sampling (regret 0,0019 vs UCB1 0,0156), GNG por " | |
| "entropia com piso (T-G1'), JEPA de fração adaptativa (bit-a-bit com " | |
| "1 braço), configs tipadas, entrada numpy (2008× na fronteira), " | |
| "avaliação com dados reais — 104/104 gates, 111/111 cargo", | |
| ) | |
| print("upload concluído") | |
| # ---------------- 4) verificação pós-upload ---------------- | |
| print("\n=== 4) verificação pós-upload ===") | |
| files = api.list_repo_files(repo_id=repo, repo_type="model") | |
| estados = [f for f in files if f.endswith(SUFIXOS_ESTADO) | |
| or f.split("/")[-1] in NOMES_ESTADO] | |
| assert not estados, f"estados publicados: {estados}" | |
| chaves = ["src/verificador.rs", "src/arvore_pesos.rs", "src/fnh.rs", | |
| "src/moe_redirecionavel.rs", "scripts/68_suite_v080.py", | |
| "scripts/69_publicar_v080.py", | |
| "docs/memorias/r-33-analise-provas-qwen-v080.md", | |
| "resultados/suite_v080_final.json"] | |
| faltando = [c for c in chaves if c not in files] | |
| assert not faltando, f"faltando: {faltando}" | |
| print(f"repo: {len(files)} arquivos | 0 estados | módulos-chave OK") | |
| # ---------------- 5) varredura REMOTA do token ---------------- | |
| print("\n=== 5) varredura REMOTA do valor do token ===") | |
| with tempfile.TemporaryDirectory() as tmp: | |
| achados_remotos = [] | |
| for f in files: | |
| if f.endswith((".py", ".rs", ".md", ".json", ".toml", ".sh", ".cfg", | |
| ".txt", ".jsonl")): | |
| try: | |
| p = api.hf_hub_download(repo_id=repo, repo_type="model", | |
| filename=f, local_dir=tmp) | |
| with open(p, "rb") as fh: | |
| if token.encode() in fh.read(): | |
| achados_remotos.append(f) | |
| except Exception: | |
| pass | |
| if achados_remotos: | |
| print(f"ERRO: token remoto em: {achados_remotos}"); sys.exit(1) | |
| print("varredura remota: limpa") | |
| print("\nPUBLICAÇÃO v0.8.0 CONCLUÍDA") | |
| if __name__ == "__main__": | |
| main() | |