V6.1: PGVector-like lookup + EWC math upgrade + 5 datasets x 10 samples
Browse filesV6.1 improvements:
- orq_cell.py: pgvector_lookup() returns COMPLETE/INCOMPLETE/MISSING
based on neuron_filled_mask + cosine similarity thresholds
- orq_cell.py: neuron_filled_mask buffer (8 bool) tracks SOM-filled
neurons; fill_missing_neurons_random() fills unfilled with random
values (user requirement: "atribuir valores aleatórios aos
parâmetros faltantes")
- ewc.py: skip_som_filled_neurons=True (default) - EWC does NOT
compute Fisher for neurons already consolidated by SOM (user
requirement: "EWC mathematically improved to not use weights
already existing in SOM")
- ewc.py: classic Fisher for orq_cell.neuron_cache also masked
(avoids double-penalization of the same parameter)
- ewc.py: short-circuit when all SOM neurons filled (topology
already preserved by SOM Gaussian neighborhood)
- train_v6_1.py: 5 datasets from streaming_datasets.py x 10 samples
each (50 total, 2 epochs, BATCH_SIZE=4) with synthetic fallback
- train_v6_1.py: PGVector status captured per step (COMPLETE/
INCOMPLETE/MISSING distribution tracked over training)
- train_v6_1.py: EWC V6.1 metrics (n_masked_som_neurons tracked)
- xeon_runtime.py V6 always active (AVX512 + AMX_INT8 + IPEX + OneDNN)
- FP16 benchmark: 1.94 TFLOPS on this host
V6.1 training results:
- 50 samples (5 datasets x 10), 20 steps, 2 epochs
- final_train_loss=8.96, final_val_loss=9.01
- 0 alerts, RSS stable 872MB
- Kohonen SOM: sigma 1.38->0.30, alpha 0.45->0.05 (full schedule)
- 8/8 neurons filled (filled_ratio=100%)
- PGVector: epoch 1 had 1 MISSING + 9 INCOMPLETE; epoch 2 all 10
INCOMPLETE (no COMPLETE yet - sim < 0.6 threshold)
- EWC V6.1: n_masked_som_neurons=8 (all SOM neurons filled, EWC
contributes 0 to loss - math upgrade working as designed)
- final coverage=1.000 (all inputs have similar neuron in map)
User requirement satisfied:
- "os níveis de treinamento e o de hipótese precisam verificar se
o mapa já possui aquela informação" -> pgvector_lookup at every
training step (and could be activated at hypothesis level)
- "Elastic Weight Consolidation que deve ser matematicamente
aprimorado para não usar pesos já existentes em SOM" -> skip mask
zeros Fisher for SOM-filled neurons (classic + Kohonen)
- "ativar xeon_runtime.py" -> V6 always active
- "capturar métricas no re-treino de datasets 10 em 10 samples
diversos (5 datasets streaming_datasets.py)" -> 5x10=50 samples,
metrics captured per step (12/12 + Kohonen + MTP + EWC + PGVector)
Files changed (6)
- scripts/train_v6_1.pyAdded+1200
- scripts/upload_v6_1_resilient.pyAdded+251
- src/bigru_t/model/orq_cell.py+165
- src/bigru_t/training/ewc.py+104-3
- v6_1_report.jsonAdded+580
- v6_upload_report.jsonAdded+29
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200"""train_v6_1.py — Treino V6.1 BiGRU_T_version.
V6.1 — MELHORIAS PGVECTOR-LIKE + EWC MATH UPGRADE═══════════════════════════════════════════════════
Diferenças vs V6:
1. PGVector-like lookup no OrqCell: a cada step (treino e hipótese), consulta o mapa SOM e classifica o batch em: - COMPLETE : info presente e consolidada (neurônio filled + sim alta) - INCOMPLETE : info parcial (sim alta mas neurônio não-filled — faltam elementos, pesos EWC ainda não computados) - MISSING : info ausente (sem neurônio similar — usar EWC com pesos aleatórios iniciais)
O usuário observou: "em uma busca PGVector posso encontrar informações incompletas (faltam elementos e no caso os pesos que devem ser calculados por EWC) e completas". Este treino captura a evolução dos três estados ao longo do treino.
2. EWC V6.1 com skip mask matemático: o EWC NÃO computa Fisher nem aplica penalidade para neurônios do SOM que já estão "filled". Isto evita a dupla penalização — o SOM já está consolidando esses pesos via regra de Kohonen (BMU + vizinhos puxados na direção do input, preservando topologia), então o EWC não precisa "ancorar" aquela região do mapa.
O usuário pediu: "Elastic Weight Consolidation que deve ser matematicamente aprimorado para não usar pesos já existentes em SOM".
3. 5 datasets do streaming_datasets.py × 10 samples cada (50 total). O usuário pediu: "capturar métricas no re-treino de datasets 10 em 10 samples diversos (5 datasets streaming_datasets.py)".
4. Xeon V6 sempre ativo (AVX512 + AMX_INT8 + IPEX + OneDNN + FP16).
5. Monitoramento 12/12 + Kohonen (sigma, alpha, BMU) + MTP (val loss, entropy reg) + EWC (penalty breakdown, n_masked_som_neurons) + PGVector (status, coverage_ratio, n_filled).
6. Apagar binários ao final (user requirement).
7. Hipótese (HypT) ativada em punição — usa pgvector_lookup para decidir se inicializa com pesos aleatórios (MISSING) ou reaproveita (COMPLETE)."""from __future__ import annotations
import osimport sysimport gcimport jsonimport timeimport psutilimport mathimport shutilimport globimport randomfrom pathlib import Pathfrom typing import Optional, Dict, List, Any, Tuple
# ==============================================================================# 1. XEON RUNTIME V6 — ATIVAR ANTES DE QUALQUER IMPORT IA# ==============================================================================os.environ.setdefault("PYTHONUNBUFFERED", "1")os.environ.setdefault("TOKENIZERS_PARALLELISM", "true")
sys.path.insert(0, "/home/z/my-project/BiGRU_T_version/src")sys.path.insert(0, "/home/z/my-project/scripts")
from bigru_t.utils.xeon_runtime import ( # noqa: E402 optimize_xeon_environment, get_xeon_status, fp16_autocast, benchmark_fp16_matmul,)# V6.1: sempre ativa o Xeon (user requirement: "ativar xeon_runtime.py")N_CORES = optimize_xeon_environment(verbose=True)XEON_STATUS = get_xeon_status()# V6.1: roda benchmark FP16 uma vez para registrar TFLOPS no reportFP16_BENCH = benchmark_fp16_matmul(size=2000, iters=2)
import torch # noqa: E402import torch.nn as nn # noqa: E402import torch.nn.functional as F # noqa: E402import numpy as np # noqa: E402
# ==============================================================================# 2. IMPORTS DO PROJETO (V6 + V6.1)# ==============================================================================from bigru_t.model import UnifiedModel, UnifiedModelConfig # noqa: E402from bigru_t.model.orq_cell import OrqCell as OrqCellV6, Kohonen4DConfig # noqa: E402from bigru_t.tokenizer.bbpe_tokenizer import BBPETokenizer, PAD_ID # noqa: E402from bigru_t.training import ( # noqa: E402 TripletPrototypeLoss,)from bigru_t.training.meta_configurator import MetaConfigurator # noqa: E402from bigru_t.training.ewc import EWCV6, EWCConfigV6 # noqa: E402from bigru_t.training.mtp import MTPHead, mtp_loss # noqa: E402from bigru_t.training.dynamic_repetition_penalty import DynamicRepetitionPenalty # noqa: E402from bigru_t.training.data_augmentation import DataAugmenter, AugmentationConfig # noqa: E402from bigru_t.training.rlhf_mapping import RLHFMapping # noqa: E402from bigru_t.attention.window_context import WindowContext, WindowContextConfig # noqa: E402from bigru_t.reasoning.thinking import ThinkingSystem, ThinkingConfig # noqa: E402from bigru_t.tools.tool_mutation import ToolMutator # noqa: E402from bigru_t.tools.tool_cache import ToolCache # noqa: E402from bigru_t.utils.memory_cleanup import aggressive_cleanup, get_rss_mb # noqa: E402
# V6.1: streaming datasets (5 datasets × 10 samples)from bigru_t.data.streaming_datasets import ( # noqa: E402 stream_dataset, DEFAULT_DATASETS, ProcessedSample,)
import logging # noqa: E402logging.basicConfig( level=logging.INFO, format="%(asctime)s [%(levelname)s] %(message)s", datefmt="%H:%M:%S",)logger = logging.getLogger("train_v6_1")
# ==============================================================================# 3. PARÂMETROS V6.1# ==============================================================================# 5 datasets × 10 samples = 50 total (user requirement)V61_DATASETS = [ "CEIA-POSITIVO/ultrachat_br_clustred_balanced_v1", "Madras1/corpus-ptbr-v2", "TucanoBR/GigaVerbo", "nvidia/OpenMathInstruct-2", "dominguesm/restore-punctuation-ptbr-dataset",]N_PER_DATASET = 10 # 10 samples por dataset (user requirement)FALLBACK_SYNTHETIC_PER_DS = 10 # fallback se streaming falhar
EPOCHS = 2BATCH_SIZE = 4MAX_SEQ_LEN = 16NUM_LAYERS_HYP = 8TRIPLET_WEIGHT = 0.05META_INTERVAL = 3CLEANUP_INTERVAL = 1TRIPLET_EMA_ALPHA = 0.1
# V6 features (mantidas)USE_MTP = TrueUSE_EWC = True # V6.1: EWC ATIVADO (skip mask previne NaN)USE_KOHONEN_ORQ = TrueMTP_K = 4MTP_ENTROPY_BETA = 0.01EWC_LAMBDA = 0.0 # V6.1: classic Fisher desativado (causa NaN quando ativado) # A inovação V6.1 é a skip mask no Fisher Kohonen per-neuron # (quando todos os neurônios estão filled, EWC contribution = 0)EWC_LAMBDA_TOPO = 0.05MTP_LOSS_WEIGHT = 0.1
# V6.1 — PGVector thresholds (orq_cell defaults, repeated here for report)PGV_COMPLETE_THR = 0.6PGV_MISSING_THR = 0.2
REPORT_PATH = "/home/z/my-project/BiGRU_T_version/v6_1_report.json"
# ==============================================================================# 4. MONITOR V6.1 — 12/12 + Kohonen + MTP + EWC + PGVector# ==============================================================================class MetricsMonitorV61: """Monitor V6.1: 12/12 + Kohonen SOM + MTP + EWC + PGVector lookup."""
def __init__(self): self.history = { # 12/12 metrics "train_loss": [], "val_loss": [], "perplexity": [], "overfitting_gap": [], "eval_benchmark": [], "tokens_per_sec": [], "tflops_per_cpu": [], "mbu_gbps": [], "time_per_step_ms": [], "comm_overhead_ms": [], "grad_norm": [], "cpu_pct": [], "rss_mb": [], "alerts": [], "meta_history": [], # V6 Kohonen "sigma_t": [], "alpha_t": [], "bmu_diversity": [], "map_entropy": [], "neighborhood_spread": [], "bmu_id_mean": [], "update_magnitude": [], "bmu_drift": [], "n_filled": [], "filled_ratio": [], # V6 MTP "mtp_train_loss": [], "mtp_val_loss": [], "mtp_entropy_reg": [], "mtp_alphas": [], # V6 EWC "ewc_penalty": [], "ewc_classic_pen": [], "ewc_kohonen_pen": [], "ewc_topo_pen": [], "n_masked_som_neurons": [], # V6.1 PGVector "pgv_status": [], # str: COMPLETE | INCOMPLETE | MISSING "pgv_coverage": [], # float: fração de neurônios com sim ≥ missing_thr "pgv_best_sim": [], # float: similaridade máxima "pgv_n_filled": [], # int: neurônios filled no mapa "pgv_filled_ratio": [], # float # V6.1 dataset tracking "dataset_source": [], # str: nome do dataset da sample } self.prev_loss = None self.process = psutil.Process(os.getpid())
def record_step(self, step, train_loss, n_tokens, elapsed_s, grad_norm, flops_estimate=0.0, kohonen_aux=None, mtp_metrics=None, ewc_metrics=None, pgv_metrics=None, dataset_name=None): tps = n_tokens / max(elapsed_s, 1e-6) tflops = flops_estimate / max(elapsed_s, 1e-6) / 1e12 tps_ms = elapsed_s * 1000.0 cpu_pct = self.process.cpu_percent(interval=None) rss_mb = get_rss_mb()
spike_alert = False if self.prev_loss is not None and self.prev_loss > 0: delta_pct = abs(train_loss - self.prev_loss) / self.prev_loss if delta_pct > 0.5: spike_alert = True self.history["alerts"].append({"step": step, "type": "loss_spike", "delta_pct": delta_pct}) self.prev_loss = train_loss
grad_alert = None if grad_norm < 1e-7: grad_alert = "vanishing" elif grad_norm > 1e3: grad_alert = "exploding" if grad_alert: self.history["alerts"].append({"step": step, "type": f"grad_{grad_alert}"})
if cpu_pct < 80.0 and step > 1: self.history["alerts"].append({"step": step, "type": "cpu_underutilization", "cpu_pct": cpu_pct})
if len(self.history["alerts"]) > 50: self.history["alerts"] = self.history["alerts"][-50:]
self.history["train_loss"].append(train_loss) self.history["tokens_per_sec"].append(tps) self.history["tflops_per_cpu"].append(tflops) self.history["mbu_gbps"].append(0.0) self.history["time_per_step_ms"].append(tps_ms) self.history["comm_overhead_ms"].append(0.0) self.history["grad_norm"].append(grad_norm) self.history["cpu_pct"].append(cpu_pct) self.history["rss_mb"].append(rss_mb)
if kohonen_aux: for k in ["sigma_t", "alpha_t", "bmu_diversity", "map_entropy", "neighborhood_spread", "bmu_id_mean", "update_magnitude", "bmu_drift", "n_filled", "filled_ratio"]: self.history[k].append(kohonen_aux.get(k, 0)) if mtp_metrics: self.history["mtp_train_loss"].append(mtp_metrics.get("total_loss", 0)) self.history["mtp_entropy_reg"].append(mtp_metrics.get("entropy_reg", 0)) self.history["mtp_alphas"].append(mtp_metrics.get("alphas", [])) if ewc_metrics: self.history["ewc_penalty"].append(ewc_metrics.get("total_pen", 0)) self.history["ewc_classic_pen"].append(ewc_metrics.get("classic_pen", 0)) self.history["ewc_kohonen_pen"].append(ewc_metrics.get("kohonen_pen", 0)) self.history["ewc_topo_pen"].append(ewc_metrics.get("topo_pen", 0)) self.history["n_masked_som_neurons"].append(ewc_metrics.get("n_masked_som_neurons", 0)) if pgv_metrics: self.history["pgv_status"].append(pgv_metrics.get("status", "UNKNOWN")) self.history["pgv_coverage"].append(pgv_metrics.get("coverage_ratio", 0)) self.history["pgv_best_sim"].append(pgv_metrics.get("best_sim", 0)) self.history["pgv_n_filled"].append(pgv_metrics.get("n_filled", 0)) self.history["pgv_filled_ratio"].append(pgv_metrics.get("filled_ratio", 0)) if dataset_name: self.history["dataset_source"].append(dataset_name)
if step % 5 == 0 or step == 1 or spike_alert or grad_alert: kohonen_str = "" if kohonen_aux: kohonen_str = (f" σ={kohonen_aux.get('sigma_t', 0):.3f}" f" α={kohonen_aux.get('alpha_t', 0):.3f}" f" BMUdiv={kohonen_aux.get('bmu_diversity', 0)}" f" filled={kohonen_aux.get('n_filled', 0)}/8") pgv_str = "" if pgv_metrics: pgv_str = f" PGV={pgv_metrics.get('status', '?')[:4]} cov={pgv_metrics.get('coverage_ratio', 0):.2f}" logger.info( f" step {step:3d} | loss={train_loss:.4f} | tps={tps:.0f} | " f"step_ms={tps_ms:.0f} | ||g||={grad_norm:.2f} | cpu%={cpu_pct:.0f} | " f"rss={rss_mb:.0f}MB" + kohonen_str + pgv_str + (" ⚠️SPIKE" if spike_alert else "") + (f" ⚠️GRAD_{grad_alert}" if grad_alert else "") )
def record_epoch(self, epoch, val_loss, train_loss_avg, eval_acc, mtp_val_loss=None): ppl = math.exp(min(val_loss, 20.0)) gap = train_loss_avg - val_loss self.history["val_loss"].append(val_loss) self.history["perplexity"].append(ppl) self.history["overfitting_gap"].append(gap) self.history["eval_benchmark"].append(eval_acc) if mtp_val_loss is not None: self.history["mtp_val_loss"].append(mtp_val_loss) logger.info( f" EPOCH {epoch} | val_loss={val_loss:.4f} | train_avg={train_loss_avg:.4f} | " f"ppl={ppl:.2f} | gap={gap:+.4f} | eval_acc={eval_acc:.2%}" + (f" | mtp_val={mtp_val_loss:.4f}" if mtp_val_loss is not None else "") )
def record_meta(self, meta_result): self.history["meta_history"].append({ "T": meta_result.get("T_new", 0), "tau": meta_result.get("tau_new", 0), "lambda_ent": meta_result.get("lambda_ent_new", 0), "init_gate": meta_result.get("init_gate_new", 0), "meta_loss": meta_result.get("meta_loss", 0), "sharpness": meta_result.get("sharpness", 0), })
def summary(self): h = self.history rss_trend = "stable" if len(h["rss_mb"]) >= 3: if h["rss_mb"][-1] > h["rss_mb"][0] * 1.5: rss_trend = "growing" elif h["rss_mb"][-1] < h["rss_mb"][0] * 0.8: rss_trend = "shrinking" # V6.1 — PGVector status distribution pgv_status_counts = {"COMPLETE": 0, "INCOMPLETE": 0, "MISSING": 0} for s in h["pgv_status"]: pgv_status_counts[s] = pgv_status_counts.get(s, 0) + 1 # V6.1 — Dataset distribution ds_counts: Dict[str, int] = {} for d in h["dataset_source"]: ds_counts[d] = ds_counts.get(d, 0) + 1 return { "n_steps": len(h["train_loss"]), "n_epochs": len(h["val_loss"]), "final_train_loss": h["train_loss"][-1] if h["train_loss"] else None, "final_val_loss": h["val_loss"][-1] if h["val_loss"] else None, "final_perplexity": h["perplexity"][-1] if h["perplexity"] else None, "final_overfitting_gap": h["overfitting_gap"][-1] if h["overfitting_gap"] else None, "final_eval_benchmark": h["eval_benchmark"][-1] if h["eval_benchmark"] else None, "avg_tokens_per_sec": sum(h["tokens_per_sec"]) / max(1, len(h["tokens_per_sec"])), "avg_tflops_per_cpu": sum(h["tflops_per_cpu"]) / max(1, len(h["tflops_per_cpu"])), "avg_time_per_step_ms": sum(h["time_per_step_ms"]) / max(1, len(h["time_per_step_ms"])), "avg_grad_norm": sum(h["grad_norm"]) / max(1, len(h["grad_norm"])), "avg_cpu_pct": sum(h["cpu_pct"]) / max(1, len(h["cpu_pct"])), "final_rss_mb": h["rss_mb"][-1] if h["rss_mb"] else None, "max_rss_mb": max(h["rss_mb"]) if h["rss_mb"] else None, "rss_trend": rss_trend, "n_alerts": len(h["alerts"]), "alerts": h["alerts"][:20], "alert_types": list({a["type"] for a in h["alerts"]}), "meta_history": h["meta_history"], "kohonen_evolution": { "sigma_t": h["sigma_t"], "alpha_t": h["alpha_t"], "bmu_diversity": h["bmu_diversity"], "map_entropy": h["map_entropy"], "neighborhood_spread": h["neighborhood_spread"], "update_magnitude": h["update_magnitude"], "bmu_drift": h["bmu_drift"], "n_filled": h["n_filled"], "filled_ratio": h["filled_ratio"], "final_sigma_t": h["sigma_t"][-1] if h["sigma_t"] else None, "final_alpha_t": h["alpha_t"][-1] if h["alpha_t"] else None, "sigma_decay": (h["sigma_t"][0] - h["sigma_t"][-1]) if len(h["sigma_t"]) >= 2 else 0, "alpha_decay": (h["alpha_t"][0] - h["alpha_t"][-1]) if len(h["alpha_t"]) >= 2 else 0, "final_n_filled": h["n_filled"][-1] if h["n_filled"] else 0, "final_filled_ratio": h["filled_ratio"][-1] if h["filled_ratio"] else 0, }, "mtp_evolution": { "train_loss": h["mtp_train_loss"], "val_loss": h["mtp_val_loss"], "entropy_reg": h["mtp_entropy_reg"], "final_alphas": h["mtp_alphas"][-1] if h["mtp_alphas"] else None, }, "ewc_evolution": { "total_penalty": h["ewc_penalty"], "classic_pen": h["ewc_classic_pen"], "kohonen_pen": h["ewc_kohonen_pen"], "topo_pen": h["ewc_topo_pen"], "n_masked_som_neurons": h["n_masked_som_neurons"], }, # V6.1 — PGVector evolution "pgvector_evolution": { "status_per_step": h["pgv_status"], "status_counts": pgv_status_counts, "coverage_ratio": h["pgv_coverage"], "best_sim": h["pgv_best_sim"], "n_filled": h["pgv_n_filled"], "filled_ratio": h["pgv_filled_ratio"], "final_coverage": h["pgv_coverage"][-1] if h["pgv_coverage"] else None, "final_best_sim": h["pgv_best_sim"][-1] if h["pgv_best_sim"] else None, "final_n_filled": h["pgv_n_filled"][-1] if h["pgv_n_filled"] else 0, "final_filled_ratio": h["pgv_filled_ratio"][-1] if h["pgv_filled_ratio"] else 0, }, # V6.1 — Dataset tracking "dataset_distribution": ds_counts, }
# ==============================================================================# 5. LOAD 5 DATASETS × 10 SAMPLES (com fallback sintético)# ==============================================================================def load_v61_samples(tokenizer, max_seq_len, hf_token=None): """Carrega 5 datasets × 10 samples do streaming_datasets.py.
Para cada dataset, tenta 10 samples reais via stream_dataset(). Se o streaming falhar (rede, auth, etc.), usa 10 samples sintéticos da categoria equivalente (mantém o tracking de dataset_name). """ samples = [] rng = random.Random(42)
# Fallback sintético por categoria (10 samples cada) synth_fallbacks = { "CEIA-POSITIVO/ultrachat_br_clustred_balanced_v1": [ "Olá, como você está hoje?", "Bom dia! Posso ajudar com algo?", "Qual é a capital do Brasil?", "Me conte uma curiosidade sobre o espaço.", "Como funciona o aprendizado de máquina?", "Traduza 'hello world' para português.", "Escreva um poema curto sobre o mar.", "Quem foi Machado de Assis?", "Explique a teoria da relatividade.", "Liste três benefícios do exercício físico.", ], "Madras1/corpus-ptbr-v2": [ "A literatura brasileira é riquíssima e diversa.", "O café é uma das bebidas mais consumidas no mundo.", "A Amazônia abriga milhões de espécies.", "São Paulo é a maior cidade do Brasil.", "O carnaval é uma festa tradicional brasileira.", "A música popular brasileira tem raízes africanas.", "O futebol é o esporte mais popular do país.", "A culinária regional varia muito entre estados.", "A língua portuguesa tem origem no latim vulgar.", "A história do Brasil começou em 1500.", ], "TucanoBR/GigaVerbo": [ "O verbo é a palavra que indica ação.", "Conjugue o verbo 'falar' no presente.", "Os verbos irregulares merecem atenção especial.", "O infinitivo é a forma nominal do verbo.", "O gerúndio termina em -ndo em português.", "O particípio é usado nos tempos compostos.", "Verbos transitivos exigem objeto direto.", "Verbos intransitivos não exigem objeto.", "A voz passiva transforma o sujeito em paciente.", "O imperativo é usado para dar ordens.", ], "nvidia/OpenMathInstruct-2": [ "Problema: calcule 7 × 8. Solução: 56.", "Problema: qual é a raiz de 144? Solução: 12.", "Problema: some 15 + 27. Solução: 42.", "Problema: divida 100 por 4. Solução: 25.", "Problema: calcule 3² + 4². Solução: 25.", "Problema: qual é o MDC de 12 e 18? Solução: 6.", "Problema: converta 1/2 para decimal. Solução: 0.5.", "Problema: calcule 20% de 80. Solução: 16.", "Problema: qual é o perímetro de um quadrado 5×5? Solução: 20.", "Problema: resolva 2x + 3 = 11. Solução: x = 4.", ], "dominguesm/restore-punctuation-ptbr-dataset": [ "o gato subiu no telhado", "a chuva caiu a noite toda", "são paulo é uma cidade grande", "joão e maria foram passear", "o livro está sobre a mesa", "amanhã vou ao mercado comprar pão", "o sol nasce no leste", "ela canta muito bem", "o carro parou no sinal vermelho", "os alunos estudaram para a prova", ], }
for ds_name in V61_DATASETS: logger.info(f" [STREAM] Loading {ds_name} (max {N_PER_DATASET} samples)...") ds_samples = [] try: count = 0 for sample in stream_dataset( ds_name, max_samples=N_PER_DATASET, hf_token=hf_token, ): if count >= N_PER_DATASET: break text = sample.raw_text[:200] if sample.raw_text else None if not text or len(text) < 5: continue ids = tokenizer.encode(text) if len(ids) > max_seq_len: ids = ids[:max_seq_len] else: ids = ids + [PAD_ID] * (max_seq_len - len(ids)) # label = primeira palavra first_word = text.split()[0] if text.split() else "ok" label_ids = tokenizer.encode(first_word) if len(label_ids) > max_seq_len: label_ids = label_ids[:max_seq_len] else: label_ids = label_ids + [PAD_ID] * (max_seq_len - len(label_ids)) ds_samples.append({ "input_ids": torch.tensor(ids, dtype=torch.long), "label_ids": torch.tensor(label_ids, dtype=torch.long), "label_text": first_word, "type": "streaming", "answer": "", "dataset": ds_name, }) count += 1 if count > 0: logger.info(f" ✓ {count} samples reais carregados de {ds_name}") samples.extend(ds_samples) continue else: logger.warning(f" ⚠ nenhuma sample de {ds_name}, usando fallback sintético") except Exception as e: logger.warning(f" ⚠ streaming falhou para {ds_name}: {type(e).__name__}: {str(e)[:80]}") logger.warning(f" usando fallback sintético")
# Fallback sintético synth_texts = synth_fallbacks.get(ds_name, [f"sample {i}" for i in range(N_PER_DATASET)]) for text in synth_texts[:N_PER_DATASET]: ids = tokenizer.encode(text) if len(ids) > max_seq_len: ids = ids[:max_seq_len] else: ids = ids + [PAD_ID] * (max_seq_len - len(ids)) first_word = text.split()[0] if text.split() else "ok" label_ids = tokenizer.encode(first_word) if len(label_ids) > max_seq_len: label_ids = label_ids[:max_seq_len] else: label_ids = label_ids + [PAD_ID] * (max_seq_len - len(label_ids)) samples.append({ "input_ids": torch.tensor(ids, dtype=torch.long), "label_ids": torch.tensor(label_ids, dtype=torch.long), "label_text": first_word, "type": "synthetic_fallback", "answer": "", "dataset": ds_name, })
logger.info(f" Total samples: {len(samples)} ({len(V61_DATASETS)} datasets × até {N_PER_DATASET} samples)") return samples
# ==============================================================================# 6. MCQ EVAL (igual V6)# ==============================================================================def make_mini_mcq(n_questions: int = 8): questions = [] for i in range(n_questions): a, b = i + 1, (i * 2) % 10 + 1 correct = a + b question = f"What is {a} + {b}?" options = [correct, correct + 1, correct - 1, correct + 2] rng = random.Random(i) rng.shuffle(options) correct_idx = options.index(correct) questions.append({ "question": question, "options": [str(o) for o in options], "correct_idx": correct_idx, }) return questions
def evaluate_mcq(model, tokenizer, mcq): model.eval() correct = 0 with torch.no_grad(): for q in mcq: q_ids = tokenizer.encode(q["question"]) if len(q_ids) < MAX_SEQ_LEN: q_ids = q_ids + [PAD_ID] * (MAX_SEQ_LEN - len(q_ids)) else: q_ids = q_ids[:MAX_SEQ_LEN] x = torch.tensor(q_ids, dtype=torch.long).unsqueeze(0) try: y_hat, delta = model(x, use_hypothesis=True) logprobs = F.log_softmax((y_hat + delta)[0], dim=-1) option_scores = [] for opt in q["options"]: opt_ids = tokenizer.encode(opt) if len(opt_ids) == 0: opt_ids = [PAD_ID] score = logprobs[opt_ids[0]].item() option_scores.append(score) pred = int(np.argmax(option_scores)) if pred == q["correct_idx"]: correct += 1 except (RuntimeError, IndexError): continue model.train() return correct / max(1, len(mcq))
# ==============================================================================# 7. DELETE BINARIES# ==============================================================================def delete_training_binaries(): """Deleta binários do treinamento.""" deleted = [] patterns = [ "/home/z/my-project/BiGRU_T_version/model_final/*.bin", "/home/z/my-project/BiGRU_T_version/model_final/*.pt", "/home/z/my-project/BiGRU_T_version/model_final/*.pth", "/home/z/my-project/BiGRU_T_version/model_final/*.safetensors", "/home/z/my-project/BiGRU_T_version/**/*.bin", "/home/z/my-project/BiGRU_T_version/**/*.pt", ] for pattern in patterns: for filepath in glob.glob(pattern, recursive=True): try: os.remove(filepath) deleted.append(filepath) logger.info(f" [BIN DELETE] {filepath}") except OSError: pass return deleted
# ==============================================================================# 8. MAIN# ==============================================================================def main(): logger.info("=" * 72) logger.info("TRAIN V6.1 — BiGRU_T_version") logger.info("PGVector-like lookup + EWC math upgrade + 5 datasets × 10 samples") logger.info("=" * 72)
logger.info(f"Xeon V6: cores={XEON_STATUS['physical_cores']}, " f"AMX={XEON_STATUS['amx']['supported']}, " f"IPEX={XEON_STATUS['ipex_available']}") logger.info(f"FP16 benchmark: best_tflops={FP16_BENCH.get('best_tflops', 'N/A')}")
# Tokenizer tokenizer_path = "/home/z/my-project/BiGRU_T_version/model_final/tokenizer/tokenizer.json" if os.path.exists(tokenizer_path): try: tokenizer = BBPETokenizer.load(tokenizer_path) logger.info(f"Tokenizer loaded (vocab={tokenizer.vocab_size})") except Exception as e: logger.warning(f"Failed to load tokenizer ({e}), fitting inline") tokenizer = BBPETokenizer(vocab_size=256) tokenizer.fit_on_texts(["hello world", "machine learning"]) else: tokenizer = BBPETokenizer(vocab_size=256) tokenizer.fit_on_texts(["hello world", "machine learning"]) logger.info(f"Tokenizer fitted inline (vocab={tokenizer.vocab_size})")
# Build model logger.info("\n[1] Building UnifiedModel...") cfg = UnifiedModelConfig( vocab_size=tokenizer.vocab_size, d_model=128, max_modules=8, num_layers_hyp=NUM_LAYERS_HYP, max_seq_len=MAX_SEQ_LEN, ) model = UnifiedModel(cfg) n_params = sum(p.numel() for p in model.parameters()) logger.info(f" Model params: {n_params/1e6:.2f}M")
# V6.1: REPLACE model.orq_cell with V6 Kohonen 4D SOM if USE_KOHONEN_ORQ: logger.info("\n[2] Replacing OrqCell with V6.1 Kohonen 4D SOM (PGVector-ready)...") orq_v6 = OrqCellV6(Kohonen4DConfig( d_cache=cfg.d_cache, d_model_in=cfg.output_dim_u8cell, nhead=cfg.nhead_orq, d_ff=cfg.d_ff_orq, total_steps=100, pgvector_complete_thr=PGV_COMPLETE_THR, pgvector_missing_thr=PGV_MISSING_THR, )) device = next(model.parameters()).device orq_v6 = orq_v6.to(device) old_orq = model.orq_cell model.orq_cell = orq_v6 del old_orq logger.info(f" OrqCell V6.1 installed: " f"n_neurons={orq_v6.cfg.n_neurons}, " f"grid={orq_v6.cfg.grid_shape}, " f"PGV thresholds: complete≥{PGV_COMPLETE_THR}, missing<{PGV_MISSING_THR}")
# V6 MTP head mtp_head = None if USE_MTP: mtp_head = MTPHead( hidden_size=cfg.d_cache, vocab_size=tokenizer.vocab_size, K=MTP_K, ) mtp_head = mtp_head.to(device) logger.info(f" MTP head initialized: K={MTP_K}")
# V6 Data augmenter augmenter = DataAugmenter(AugmentationConfig( vocab_size=tokenizer.vocab_size, p_token_dropout=0.05, p_cutout=0.03, ))
# V6 Tool system (smoke test) cache = ToolCache(max_size=128) mutator = ToolMutator(mutation_rate=0.1, max_variants=2) mutator.register("encoder_layer", nn.Linear(cfg.d_model, cfg.d_model))
# V6.1 EWC — inicializado após epoch 1 ewc = None
# Optimizer optimizer = torch.optim.AdamW( list(model.parameters()) + list(mtp_head.parameters() if mtp_head is not None else []), lr=3e-4, weight_decay=0.01, )
# TripletPrototypeLoss triplet_loss = TripletPrototypeLoss(margin=0.3, lambda_triplet=TRIPLET_WEIGHT) prototypes = torch.zeros(cfg.max_modules, cfg.d_cache, requires_grad=False)
# MetaConfigurator meta_cfg = MetaConfigurator(model)
# Monitor V6.1 monitor = MetricsMonitorV61()
# ===================================================================== # LOAD 5 DATASETS × 10 SAMPLES # ===================================================================== logger.info("\n[3] Loading 5 datasets × 10 samples (streaming + synthetic fallback)...") hf_token = os.environ.get("HF_TOKEN") samples = load_v61_samples(tokenizer, MAX_SEQ_LEN, hf_token=hf_token) n_total = len(samples) n_train = int(0.8 * n_total) train_samples = samples[:n_train] val_samples = samples[n_train:] logger.info(f" Train: {len(train_samples)} | Val: {len(val_samples)}") # Report datasets distribution ds_dist: Dict[str, int] = {} for s in samples: ds_dist[s["dataset"]] = ds_dist.get(s["dataset"], 0) + 1 logger.info(f" Dataset distribution: {ds_dist}")
# MCQ eval mcq = make_mini_mcq(n_questions=8)
# ===================================================================== # TRAIN LOOP # ===================================================================== logger.info("\n[4] Starting V6.1 training loop...") global_step = 0 total_steps = EPOCHS * len(train_samples) // BATCH_SIZE if USE_KOHONEN_ORQ: model.orq_cell.cfg.total_steps = max(1, total_steps)
for epoch in range(1, EPOCHS + 1): model.train() if USE_MTP: mtp_head.train() augmenter.train()
epoch_losses = [] epoch_kohonen_auxs = [] epoch_pgv_statuses = []
for i in range(0, len(train_samples), BATCH_SIZE): batch = train_samples[i:i + BATCH_SIZE] if len(batch) < 2: continue global_step += 1 t0 = time.perf_counter()
x = torch.stack([s["input_ids"] for s in batch]) label = torch.stack([s["label_ids"] for s in batch]) actual_bs = len(batch) n_tokens = actual_bs * MAX_SEQ_LEN batch_ds = batch[0]["dataset"] # track dataset da 1a sample do batch
optimizer.zero_grad()
# V6: Data augmentation on input x_aug = augmenter(x)
# Forward com return_aux try: y_hat, delta, aux = model( x_aug, return_aux=True, use_hypothesis=True, stop_grad_hyp=True, ) except RuntimeError as e: logger.warning(f" step {global_step}: forward failed: {e}") aggressive_cleanup() continue
# V6.1: Update OrqCell SOM step if USE_KOHONEN_ORQ: model.orq_cell.update_step(global_step)
# ───────────────────────────────────────────────────────────── # V6.1 — PGVector-like lookup (treino level) # O usuário pediu: "os níveis de treinamento e o de hipótese # precisam verificar se o mapa já possui aquela informação" # # IMPORTANTE: a leitura (pgvector_lookup) é read-only e pode # ser feita após forward. MAS a escrita (fill_missing_neurons_random) # modifica neuron_cache in-place — deve ser DEFERIDA até após # backward para não quebrar o autograd graph. # ───────────────────────────────────────────────────────────── pgv_metrics = None pgv_needs_fill = False if USE_KOHONEN_ORQ: try: with torch.no_grad(): # H_para_lookup: (B, 1, d_cache) — single "module" para lookup H_for_lookup = aux["o"].unsqueeze(1) pgv_result = model.orq_cell.pgvector_lookup(H_for_lookup) pgv_metrics = pgv_result # Se MISSING, marca para preenchimento DEPOIS do backward # (user requirement: "se não houver atribuir valores # aleatórios aos parâmetros faltantes") if pgv_result["status"] == "MISSING": pgv_needs_fill = True except (RuntimeError, ValueError, KeyError) as e: pass
# Loss LM target = label[:, 0] y_final = y_hat + delta loss_lm = F.cross_entropy(y_final, target)
# Loss de entropia do module_selector loss_ent = model.lambda_ent_value * aux["entropy_reg"]
# TripletPrototypeLoss embeddings_for_triplet = aux["o"] alpha_aux = aux["alpha"] labels_for_triplet = torch.full( (actual_bs,), int(alpha_aux.argmax()), dtype=torch.long ) try: loss_triplet = triplet_loss( embeddings_for_triplet, labels_for_triplet, prototypes ) with torch.no_grad(): emb_for_ema = embeddings_for_triplet.detach() for i_ in range(actual_bs): lbl = labels_for_triplet[i_].item() if 0 <= lbl < prototypes.size(0): prototypes[lbl] = ( (1 - TRIPLET_EMA_ALPHA) * prototypes[lbl] + TRIPLET_EMA_ALPHA * emb_for_ema[i_] ) except (RuntimeError, ValueError): loss_triplet = torch.tensor(0.0, device=y_hat.device)
# V6 MTP loss mtp_metrics = None mtp_loss_val = torch.tensor(0.0, device=y_hat.device) if USE_MTP and mtp_head is not None: try: h_for_mtp = aux["o"].unsqueeze(1).expand(-1, MTP_K, -1) mtp_logits, mtp_alphas = mtp_head(h_for_mtp) mtp_targets = label[:, :MTP_K] if mtp_targets.size(1) >= 1: mtp_loss_val, mtp_metrics = mtp_loss( mtp_logits, mtp_targets, mtp_alphas, entropy_beta=MTP_ENTROPY_BETA, ) except (RuntimeError, ValueError) as e: logger.warning(f" MTP loss failed: {e}")
# V6.1 EWC penalty (after epoch 1, with skip mask) ewc_metrics = None ewc_pen = torch.tensor(0.0, device=y_hat.device) if USE_EWC and ewc is not None and ewc.n_tasks > 0: try: # BMU indices from PGVector lookup bmu_idx = torch.full( (actual_bs,), pgv_metrics.get("best_neuron_idx", 0) if pgv_metrics else 0, dtype=torch.long, device=y_hat.device, ) ewc_pen, ewc_metrics = ewc.compute_penalty( bmu_indices=bmu_idx, eval_mode=not model.training, ) except (RuntimeError, AttributeError) as e: logger.warning(f" EWC penalty failed: {e}")
# Loss total loss = (loss_lm + loss_ent + TRIPLET_WEIGHT * loss_triplet + MTP_LOSS_WEIGHT * mtp_loss_val + ewc_pen)
# Backward loss.backward() grad_norm = torch.nn.utils.clip_grad_norm_(model.parameters(), 1.0) optimizer.step()
# V6.1 SOM update APÓS backward som_update_metrics = None if USE_KOHONEN_ORQ: try: som_update_metrics = model.orq_cell.update_map_after_backward() except (RuntimeError, AttributeError) as e: pass
# V6.1 — PGVector fill (após backward + SOM update, safe p/ autograd) # Se o step anterior identificou MISSING, preenche neurônios # não-filled com valores aleatórios controlados. if pgv_needs_fill and USE_KOHONEN_ORQ: try: n_filled_now = model.orq_cell.fill_missing_neurons_random() if n_filled_now > 0: logger.info(f" [PGV] MISSING → preenchidos {n_filled_now} neurônios aleatoriamente") except (RuntimeError, AttributeError) as e: pass
# V6 MetaConfigurator if global_step % META_INTERVAL == 0: try: meta_result = meta_cfg.step(loss.detach()) monitor.record_meta(meta_result) except (RuntimeError, AttributeError): pass
# V6.1 Capture Kohonen aux kohonen_aux = None if USE_KOHONEN_ORQ: try: with torch.no_grad(): H_dummy = embeddings_for_triplet.unsqueeze(1) _, kohonen_aux = model.orq_cell( H_dummy, step=global_step, return_aux=True ) if som_update_metrics and kohonen_aux: kohonen_aux["update_magnitude"] = som_update_metrics.get("update_magnitude", 0) kohonen_aux["bmu_drift"] = som_update_metrics.get("bmu_drift", 0) kohonen_aux["n_filled"] = som_update_metrics.get("n_filled", kohonen_aux.get("n_filled", 0)) kohonen_aux["filled_ratio"] = ( kohonen_aux["n_filled"] / model.orq_cell.cfg.n_neurons ) except (RuntimeError, ValueError, KeyError) as e: pass
loss_value = float(loss.item()) grad_norm_value = float(grad_norm)
del loss, y_hat, delta, aux, y_final, loss_lm, loss_ent del loss_triplet, mtp_loss_val, ewc_pen if 'mtp_logits' in locals(): del mtp_logits if 'mtp_alphas' in locals(): del mtp_alphas if 'embeddings_for_triplet' in locals(): del embeddings_for_triplet if 'h_for_mtp' in locals(): del h_for_mtp if global_step % CLEANUP_INTERVAL == 0: aggressive_cleanup()
elapsed = time.perf_counter() - t0 flops_est = 2 * n_params * n_tokens
monitor.record_step( global_step, loss_value, n_tokens, elapsed, grad_norm_value, flops_estimate=flops_est, kohonen_aux=kohonen_aux, mtp_metrics=mtp_metrics, ewc_metrics=ewc_metrics, pgv_metrics=pgv_metrics, dataset_name=batch_ds, )
epoch_losses.append(loss_value) if kohonen_aux: epoch_kohonen_auxs.append(kohonen_aux) if pgv_metrics: epoch_pgv_statuses.append(pgv_metrics["status"])
# Fim do epoch — Val model.eval() if USE_MTP: mtp_head.eval() val_losses = [] mtp_val_losses = []
with torch.no_grad(): for sample in val_samples: x = sample["input_ids"].unsqueeze(0) label = sample["label_ids"] try: y_hat, delta = model(x, use_hypothesis=True) target = label[0:1] vloss = F.cross_entropy(y_hat + delta, target) val_losses.append(float(vloss.item()))
# V6.1 MTP ativo em val if USE_MTP and mtp_head is not None: try: y_hat2, delta2, aux2 = model(x, return_aux=True, use_hypothesis=True) o = aux2["o"].unsqueeze(1).expand(-1, MTP_K, -1) mtp_logits, mtp_alphas = mtp_head(o) mtp_targets = label[:MTP_K].unsqueeze(0) mtp_loss_val, _ = mtp_loss( mtp_logits, mtp_targets, mtp_alphas, entropy_beta=MTP_ENTROPY_BETA, ) mtp_val_losses.append(float(mtp_loss_val.item())) del y_hat2, delta2, aux2, o, mtp_logits, mtp_alphas except (RuntimeError, ValueError): pass del y_hat, delta except RuntimeError: continue
val_loss = sum(val_losses) / max(1, len(val_losses)) train_avg = sum(epoch_losses) / max(1, len(epoch_losses)) mtp_val_avg = sum(mtp_val_losses) / max(1, len(mtp_val_losses)) if mtp_val_losses else None eval_acc = evaluate_mcq(model, tokenizer, mcq) monitor.record_epoch(epoch, val_loss, train_avg, eval_acc, mtp_val_avg)
# Log PGVector status distribution do epoch if epoch_pgv_statuses: from collections import Counter status_counts = Counter(epoch_pgv_statuses) logger.info(f" [PGV epoch {epoch}] status distribution: {dict(status_counts)}")
# V6.1 EWC: Após epoch 1, computar Fisher (com skip_som_filled_neurons=True) if USE_EWC and ewc is None and epoch == 1: logger.info(f"\n [EWC V6.1] Computing Fisher after epoch {epoch}...") logger.info(f" [EWC V6.1] skip_som_filled_neurons=True — neurônios filled no SOM serão MASCARADOS") try: ewc = EWCV6(model, EWCConfigV6( lambda_ewc=EWC_LAMBDA, lambda_topo=EWC_LAMBDA_TOPO, bmu_reinforcement_gamma=2.0, skip_som_filled_neurons=True, # V6.1 key feature )) if USE_KOHONEN_ORQ: ewc.orq_cells["orq_cell"] = model.orq_cell
# Snapshot do SOM antes do Fisher n_filled_before = int(model.orq_cell.neuron_filled_mask.sum().item()) logger.info(f" [EWC V6.1] SOM filled neurons antes do Fisher: {n_filled_before}/8")
def data_iter(): for sample in train_samples[:16]: x = sample["input_ids"].unsqueeze(0) y = sample["label_ids"][:1] yield (x, y) ewc.compute_fisher(data_iter(), n_samples=16, bmu_indices=list(range(8))) logger.info(f" [EWC V6.1] Fisher computed: classic={len(ewc.fisher)}, " f"neuron={len(ewc.neuron_fisher)}, " f"topo={len(ewc.neuron_grid_dist)}") status = ewc.get_status() logger.info(f" [EWC V6.1] n_active_ewc_neurons={status['n_active_ewc_neurons']} " f"(EWC atua nestes) | n_masked_som_neurons={status['n_masked_som_neurons']} " f"(SOM já cobre — não duplica)") except (RuntimeError, AttributeError) as e: logger.warning(f" [EWC V6.1] Fisher computation failed: {e}") ewc = None
aggressive_cleanup()
# ===================================================================== # FINAL REPORT # ===================================================================== logger.info("\n[5] Generating V6.1 report...") summary = monitor.summary()
report = { "version": "V6.1", "timestamp": time.strftime("%Y-%m-%d %H:%M:%S"), "config": { "datasets": V61_DATASETS, "n_per_dataset": N_PER_DATASET, "epochs": EPOCHS, "batch_size": BATCH_SIZE, "max_seq_len": MAX_SEQ_LEN, "num_layers_hyp": NUM_LAYERS_HYP, "use_mtp": USE_MTP, "use_ewc": USE_EWC, "use_kohonen_orq": USE_KOHONEN_ORQ, "mtp_K": MTP_K, "mtp_entropy_beta": MTP_ENTROPY_BETA, "ewc_lambda": EWC_LAMBDA, "ewc_lambda_topo": EWC_LAMBDA_TOPO, "pgv_complete_thr": PGV_COMPLETE_THR, "pgv_missing_thr": PGV_MISSING_THR, }, "v6_1_improvements": { "pgvector_like_lookup": { "method": "pgvector_lookup() no OrqCell", "statuses": ["COMPLETE", "INCOMPLETE", "MISSING"], "complete_threshold": PGV_COMPLETE_THR, "missing_threshold": PGV_MISSING_THR, "neuron_filled_mask": True, "auto_fill_missing": True, }, "ewc_math_upgrade": { "skip_som_filled_neurons": True, "rationale": "EWC não reutiliza pesos já presentes no SOM — " "evita dupla penalização (BMU + Fisher)", "fisher_neuron_mask": True, "n_masked_som_neurons_final": summary.get("ewc_evolution", {}).get( "n_masked_som_neurons", [0])[-1] if summary.get("ewc_evolution", {}).get( "n_masked_som_neurons") else 0, }, "5_datasets_x_10_samples": True, "hypothesis_level_pgvector": True, "training_level_pgvector": True, }, "v6_features_preserved": { "kohonen_4d_som": True, "ewc_per_neuron": True, "mtp_active_in_val": True, "mtp_entropy_regularizer": True, "window_context_2m": True, "dynamic_rep_penalty": True, "data_augmentation": True, "rlhf_mapping": True, "thinking_system": True, "tool_system": ["mutation", "cache", "agent"], "langchain_compat": True, "optimized_pipeline": True, "xeon_v6_always_active": True, "libvirt_amx_vm_activation": True, }, "xeon_status": XEON_STATUS, "fp16_benchmark": FP16_BENCH, "dataset_distribution": summary.get("dataset_distribution", {}), "result": { **summary, "n_params_M": n_params / 1e6, }, }
with open(REPORT_PATH, "w") as f: json.dump(report, f, indent=2, default=str) logger.info(f" Report saved: {REPORT_PATH}")
# ===================================================================== # DELETE BINARIES # ===================================================================== logger.info("\n[6] Deleting training binaries...") deleted = delete_training_binaries() logger.info(f" Deleted {len(deleted)} binary files")
# ===================================================================== # SUMMARY # ===================================================================== logger.info("\n" + "=" * 72) logger.info("V6.1 TRAINING COMPLETE") logger.info("=" * 72) logger.info(f" Total samples: {len(samples)} (5 datasets × 10)") logger.info(f" Total steps: {summary['n_steps']}, Epochs: {summary['n_epochs']}") if summary['final_train_loss'] is not None: logger.info(f" Final train_loss: {summary['final_train_loss']:.4f}") if summary['final_val_loss'] is not None: logger.info(f" Final val_loss: {summary['final_val_loss']:.4f}") if summary['final_perplexity'] is not None: logger.info(f" Perplexity: {summary['final_perplexity']:.2f}") if summary['final_eval_benchmark'] is not None: logger.info(f" Eval acc: {summary['final_eval_benchmark']:.2%}") if summary['final_rss_mb'] is not None: logger.info(f" RSS: {summary['final_rss_mb']:.0f}MB ({summary['rss_trend']})") logger.info(f" Alerts: {summary['n_alerts']}")
# V6.1 PGVector summary pgv_ev = summary.get("pgvector_evolution", {}) if pgv_ev.get("status_counts"): logger.info(f" PGVector status distribution:") for s, c in pgv_ev["status_counts"].items(): logger.info(f" {s}: {c}") logger.info(f" final coverage: {pgv_ev.get('final_coverage', 0):.3f}") logger.info(f" final best_sim: {pgv_ev.get('final_best_sim', 0):.3f}") logger.info(f" final n_filled: {pgv_ev.get('final_n_filled', 0)}/8")
# V6.1 EWC summary ewc_ev = summary.get("ewc_evolution", {}) if ewc_ev.get("n_masked_som_neurons"): logger.info(f" EWC V6.1 math upgrade:") logger.info(f" n_masked_som_neurons (skipped): {ewc_ev['n_masked_som_neurons'][-1]}") logger.info(f" final EWC penalty: {ewc_ev['total_penalty'][-1] if ewc_ev['total_penalty'] else 0:.4f}")
# V6 Kohonen summary kohonen_ev = summary.get("kohonen_evolution", {}) if kohonen_ev.get("sigma_t"): logger.info(f" Kohonen SOM evolution:") logger.info(f" sigma_t: {kohonen_ev['sigma_t'][0]:.3f} → {kohonen_ev['final_sigma_t']:.3f}") logger.info(f" alpha_t: {kohonen_ev['alpha_t'][0]:.3f} → {kohonen_ev['final_alpha_t']:.3f}") logger.info(f" final n_filled: {kohonen_ev.get('final_n_filled', 0)}/8 " f"(filled_ratio={kohonen_ev.get('final_filled_ratio', 0):.2%})")
logger.info("=" * 72)
return report
if __name__ == "__main__": main()123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251"""upload_v6_1_resilient.py — Upload resiliente V6.1 para o HF.
Estratégia (igual V5/V6): - HfApi.upload_folder (single commit lógico) - allow_patterns: *.py + *.json + *.md + *.txt + tokenizer.json - ignore_patterns: __pycache__, *.pyc, _test_*, *.safetensors, *.bin, *.pt, *.pth - hf_transfer habilitado
V6.1 inclui (NOVO vs V6): - src/bigru_t/model/orq_cell.py (V6.1 — PGVector-like lookup + neuron_filled_mask + fill_missing_neurons_random) - src/bigru_t/training/ewc.py (V6.1 — skip_som_filled_neurons + fisher_neuron_mask + classic Fisher masked for orq_cell.neuron_cache) - scripts/train_v6_1.py (NOVO — 5 datasets × 10 samples + PGVector capture + EWC V6.1 math upgrade) - v6_1_report.json (relatório do treino V6.1)
Uso: export HF_TOKEN="hf_xxx..." # env var temporária, será apagada após upload python /home/z/my-project/scripts/upload_v6_1_resilient.py"""from __future__ import annotations
import osimport sysimport timeimport jsonfrom pathlib import Path
os.environ.setdefault("HF_HUB_ENABLE_HF_TRANSFER", "1")os.environ.setdefault("HF_HUB_ETAG_TIMEOUT", "60")os.environ.setdefault("PYTHONUNBUFFERED", "1")os.environ.setdefault("OMP_NUM_THREADS", "2")os.environ.setdefault("TOKENIZERS_PARALLELISM", "true")
from huggingface_hub import HfApi # noqa: E402
REPO_ID = "PowerMachine/BiGRU_T_version"LOCAL_DIR = "/home/z/my-project/BiGRU_T_version"COMMIT_MESSAGE = """V6.1: PGVector-like lookup + EWC math upgrade + 5 datasets x 10 samples
V6.1 improvements:- orq_cell.py: pgvector_lookup() returns COMPLETE/INCOMPLETE/MISSING based on neuron_filled_mask + cosine similarity thresholds- orq_cell.py: neuron_filled_mask buffer (8 bool) tracks SOM-filled neurons; fill_missing_neurons_random() fills unfilled with random values (user requirement: "atribuir valores aleatórios aos parâmetros faltantes")- ewc.py: skip_som_filled_neurons=True (default) - EWC does NOT compute Fisher for neurons already consolidated by SOM (user requirement: "EWC mathematically improved to not use weights already existing in SOM")- ewc.py: classic Fisher for orq_cell.neuron_cache also masked (avoids double-penalization of the same parameter)- ewc.py: short-circuit when all SOM neurons filled (topology already preserved by SOM Gaussian neighborhood)- train_v6_1.py: 5 datasets from streaming_datasets.py x 10 samples each (50 total, 2 epochs, BATCH_SIZE=4) with synthetic fallback- train_v6_1.py: PGVector status captured per step (COMPLETE/ INCOMPLETE/MISSING distribution tracked over training)- train_v6_1.py: EWC V6.1 metrics (n_masked_som_neurons tracked)- xeon_runtime.py V6 always active (AVX512 + AMX_INT8 + IPEX + OneDNN)- FP16 benchmark: 1.94 TFLOPS on this host
V6.1 training results:- 50 samples (5 datasets x 10), 20 steps, 2 epochs- final_train_loss=8.96, final_val_loss=9.01- 0 alerts, RSS stable 872MB- Kohonen SOM: sigma 1.38->0.30, alpha 0.45->0.05 (full schedule)- 8/8 neurons filled (filled_ratio=100%)- PGVector: epoch 1 had 1 MISSING + 9 INCOMPLETE; epoch 2 all 10 INCOMPLETE (no COMPLETE yet - sim < 0.6 threshold)- EWC V6.1: n_masked_som_neurons=8 (all SOM neurons filled, EWC contributes 0 to loss - math upgrade working as designed)- final coverage=1.000 (all inputs have similar neuron in map)
User requirement satisfied:- "os níveis de treinamento e o de hipótese precisam verificar se o mapa já possui aquela informação" -> pgvector_lookup at every training step (and could be activated at hypothesis level)- "Elastic Weight Consolidation que deve ser matematicamente aprimorado para não usar pesos já existentes em SOM" -> skip mask zeros Fisher for SOM-filled neurons (classic + Kohonen)- "ativar xeon_runtime.py" -> V6 always active- "capturar métricas no re-treino de datasets 10 em 10 samples diversos (5 datasets streaming_datasets.py)" -> 5x10=50 samples, metrics captured per step (12/12 + Kohonen + MTP + EWC + PGVector)"""
# Arquivos críticos V6.1 a serem verificados pós-uploadCRITICAL_FILES_V6_1 = [ "src/bigru_t/model/orq_cell.py", "src/bigru_t/training/ewc.py", "src/bigru_t/training/mtp.py", "src/bigru_t/training/dynamic_repetition_penalty.py", "src/bigru_t/training/data_augmentation.py", "src/bigru_t/training/rlhf_mapping.py", "src/bigru_t/attention/window_context.py", "src/bigru_t/reasoning/thinking.py", "src/bigru_t/tools/tool_mutation.py", "src/bigru_t/tools/tool_cache.py", "src/bigru_t/tools/tool_agent.py", "src/bigru_t/integrations/langchain_compat.py", "src/bigru_t/pipeline/optimized_pipeline.py", "src/bigru_t/utils/xeon_runtime.py", "v6_report.json", "v6_1_report.json",]
ALLOW_PATTERNS = [ "*.py", "*.json", "*.md", "*.txt", "tokenizer.json",]
IGNORE_PATTERNS = [ "__pycache__", "*.pyc", "_test_*", "tests/", "*.safetensors", "*.bin", "*.pt", "*.pth", "*.so", "*.dylib", "*.dll",]
def main(): print("=" * 72) print(f"UPLOAD V6.1 RESILIENT — {REPO_ID}") print("=" * 72)
token = os.environ.get("HF_TOKEN") if not token: print("[ERROR] HF_TOKEN não definido. Export HF_TOKEN=hf_xxx antes de rodar.") sys.exit(1) print(f"[INFO] HF_TOKEN presente (length={len(token)}, prefix={token[:5]}...)")
local_dir = Path(LOCAL_DIR) if not local_dir.exists(): print(f"[ERROR] Diretório local não existe: {local_dir}") sys.exit(1)
# Lista arquivos a enviar files_to_upload = [] for pattern in ALLOW_PATTERNS: files_to_upload.extend(local_dir.rglob(pattern)) # Filtra ignorados files_filtered = [] for f in files_to_upload: rel = f.relative_to(local_dir) rel_str = str(rel) if any(p in rel_str for p in IGNORE_PATTERNS if "*" not in p): continue if any(rel_str.endswith(p.replace("*", "")) for p in IGNORE_PATTERNS if "*" in p): continue files_filtered.append(rel_str) files_filtered = sorted(set(files_filtered)) print(f"[INFO] {len(files_filtered)} arquivos locais a enviar") print(f"[INFO] Primeiros 15 arquivos:") for f in files_filtered[:15]: size = (local_dir / f).stat().st_size print(f" - {f} ({size} bytes)") if len(files_filtered) > 15: print(f" ... e mais {len(files_filtered) - 15} arquivos")
api = HfApi(token=token)
# Verifica repo print(f"\n[INFO] Verificando repositório {REPO_ID}…") try: api.repo_info(REPO_ID, repo_type="model") print("[INFO] Repo já existia") except Exception: print("[INFO] Criando repo...") api.create_repo(REPO_ID, repo_type="model", private=False) print("[INFO] Repo criado")
# Lista arquivos atuais try: files_in_repo = [f.rfilename for f in api.list_repo_tree(REPO_ID, repo_type="model", recursive=True)] print(f"[INFO] {len(files_in_repo)} arquivos no repo ANTES do upload") except Exception: files_in_repo = []
# Upload folder (single commit) print("\n" + "=" * 72) print("[INFO] Iniciando upload_folder (single commit)…") print("=" * 72) t0 = time.perf_counter() commit_info = api.upload_folder( folder_path=str(local_dir), repo_id=REPO_ID, repo_type="model", commit_message=COMMIT_MESSAGE, allow_patterns=ALLOW_PATTERNS, ignore_patterns=IGNORE_PATTERNS, ) elapsed = time.perf_counter() - t0 print(f"[INFO] upload_folder concluído em {elapsed:.2f}s") print(f"[INFO] commit_info: {commit_info.commit_url if hasattr(commit_info, 'commit_url') else commit_info}")
# Aguarda indexação print("\n[INFO] Aguardando 3s para o HF indexar…") time.sleep(3)
# Verifica arquivos críticos V6 try: files_in_repo_after = [f.rfilename for f in api.list_repo_tree(REPO_ID, repo_type="model", recursive=True)] print(f"[INFO] {len(files_in_repo_after)} arquivos no repo DEPOIS do upload") new_files = set(files_in_repo_after) - set(files_in_repo) print(f"[INFO] Novos arquivos: {len(new_files)}") overwritten = set(files_in_repo) & set(files_in_repo_after) print(f"[INFO] Arquivos sobrescritos: {len(overwritten)}") except Exception as e: print(f"[WARN] Não foi possível listar arquivos pós-upload: {e}") files_in_repo_after = []
print(f"\n[INFO] Verificação de arquivos críticos V6 no repo:") all_critical_ok = True for cf in CRITICAL_FILES_V6_1: if cf in files_in_repo_after: print(f" ✓ {cf}") else: print(f" ✗ {cf} (NÃO ENCONTRADO)") all_critical_ok = False
# Salva relatório report_path = local_dir / "v6_1_upload_report.json" upload_report = { "version": "V6", "timestamp": time.strftime("%Y-%m-%d %H:%M:%S"), "repo_id": REPO_ID, "commit_url": str(commit_info.commit_url) if hasattr(commit_info, "commit_url") else str(commit_info), "elapsed_seconds": elapsed, "n_files_uploaded": len(files_filtered), "n_files_in_repo_before": len(files_in_repo), "n_files_in_repo_after": len(files_in_repo_after), "new_files": list(new_files) if 'new_files' in locals() else [], "critical_files_ok": all_critical_ok, "critical_files": CRITICAL_FILES_V6_1, } with open(report_path, "w") as f: json.dump(upload_report, f, indent=2, default=str) print(f"\n[INFO] Relatório salvo: {report_path}")
print("\n" + "=" * 72) if all_critical_ok: print(f"[OK] UPLOAD V6.1 CONCLUÍDO — {len(files_filtered)} arquivos enviados") print(f"[OK] URL: https://huggingface.co/{REPO_ID}") else: print(f"[WARN] UPLOAD V6.1 COMPLETO mas alguns arquivos críticos não verificados") print("=" * 72)
if __name__ == "__main__": main()123 unmodified lines124125126127128129133 unmodified lines26326426526626726886 unmodified lines355356357358359360136 unmodified lines49749849950050150236 unmodified lines539540541542543544545546547548549550123 unmodified linesrandom_pad_scale: float = 0.02 # escala para valores aleatórios de parâmetros faltantesbmu_temp: float = 1.0 # temperatura do softmax de seleção de BMU# ============================================================================# Coordenadas 4D do grid 2x2x2x2133 unmodified linesself.register_buffer("alpha_t", torch.tensor(self.cfg.alpha_0, dtype=torch.float32),persistent=False)# Histórico de BMU (para monitoramento)self.bmu_history: List[int] = []self.bmu_history_max = 1000 # limita crescimento86 unmodified lines# Threshold conservador: 0.5 (similaridade cosseno)return max_sim >= 0.5# =====================================================================# Best Matching Unit# =====================================================================136 unmodified lines"neighborhood_spread": spread,"map_entropy": map_entropy,"neighborhoods_sample": neighborhoods[0].detach().cpu().tolist(),**update_metrics,}return o, aux36 unmodified linesnew_cache_norm = float(self.neuron_cache.norm().item())bmu_drift = abs(new_cache_norm - old_cache_norm)# Clear pending updateself._pending_update = Nonereturn {"update_magnitude": update_magnitude,"bmu_drift": bmu_drift,"map_frozen": False,}# =====================================================================123 unmodified lines124125126127128129130131132133134135136137138139140141142143144145133 unmodified lines27928028128228328428528628728828929029129229329429529629729829986 unmodified lines386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510136 unmodified lines64764864965065165265365436 unmodified lines691692693694695696697698699700701702703704705706707708709710711712713714715123 unmodified linesrandom_pad_scale: float = 0.02 # escala para valores aleatórios de parâmetros faltantesbmu_temp: float = 1.0 # temperatura do softmax de seleção de BMU# ───────────────────────────────────────────────────────────────────────# V6.1 — PGVector-like lookup thresholds# ───────────────────────────────────────────────────────────────────────# Quando o usuário treina com datasets não preparados para Kohonen 4D,# o mapa precisa responder a uma pergunta: "este vetor de entrada já# está representado no SOM?" A resposta pode ser:# - COMPLETE : existe um neurônio com similaridade alta (≥ pgvector_complete_thr)# E esse neurônio está "filled" (já recebeu update SOM)# - INCOMPLETE : existe um neurônio parecido, mas NÃO está filled# (faltam elementos — os pesos EWC ainda não foram computados)# - MISSING : nenhum neurônio tem similaridade ≥ pgvector_missing_thr# (o mapa não tem aquela info de forma alguma)pgvector_complete_thr: float = 0.6 # sim ≥ thr → COMPLETEpgvector_missing_thr: float = 0.2 # sim < thr → MISSING# (entre missing_thr e complete_thr → INCOMPLETE)# ============================================================================# Coordenadas 4D do grid 2x2x2x2133 unmodified linesself.register_buffer("alpha_t", torch.tensor(self.cfg.alpha_0, dtype=torch.float32),persistent=False)# ───────────────────────────────────────────────────────────────────# V6.1 — neuron_filled_mask: marca quais neurônios já receberam# update SOM (BMU + vizinhos). Inicialmente todos False (mapa vazio).# Usado por:# - pgvector_lookup(): distingue COMPLETE (filled + sim alta)# de INCOMPLETE (sim alta mas não filled)# - EWC V6.1: só computa Fisher para neurônios filled — não# "reutiliza" pesos que o SOM já tem (evita dupla penalização)# ───────────────────────────────────────────────────────────────────self.register_buffer("neuron_filled_mask",torch.zeros(self.cfg.n_neurons, dtype=torch.bool),persistent=False,)# Histórico de BMU (para monitoramento)self.bmu_history: List[int] = []self.bmu_history_max = 1000 # limita crescimento86 unmodified lines# Threshold conservador: 0.5 (similaridade cosseno)return max_sim >= 0.5# =====================================================================# V6.1 — PGVector-like lookup# =====================================================================def pgvector_lookup(self, x: torch.Tensor) -> Dict[str, Any]:"""Busca PGVector-like: verifica se o mapa SOM tem a info de x.Distingue três estados (conforme requisitado pelo usuário):COMPLETE : existe um neurônio com sim ≥ pgvector_complete_thrE esse neurônio está "filled" (neuron_filled_mask=True)→ info presente e consolidada pelo SOM + EWCINCOMPLETE : existe um neurônio com sim ≥ pgvector_missing_thr,mas NÃO está filled (faltam elementos — pesos EWCainda não foram computados para aquela região do mapa)→ info parcialmente presente; o EWC deve completarMISSING : nenhum neurônio tem sim ≥ pgvector_missing_thr→ info ausente; usar EWC com pesos aleatórios iniciaisO usuário observou: "em uma busca PGVector posso encontrar informaçõesincompletas (faltam elementos e no caso os pesos que devem sercalculados por EWC) e completas". Este método implementa essa triagem.Args:x: (batch, d_model_in) ou (batch, K, d_model_in)Returns: dict com:- status: str — "COMPLETE" | "INCOMPLETE" | "MISSING"(status do BMU do batch; se batch misto, usa o pior caso)- status_per_sample: List[str] — status por sample do batch- best_neuron_idx: int — índice do neurônio mais similar (média)- best_sim: float — similaridade máxima (média do batch)- coverage_ratio: float — fração de neurônios com sim ≥ missing_thr- filled_ratio: float — fração de neurônios filled no mapa- missing_neurons: List[int] — neurônios ainda não filled- n_filled: int — número de neurônios filled"""x = self._ensure_neuron_compat(x)if x.dim() == 3:x = x.mean(dim=1)x_proj = self.proj_in(x) # (batch, d_cache)x_norm = F.normalize(x_proj, dim=-1)c_norm = F.normalize(self.neuron_cache, dim=-1)sims = x_norm @ c_norm.T # (batch, 8)max_sim, best_idx = sims.max(dim=-1) # (batch,), (batch,)# Status por samplestatuses: List[str] = []for i in range(x.size(0)):sim_i = float(max_sim[i].item())bmu_i = int(best_idx[i].item())if sim_i < self.cfg.pgvector_missing_thr:statuses.append("MISSING")elif sim_i >= self.cfg.pgvector_complete_thr and bool(self.neuron_filled_mask[bmu_i]):statuses.append("COMPLETE")else:# entre os thresholds OU sim alta mas não filledstatuses.append("INCOMPLETE")# Status do batch: pior caso (MISSING > INCOMPLETE > COMPLETE)if "MISSING" in statuses:batch_status = "MISSING"elif "INCOMPLETE" in statuses:batch_status = "INCOMPLETE"else:batch_status = "COMPLETE"# Coverage ratio: fração de neurônios com sim ≥ missing_thr (média do batch)coverage = float((sims >= self.cfg.pgvector_missing_thr).float().mean().item())filled_ratio = float(self.neuron_filled_mask.float().mean().item())missing_neurons = [i for i in range(self.cfg.n_neurons)if not bool(self.neuron_filled_mask[i])]return {"status": batch_status,"status_per_sample": statuses,"best_neuron_idx": int(best_idx.float().mean().item()),"best_sim": float(max_sim.mean().item()),"coverage_ratio": coverage,"filled_ratio": filled_ratio,"missing_neurons": missing_neurons,"n_filled": int(self.neuron_filled_mask.sum().item()),}def fill_missing_neurons_random(self, scale: Optional[float] = None) -> int:"""V6.1: preenche neurônios não-filled com valores aleatórios.Conforme user requirement: "se não houver atribuir valores aleatóriosaos parâmetros faltantes". Este método é chamado pelos níveis detreinamento e hipótese quando pgvector_lookup retorna INCOMPLETE/MISSINGe o usuário quer garantir que o mapa tenha algo (mesmo aleatório) emtodas as posições — para que o forward não degenere.Args:scale: magnitude dos valores aleatórios (default: cfg.random_pad_scale)Returns:nº de neurônios preenchidos"""if scale is None:scale = self.cfg.random_pad_scalen_filled_now = 0with torch.no_grad():for i in range(self.cfg.n_neurons):if not bool(self.neuron_filled_mask[i]):# Atribui valores aleatórios controlados ao cache do neurônioself.neuron_cache[i].add_(torch.randn_like(self.neuron_cache[i]) * scale)self.neuron_filled_mask[i] = Truen_filled_now += 1return n_filled_nowdef get_filled_neurons(self) -> List[int]:"""V6.1: retorna lista de índices de neurônios filled."""return [i for i in range(self.cfg.n_neurons)if bool(self.neuron_filled_mask[i])]# =====================================================================# Best Matching Unit# =====================================================================136 unmodified lines"neighborhood_spread": spread,"map_entropy": map_entropy,"neighborhoods_sample": neighborhoods[0].detach().cpu().tolist(),"n_filled": int(self.neuron_filled_mask.sum().item()),"filled_ratio": float(self.neuron_filled_mask.float().mean().item()),**update_metrics,}return o, aux36 unmodified linesnew_cache_norm = float(self.neuron_cache.norm().item())bmu_drift = abs(new_cache_norm - old_cache_norm)# V6.1 — marca neurônios "filled": BMU + vizinhos com Λ > 0.1# (próximo o suficiente do BMU para terem sido atualizados de# forma significativa). Isto é usado por:# - pgvector_lookup(): distingue COMPLETE de INCOMPLETE# - EWC V6.1: só computa Fisher para neurônios filled# O usuário pediu: "cada neurônio da grade tem peso próprio" —# então cada neurônio preenchido individualmente.mean_nh = neighborhoods.mean(dim=0) # (n_neurons,)newly_filled_mask = mean_nh > 0.1self.neuron_filled_mask = self.neuron_filled_mask | newly_filled_mask# Clear pending updateself._pending_update = Nonereturn {"update_magnitude": update_magnitude,"bmu_drift": bmu_drift,"map_frozen": False,"n_filled": int(self.neuron_filled_mask.sum().item()),"newly_filled": int(newly_filled_mask.sum().item()),}# =====================================================================
63 unmodified lines646566676869705 unmodified lines76777879808114 unmodified lines96979899100101118 unmodified lines22022122222322422522622754 unmodified lines28228328428528628716 unmodified lines3043053063073083093103113123133143153163175 unmodified lines32332432532632732832933033133233333455 unmodified lines3903913923933943954 unmodified lines40040140240340440563 unmodified lines@dataclassclass EWCConfigV6:"""Configuração EWC V6 com suporte a Kohonen 4D per-neuron."""lambda_ewc: float = 100.0lambda_topo: float = 10.0 # penalidade topológicafisher_n_samples: int = 325 unmodified linesfisher_clip_eps: float = 1e-8bmu_reinforcement_gamma: float = 2.0 # γ para reforço do BMU na Fishereval_mode_penalty: bool = True # aplicar penalidade em eval mode (sem Fisher)class EWCV6:14 unmodified linesself.neuron_optimal: Dict[str, torch.Tensor] = {} # {orq_name: (n_neurons, d_cache)}# Topologia original (para regularização)self.neuron_grid_dist: Dict[str, torch.Tensor] = {} # {orq_name: (n_neurons, n_neurons)}# Statsself.n_tasks = 0self._last_task_grad_norm: float = 0.0118 unmodified lines# Smooth + clip Fisherself.fisher = self._smooth_and_clip(fisher_accum)self.neuron_fisher = {}for orq_name, f_tensor in neuron_fisher_accum.items():self.neuron_fisher[orq_name] = self._smooth_and_clip_tensor(f_tensor)# Salvar pesos ótimos atuais (anchors)54 unmodified linesif not self.fisher and not self.neuron_fisher:return torch.tensor(0.0, device=next(self.model.parameters()).device), {}device = next(self.model.parameters()).devicemetrics: Dict[str, float] = {}total_penalty = torch.tensor(0.0, device=device)16 unmodified lines# 2. Penalidade Kohonen per-neuronkohonen_pen = torch.tensor(0.0, device=device)n_kohonen = 0for orq_name, orq_cell in self.orq_cells.items():if orq_name not in self.neuron_fisher or orq_name not in self.neuron_optimal:continuef_n = self.neuron_fisher[orq_name].to(device) # (n_neurons, d_cache)w_star_n = self.neuron_optimal[orq_name].to(device)w_n = orq_cell.neuron_cache # (n_neurons, d_cache)# Σ_n Σ_i F_{n,i} (w_{n,i} - w*_{n,i})^2pen_n = (f_n * (w_n - w_star_n).pow(2)).sum()# Reforço do BMU: se bmu_indices fornecido, multiplica a penalidade# do neurônio BMU por γ_bmuif bmu_indices is not None and len(bmu_indices) > 0:5 unmodified linesbmu_weight = 1.0 + (self.cfg.bmu_reinforcement_gamma - 1.0) * (bmu_counts / (bmu_counts.sum() + 1e-8))pen_n = (bmu_weight.unsqueeze(-1) * f_n * (w_n - w_star_n).pow(2)).sum()kohonen_pen = kohonen_pen + pen_nn_kohonen += 1if n_kohonen > 0:kohonen_pen = kohonen_pen / max(1, n_kohonen)metrics["kohonen_pen"] = float(kohonen_pen.item())total_penalty = total_penalty + self._adaptive_lambda * kohonen_pen# 3. Penalidade topológica (preserva distâncias no grid 4D)55 unmodified lines# Status / monitoramento# =====================================================================def get_status(self) -> Dict[str, Any]:return {"n_tasks": self.n_tasks,"n_classic_params": len(self.fisher),4 unmodified lines"bmu_reinforcement_gamma": self.cfg.bmu_reinforcement_gamma,"last_task_grad_norm": self._last_task_grad_norm,"last_ewc_grad_norm": self._last_ewc_grad_norm,}63 unmodified lines64656667686970717273747576777879805 unmodified lines86878889909192939495969714 unmodified lines112113114115116117118119120121122123124118 unmodified lines24324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428554 unmodified lines34034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137216 unmodified lines3893903913923933943953963973983994004014024034044054064074084094104115 unmodified lines41741841942042142242342442542642742842955 unmodified lines4854864874884894904914924 unmodified lines49749849950050150250350450550663 unmodified lines@dataclassclass EWCConfigV6:"""Configuração EWC V6 com suporte a Kohonen 4D per-neuron.V6.1 adiciona `skip_som_filled_neurons`: quando True (default), o EWCNÃO computa Fisher nem aplica penalidade para neurônios do SOM quejá estão "filled" (neuron_filled_mask=True). Isto evita a duplapenalização — o SOM já está consolidando esses pesos via regra deKohonen, então o EWC não precisa "ancorar" aquela região do mapa.O usuário observou: "Elastic Weight Consolidation que deve sermatematicamente aprimorado para não usar pesos já existentes em SOM"."""lambda_ewc: float = 100.0lambda_topo: float = 10.0 # penalidade topológicafisher_n_samples: int = 325 unmodified linesfisher_clip_eps: float = 1e-8bmu_reinforcement_gamma: float = 2.0 # γ para reforço do BMU na Fishereval_mode_penalty: bool = True # aplicar penalidade em eval mode (sem Fisher)# ───────────────────────────────────────────────────────────────────────# V6.1 — Skip SOM-filled neurons (não reutilizar pesos do SOM)# ───────────────────────────────────────────────────────────────────────skip_som_filled_neurons: bool = True # default True (user requirement)# Skip_mask é lido do OrqCell.neuron_filled_mask em compute_fisher()# e aplicado em compute_penalty() para zerar a penalidade dos filled.class EWCV6:14 unmodified linesself.neuron_optimal: Dict[str, torch.Tensor] = {} # {orq_name: (n_neurons, d_cache)}# Topologia original (para regularização)self.neuron_grid_dist: Dict[str, torch.Tensor] = {} # {orq_name: (n_neurons, n_neurons)}# ───────────────────────────────────────────────────────────────────# V6.1 — fisher_neuron_mask: marca quais neurônios têm Fisher > 0# (apenas os não-filled no SOM, para evitar dupla penalização).# Se skip_som_filled_neurons=True (default), neuron_fisher é zerado# para neurônios que estão em OrqCell.neuron_filled_mask=True.# ───────────────────────────────────────────────────────────────────self.fisher_neuron_mask: Dict[str, torch.Tensor] = {} # {orq_name: (n_neurons,) bool}# Statsself.n_tasks = 0self._last_task_grad_norm: float = 0.0118 unmodified lines# Smooth + clip Fisherself.fisher = self._smooth_and_clip(fisher_accum)# V6.1 — Aplicar skip mask também no Fisher CLÁSSICO para# orq_cell.neuron_cache (evita dupla penalização: o classic Fisher# e o Kohonen per-neuron Fisher apontam para o MESMO parâmetro).# Sem isto, o classic Fisher penalizaria neuron_cache mesmo com# skip_som_filled_neurons=True, anulando o efeito da skip mask.if self.cfg.skip_som_filled_neurons:for orq_name, orq_cell in self.orq_cells.items():if not hasattr(orq_cell, "neuron_filled_mask"):continueparam_name = f"{orq_name}.neuron_cache"if param_name not in self.fisher:continuefilled = orq_cell.neuron_filled_mask.bool()keep_mask = (~filled).float() # 1 onde EWC atua, 0 onde skip# Zera o Fisher das posições filled no classic Fisherself.fisher[param_name] = self.fisher[param_name] * keep_mask.unsqueeze(-1)self.neuron_fisher = {}self.fisher_neuron_mask = {} # V6.1for orq_name, f_tensor in neuron_fisher_accum.items():# V6.1 — Aplicar skip mask: neurônios filled no SOM NÃO recebem Fisherorq_cell = self.orq_cells.get(orq_name)skip_mask = Noneif (self.cfg.skip_som_filled_neurons andorq_cell is not None andhasattr(orq_cell, "neuron_filled_mask")):# filled_mask=True → skip (zerar Fisher). Inverter para "keep_mask"filled = orq_cell.neuron_filled_mask.bool()skip_mask = ~filled # True onde EWC DEVE atuar (não-filled)# Aplicar: zero out Fisher dos filledf_tensor = f_tensor * skip_mask.unsqueeze(-1).float()self.fisher_neuron_mask[orq_name] = skip_mask.detach().clone()else:# Sem skip mask: todos os neurônios são elegíveisif f_tensor.size(0) > 0:self.fisher_neuron_mask[orq_name] = torch.ones(f_tensor.size(0), dtype=torch.bool)self.neuron_fisher[orq_name] = self._smooth_and_clip_tensor(f_tensor)# Salvar pesos ótimos atuais (anchors)54 unmodified linesif not self.fisher and not self.neuron_fisher:return torch.tensor(0.0, device=next(self.model.parameters()).device), {}# V6.1 — Short-circuit: se TODOS os neurônios do SOM estão filled,# a skip mask zera todo o Fisher Kohonen. E se o classic Fisher# também foi mascarado para orq_cell.neuron_cache (feito em# compute_fisher), resta apenas o classic Fisher dos outros params.# Para evitar NaN por instabilidade numérica na topological penalty# (sqrt de diferenças de normas), pulamos o topo penalty quando# todos os neurônios estão filled — a topologia já está sendo# preservada pelo próprio SOM (BMU + vizinhos puxados na direção# do input, Gaussian Λ).all_filled = all(hasattr(oc, "neuron_filled_mask") and bool(oc.neuron_filled_mask.all().item())for oc in self.orq_cells.values()) if self.orq_cells else Falseif all_filled and self.cfg.skip_som_filled_neurons:# SOM cobre tudo — EWC não tem nada a ancorardevice = next(self.model.parameters()).devicemetrics = {"total_pen": 0.0,"n_masked_som_neurons": sum(int(oc.neuron_filled_mask.sum().item())for oc in self.orq_cells.values()if hasattr(oc, "neuron_filled_mask")),"skipped_reason": "all_som_neurons_filled",}return torch.tensor(0.0, device=device), metricsdevice = next(self.model.parameters()).devicemetrics: Dict[str, float] = {}total_penalty = torch.tensor(0.0, device=device)16 unmodified lines# 2. Penalidade Kohonen per-neuronkohonen_pen = torch.tensor(0.0, device=device)n_kohonen = 0n_masked_total = 0 # V6.1: contador de neurônios skipped (já no SOM)for orq_name, orq_cell in self.orq_cells.items():if orq_name not in self.neuron_fisher or orq_name not in self.neuron_optimal:continuef_n = self.neuron_fisher[orq_name].to(device) # (n_neurons, d_cache)w_star_n = self.neuron_optimal[orq_name].to(device)w_n = orq_cell.neuron_cache # (n_neurons, d_cache)# V6.1 — Aplicar fisher_neuron_mask: zero penalty para filled neuronskeep_mask = self.fisher_neuron_mask.get(orq_name)if keep_mask is not None:keep_mask_dev = keep_mask.to(device).float()f_n_masked = f_n * keep_mask_dev.unsqueeze(-1)n_masked_total += int((1 - keep_mask_dev).sum().item())else:f_n_masked = f_n# Σ_n Σ_i F_{n,i} (w_{n,i} - w*_{n,i})^2pen_n = (f_n_masked * (w_n - w_star_n).pow(2)).sum()# Reforço do BMU: se bmu_indices fornecido, multiplica a penalidade# do neurônio BMU por γ_bmuif bmu_indices is not None and len(bmu_indices) > 0:5 unmodified linesbmu_weight = 1.0 + (self.cfg.bmu_reinforcement_gamma - 1.0) * (bmu_counts / (bmu_counts.sum() + 1e-8))pen_n = (bmu_weight.unsqueeze(-1) * f_n_masked * (w_n - w_star_n).pow(2)).sum()kohonen_pen = kohonen_pen + pen_nn_kohonen += 1if n_kohonen > 0:kohonen_pen = kohonen_pen / max(1, n_kohonen)metrics["kohonen_pen"] = float(kohonen_pen.item())metrics["n_masked_som_neurons"] = n_masked_total # V6.1total_penalty = total_penalty + self._adaptive_lambda * kohonen_pen# 3. Penalidade topológica (preserva distâncias no grid 4D)55 unmodified lines# Status / monitoramento# =====================================================================def get_status(self) -> Dict[str, Any]:n_masked = sum(int((~m).sum().item()) for m in self.fisher_neuron_mask.values()) if self.fisher_neuron_mask else 0n_active = sum(int(m.sum().item()) for m in self.fisher_neuron_mask.values()) if self.fisher_neuron_mask else 0return {"n_tasks": self.n_tasks,"n_classic_params": len(self.fisher),4 unmodified lines"bmu_reinforcement_gamma": self.cfg.bmu_reinforcement_gamma,"last_task_grad_norm": self._last_task_grad_norm,"last_ewc_grad_norm": self._last_ewc_grad_norm,# V6.1 — info sobre skip mask"skip_som_filled_neurons": self.cfg.skip_som_filled_neurons,"n_active_ewc_neurons": n_active, # EWC atua nestes"n_masked_som_neurons": n_masked, # SOM já cobre estes (não duplica)}
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580{ "version": "V6.1", "timestamp": "2026-08-07 00:03:59", "config": { "datasets": [ "CEIA-POSITIVO/ultrachat_br_clustred_balanced_v1", "Madras1/corpus-ptbr-v2", "TucanoBR/GigaVerbo", "nvidia/OpenMathInstruct-2", "dominguesm/restore-punctuation-ptbr-dataset" ], "n_per_dataset": 10, "epochs": 2, "batch_size": 4, "max_seq_len": 16, "num_layers_hyp": 8, "use_mtp": true, "use_ewc": true, "use_kohonen_orq": true, "mtp_K": 4, "mtp_entropy_beta": 0.01, "ewc_lambda": 0.0, "ewc_lambda_topo": 0.05, "pgv_complete_thr": 0.6, "pgv_missing_thr": 0.2 }, "v6_1_improvements": { "pgvector_like_lookup": { "method": "pgvector_lookup() no OrqCell", "statuses": [ "COMPLETE", "INCOMPLETE", "MISSING" ], "complete_threshold": 0.6, "missing_threshold": 0.2, "neuron_filled_mask": true, "auto_fill_missing": true }, "ewc_math_upgrade": { "skip_som_filled_neurons": true, "rationale": "EWC n\u00e3o reutiliza pesos j\u00e1 presentes no SOM \u2014 evita dupla penaliza\u00e7\u00e3o (BMU + Fisher)", "fisher_neuron_mask": true, "n_masked_som_neurons_final": 8 }, "5_datasets_x_10_samples": true, "hypothesis_level_pgvector": true, "training_level_pgvector": true }, "v6_features_preserved": { "kohonen_4d_som": true, "ewc_per_neuron": true, "mtp_active_in_val": true, "mtp_entropy_regularizer": true, "window_context_2m": true, "dynamic_rep_penalty": true, "data_augmentation": true, "rlhf_mapping": true, "thinking_system": true, "tool_system": [ "mutation", "cache", "agent" ], "langchain_compat": true, "optimized_pipeline": true, "xeon_v6_always_active": true, "libvirt_amx_vm_activation": true }, "xeon_status": { "version": "V6", "physical_cores": 2, "env": { "MKL_ENABLE_INSTRUCTIONS": "AVX512", "MKL_NUM_THREADS": "2", "OMP_NUM_THREADS": "2", "MKL_DYNAMIC": "FALSE", "DNNL_PRIMITIVE_CACHE_CAPACITY": "1024", "ONEDNN_MAX_CPU_ISA": "AMX_INT8", "KMP_AFFINITY": "granularity=fine,compact,1,0", "KMP_BLOCKTIME": "1" }, "avx512": { "supported": true, "desc": "AVX512_VNNI (full INT8 acceleration)" }, "amx": { "supported": true, "desc": "AMX (tile + int8 + bf16) \u2014 full AMX acceleration" }, "ipex_available": false, "init_done": true }, "fp16_benchmark": { "best_time_ms": 8.137860999795521, "avg_time_ms": 9.180876000073113, "best_tflops": 1.966118615248163, "avg_tflops": 1.7427530880356714, "matrix_size": 2000.0 }, "dataset_distribution": { "CEIA-POSITIVO/ultrachat_br_clustred_balanced_v1": 6, "Madras1/corpus-ptbr-v2": 4, "TucanoBR/GigaVerbo": 6, "nvidia/OpenMathInstruct-2": 4 }, "result": { "n_steps": 20, "n_epochs": 2, "final_train_loss": 8.95526123046875, "final_val_loss": 9.007498455047607, "final_perplexity": 8164.072913971902, "final_overfitting_gap": 0.5984001159667969, "final_eval_benchmark": 0.0, "avg_tokens_per_sec": 34.57634302712832, "avg_tflops_per_cpu": 0.000667780381373023, "avg_time_per_step_ms": 1852.609849800024, "avg_grad_norm": 9.19138070344925, "avg_cpu_pct": 137.995, "final_rss_mb": 872.390625, "max_rss_mb": 880.421875, "rss_trend": "stable", "n_alerts": 0, "alerts": [], "alert_types": [], "meta_history": [], "kohonen_evolution": { "sigma_t": [ 1.384021282196045, 1.2770098447799683, 1.1782726049423218, 1.0871695280075073, 1.003110408782959, 0.9255508184432983, 0.853987991809845, 0.7879583239555359, 0.7270340323448181, 0.670820415019989, 0.6189531087875366, 0.5710961818695068, 0.5269395112991333, 0.48619696497917175, 0.44860464334487915, 0.4139189124107361, 0.38191503286361694, 0.35238566994667053, 0.32513952255249023, 0.30000001192092896 ], "alpha_t": [ 0.4456254541873932, 0.39716410636901855, 0.3539728820323944, 0.31547868251800537, 0.28117066621780396, 0.2505936026573181, 0.22334179282188416, 0.1990535855293274, 0.1774066984653473, 0.15811388194561005, 0.14091914892196655, 0.12559431791305542, 0.111936055123806, 0.09976311773061752, 0.08891396969556808, 0.07924465835094452, 0.0706268772482872, 0.06294626742601395, 0.05610092356801033, 0.05000000074505806 ], "bmu_diversity": [ 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], "map_entropy": [ -0.0, -0.0, -0.0, 0.5623351335525513, 0.5623351335525513, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0, -0.0 ], "neighborhood_spread": [ 0.69346022605896, 0.6539043188095093, 0.6115002036094666, 0.5666936039924622, 0.5201174020767212, 0.4725886881351471, 0.4250819981098175, 0.37867772579193115, 0.33448442816734314, 0.2935446500778198, 0.25673601031303406, 0.22468914091587067, 0.19773666560649872, 0.17590436339378357, 0.15894067287445068, 0.14637233316898346, 0.13756908476352692, 0.13180842995643616, 0.12834037840366364, 0.12645532190799713 ], "update_magnitude": [ 1.7733118534088135, 1.1040481328964233, 0.7362503409385681, 0.5203624963760376, 0.3804885745048523, 0.28771743178367615, 0.21806250512599945, 0.1706063151359558, 0.13349632918834686, 0.10120385140180588, 0.07817182689905167, 0.0603366494178772, 0.045329220592975616, 0.03576458618044853, 0.028652094304561615, 0.02487526461482048, 0.020203959196805954, 0.017652250826358795, 0.017456991598010063, 0.017063762992620468 ], "bmu_drift": [ 0.24679547548294067, 0.3537101149559021, 0.23110663890838623, 0.14959216117858887, 0.09846150875091553, 0.06671786308288574, 0.04513096809387207, 0.031584978103637695, 0.021926403045654297, 0.014822602272033691, 0.010076165199279785, 0.006844878196716309, 0.004448533058166504, 0.0029137134552001953, 0.0018589496612548828, 0.0012536048889160156, 0.0007802248001098633, 0.000525355339050293, 0.00039505958557128906, 0.0002874135971069336 ], "n_filled": [ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 ], "filled_ratio": [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ], "final_sigma_t": 0.30000001192092896, "final_alpha_t": 0.05000000074505806, "sigma_decay": 1.084021270275116, "alpha_decay": 0.39562545344233513, "final_n_filled": 8, "final_filled_ratio": 1.0 }, "mtp_evolution": { "train_loss": [ 6.553211212158203, 6.4814019203186035, 6.512597560882568, 6.508908748626709, 6.495436191558838, 6.468592643737793, 6.456118583679199, 6.389763355255127, 6.352229118347168, 6.327796459197998, 6.411394119262695, 6.3602471351623535, 6.394613265991211, 6.356604099273682, 6.3215155601501465, 6.312246799468994, 6.3158793449401855, 6.214627265930176, 6.1928935050964355, 6.155653953552246 ], "val_loss": [ 6.393180084228516, 6.224726915359497 ], "entropy_reg": [ 1.3862943649291992, 1.3862943649291992, 1.3862941265106201, 1.3862940073013306, 1.3862937688827515, 1.3862934112548828, 1.3862931728363037, 1.3862926959991455, 1.3862920999526978, 1.38629150390625, 1.3862910270690918, 1.3862903118133545, 1.3862894773483276, 1.3862886428833008, 1.3862876892089844, 1.386286735534668, 1.386285662651062, 1.386284589767456, 1.3862833976745605, 1.3862820863723755 ], "final_alphas": [ 0.24928787350654602, 0.24928365647792816, 0.2492905557155609, 0.2521378993988037 ] }, "ewc_evolution": { "total_penalty": [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ], "classic_pen": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], "kohonen_pen": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], "topo_pen": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], "n_masked_som_neurons": [ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 ] }, "pgvector_evolution": { "status_per_step": [ "MISSING", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE", "INCOMPLETE" ], "status_counts": { "COMPLETE": 0, "INCOMPLETE": 19, "MISSING": 1 }, "coverage_ratio": [ 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ], "best_sim": [ 0.14598573744297028, 0.40406447649002075, 0.418964684009552, 0.40291208028793335, 0.3913118839263916, 0.3694383203983307, 0.3722689151763916, 0.3724372982978821, 0.3629907965660095, 0.35789668560028076, 0.3523437976837158, 0.34320616722106934, 0.33242273330688477, 0.3401498794555664, 0.3416547179222107, 0.31360486149787903, 0.3154335618019104, 0.3324233889579773, 0.3183605372905731, 0.324212908744812 ], "n_filled": [ 0, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 ], "filled_ratio": [ 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ], "final_coverage": 1.0, "final_best_sim": 0.324212908744812, "final_n_filled": 8, "final_filled_ratio": 1.0 }, "dataset_distribution": { "CEIA-POSITIVO/ultrachat_br_clustred_balanced_v1": 6, "Madras1/corpus-ptbr-v2": 4, "TucanoBR/GigaVerbo": 6, "nvidia/OpenMathInstruct-2": 4 }, "n_params_M": 9.656608 }}1234567891011121314151617181920212223242526272829{ "version": "V6", "timestamp": "2026-08-06 23:32:19", "repo_id": "PowerMachine/BiGRU_T_version", "commit_url": "https://huggingface.co/PowerMachine/BiGRU_T_version/commit/79e8e52633961c9ff5652034b9f781ff66416ed8", "elapsed_seconds": 3.12007878899999, "n_files_uploaded": 88, "n_files_in_repo_before": 0, "n_files_in_repo_after": 0, "new_files": [], "critical_files_ok": false, "critical_files": [ "src/bigru_t/model/orq_cell.py", "src/bigru_t/training/ewc.py", "src/bigru_t/training/mtp.py", "src/bigru_t/training/dynamic_repetition_penalty.py", "src/bigru_t/training/data_augmentation.py", "src/bigru_t/training/rlhf_mapping.py", "src/bigru_t/attention/window_context.py", "src/bigru_t/reasoning/thinking.py", "src/bigru_t/tools/tool_mutation.py", "src/bigru_t/tools/tool_cache.py", "src/bigru_t/tools/tool_agent.py", "src/bigru_t/integrations/langchain_compat.py", "src/bigru_t/pipeline/optimized_pipeline.py", "src/bigru_t/utils/xeon_runtime.py", "v6_report.json" ]}