V6.5-V2-dynamic: upload batch (scripts + state + model) [13 files]
Browse filesFiles changed (8)
580 unmodified lines581582583584585586587588589590591592593594595596393 unmodified lines990991992993994995996997998999983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410256 unmodified lines103210331034101210351036103710381039104010411042104310441015101610171018101910201021102210231024102510451046104710481049105010511052105310541055105610571058321 unmodified lines1380138113821353138313841385138613871388138913571390139113921393136013611362139413951396139713981399140013671401140214031404140514061370140714081409141013731374137513761411141214131414141514161417244 unmodified lines16621663166416651666162716281629163016311632163316341635163616371638166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690580 unmodified lines
self.buffer_4d = [] self.buffer_labels = [] # V6.5-V2-memfix — Sliding window limit for buffer_4d to prevent OOM. # User requirement: "resolver falhas de lógica e de bugs que estejam # causando alto consumo de memória sem distorcer a arquitetura Kohonen". # The buffer stores vec_4d tensors for SOM training and neuron labeling. # Without a limit, streaming 8000+ samples accumulates 8000 tensors, # each retaining the embedding computation graph (16M params), causing # OOM (3.5GB RSS observed). Sliding window of 512 keeps recent samples # for SOM updates while bounding memory. The Kohonen architecture (SOM # grid, BMU, Gaussian neighborhood, EWC) is NOT changed. self.buffer_max_size = 512 self.training_ready = False self.N = N_start self.dim_choice = dim_choice393 unmodified lines if dataset_name is not None: self.last_dataset_used = dataset_name
# V6.5-V2-memfix — Use torch.no_grad() to avoid building computation # graphs during vec_4d computation. The embedding graph (16M params) # would otherwise be retained by every tensor in buffer_4d, causing OOM # with 8000+ samples. The vec_4d is a 4-float summary (x,y,z,w) that # does NOT need gradient — it feeds into SOM (Hebbian, no backprop) and # the HypothesisClassifier (which trains its own weights). with torch.no_grad(): for sent, lab in zip(sentences, labels): self.time_counter += 1 vec = text_to_4d_vector( sent, self.tokenizer, self.embedding, self.hidden_dim, self.seq_len, self.time_counter, self.T_max, attention=self.attention, # V6.5-attn attention_metrics=self.attention_metrics, # V6.5-attn ) self.buffer_4d.append(vec) self.buffer_labels.append(lab) dim_val = round(vec[self.dim_index].item(), 2) self.histogram[dim_val] += 1 for sent, lab in zip(sentences, labels): self.time_counter += 1 vec = text_to_4d_vector( sent, self.tokenizer, self.embedding, self.hidden_dim, self.seq_len, self.time_counter, self.T_max, attention=self.attention, # V6.5-attn attention_metrics=self.attention_metrics, # V6.5-attn ) # CRITICAL: detach to break any residual graph + clone for safety self.buffer_4d.append(vec.detach().clone()) self.buffer_labels.append(lab) dim_val = round(vec[self.dim_index].item(), 2) self.histogram[dim_val] += 1 # V6.5-V2-memfix — Enforce sliding window limit if len(self.buffer_4d) > self.buffer_max_size: overflow = len(self.buffer_4d) - self.buffer_max_size self.buffer_4d = self.buffer_4d[-self.buffer_max_size:] self.buffer_labels = self.buffer_labels[-self.buffer_max_size:]
def check_training_start(self) -> bool: """Inicia treino quando algum bucket do histograma atinge N."""6 unmodified lines return False
def train_som_on_buffer(self): """Treina SOM por 5 épocas sobre o buffer atual (com Fisher accum).""" """Treina SOM por 5 épocas sobre o buffer atual (com Fisher accum).
V6.5-V2-memfix — Wrapped in torch.no_grad() to prevent graph building during SOM Hebbian updates. The SOM uses competitive learning (BMU + Gaussian neighborhood), not backprop — no gradient is needed. """ if not self.buffer_4d: return # V6.5-V2-memfix — detach+stack to ensure no graph leaks from buffer data = torch.stack(self.buffer_4d).detach() data = torch.stack(self.buffer_4d) for _ in range(5): # épocas de treino rápido perm = torch.randperm(len(data)) for idx in perm: x = data[idx] bmu = self.som.find_bmu(x) acc_fisher = ( self.punishment_count == 0 and self.som.old_weights_w is None ) self.som.update_weights(x, bmu, accumulate_fisher=acc_fisher) with torch.no_grad(): for _ in range(5): # épocas de treino rápido perm = torch.randperm(len(data)) for idx in perm: x = data[idx] bmu = self.som.find_bmu(x) acc_fisher = ( self.punishment_count == 0 and self.som.old_weights_w is None ) self.som.update_weights(x, bmu, accumulate_fisher=acc_fisher)
# V6.5 — Ativa VQ-VAE-2 compressor no pipeline if self.enable_vqvae2 and self.vqvae2_compressor is not None:321 unmodified lines return dist.flatten()
def _label_neurons(self): """Rotula neurônios por votação majoritária sobre o buffer.""" """Rotula neurônios por votação majoritária sobre o buffer.
V6.5-V2-memfix — no_grad to prevent graph building during BMU search. """ self.neuron_label = {} if not self.buffer_4d: return data = torch.stack(self.buffer_4d) data = torch.stack(self.buffer_4d).detach() labels = torch.tensor(self.buffer_labels) votes = defaultdict(lambda: [0, 0]) with torch.no_grad(): for i in range(len(data)): bmu = self.som.find_bmu(data[i]) votes[bmu][int(labels[i].item())] += 1 for i in range(len(data)): bmu = self.som.find_bmu(data[i]) votes[bmu][int(labels[i].item())] += 1 for bmu, v in votes.items(): self.neuron_label[bmu] = 1.0 if v[1] > v[0] else 0.0
def evaluate_classification(self) -> float: """Acurácia sobre o buffer atual.""" """Acurácia sobre o buffer atual.
V6.5-V2-memfix — no_grad to prevent graph building during evaluation. """ if not self.buffer_4d: return 1.0 data = torch.stack(self.buffer_4d) data = torch.stack(self.buffer_4d).detach() labels = torch.tensor(self.buffer_labels).float() correct = 0 with torch.no_grad(): for i in range(len(data)): pred = self._predict_single(data[i]) if (pred > 0.5) == (labels[i] > 0.5): correct += 1 for i in range(len(data)): pred = self._predict_single(data[i]) if (pred > 0.5) == (labels[i] > 0.5): correct += 1 return correct / len(data)
def _predict_single(self, x):244 unmodified lines self.last_dataset_used = dataset_name
# 2. Compute vec_4d for the misclassified sentence # V6.5-V2-memfix — no_grad + detach to prevent graph accumulation with torch.no_grad(): self.time_counter += 1 vec = text_to_4d_vector( sentence, self.tokenizer, self.embedding, self.hidden_dim, self.seq_len, self.time_counter, self.T_max, attention=self.attention, attention_metrics=self.attention_metrics, ) self.time_counter += 1 vec = text_to_4d_vector( sentence, self.tokenizer, self.embedding, self.hidden_dim, self.seq_len, self.time_counter, self.T_max, attention=self.attention, attention_metrics=self.attention_metrics, ) vec = vec.detach().clone()
# 3. Add to buffer + update histogram (mirror add_data) self.buffer_4d.append(vec) self.buffer_labels.append(int(correct_label_int)) # Enforce sliding window limit (mirror add_data) if len(self.buffer_4d) > self.buffer_max_size: self.buffer_4d = self.buffer_4d[-self.buffer_max_size:] self.buffer_labels = self.buffer_labels[-self.buffer_max_size:] dim_val = round(vec[self.dim_index].item(), 2) self.histogram[dim_val] += 1
2 unmodified lines3456678989101111121314151617171819202 unmodified lines "user_requirement": "verificar se o mecanismo de atenção está ativo e acessado logicamente funcional", "metrics": { "active": true, "n_calls": 3441, "n_calls": 10680, "n_errors": 0, "last_norm_in": 54.769012451171875, "last_norm_out": 56.71458053588867, "last_norm_in": 111.9294204711914, "last_norm_out": 116.00782012939453, "last_attn_activated": true, "last_attn_diff_norm": 56.80364227294922, "last_attn_diff_norm": 116.50959014892578, "n_heads": 8, "logic_functional": true }, "active": true, "logic_functional": true, "n_calls": 3441, "n_calls": 10680, "n_errors": 0, "n_heads": 8, "assessment": "PASS"123version https://git-lfs.github.com/spec/v1oid sha256:ff42c43886461f7b5cfd55a0d125ce6dbf4f719a0d41383d3991fe687e60958esize 220174132123version https://git-lfs.github.com/spec/v1oid sha256:5e59c64fa9ed050f79bddf2f3546b104a93b846e7af732bd4527c9ed10c578dasize 2176942334 unmodified lines56789891011121 unmodified line141516171817181920211 unmodified line232425262726272829301 unmodified line323334353635363738391 unmodified line414243444544454647481 unmodified line5051525354535455565745 unmodified lines1031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341354 unmodified lines "results": [ { "query": "o gato dorme na cama", "prediction": "unpunctuated", "probability": 0.0, "prediction": "short_text", "probability": NaN, "is_gato_hardcoded": false, "is_cachorro_hardcoded": false, "is_registry_label": true,1 unmodified line }, { "query": "calcule dois mais dois", "prediction": "unpunctuated", "probability": 0.0, "prediction": "short_text", "probability": NaN, "is_gato_hardcoded": false, "is_cachorro_hardcoded": false, "is_registry_label": true,1 unmodified line }, { "query": "qual é a capital do brasil", "prediction": "unpunctuated", "probability": 0.0, "prediction": "short_text", "probability": NaN, "is_gato_hardcoded": false, "is_cachorro_hardcoded": false, "is_registry_label": true,1 unmodified line }, { "query": "explique o que é uma rede neural", "prediction": "unpunctuated", "probability": 0.0, "prediction": "short_text", "probability": NaN, "is_gato_hardcoded": false, "is_cachorro_hardcoded": false, "is_registry_label": true,1 unmodified line }, { "query": "olá como você está", "prediction": "unpunctuated", "probability": 0.0, "prediction": "short_text", "probability": NaN, "is_gato_hardcoded": false, "is_cachorro_hardcoded": false, "is_registry_label": true,1 unmodified line }, { "query": "traduza hello para portugues", "prediction": "unpunctuated", "probability": 0.0, "prediction": "short_text", "probability": NaN, "is_gato_hardcoded": false, "is_cachorro_hardcoded": false, "is_registry_label": true,45 unmodified lines ], "prediction": "unpunctuated", "valid_for_dataset": true }, { "dataset": "iara-project/news-articles-ptbr-dataset", "expected_labels": [ "headline", "body" ], "prediction": "headline", "valid_for_dataset": true }, { "dataset": "manoela/noticias_ptbr", "expected_labels": [ "headline", "body" ], "prediction": "headline", "valid_for_dataset": true }, { "dataset": "BrunoN-Dev/corpus-ptbr-v1", "expected_labels": [ "short_text", "long_text" ], "prediction": "short_text", "valid_for_dataset": true } ], "summary": {12334562 unmodified lines91011121314121314151616171819181920212231 unmodified lines545556575859605758596061626320 unmodified lines8485868788899087888990919293949596979899939495969798991001011021031041041051061079 unmodified lines117118119120121120121122123124125126127127128129130129130131132133134135136137138139140136137138139140141142143142143144145146147148146147148149150151151152153154155156153154155156157158158159160159160161162163163164165166166167167168169169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294{ "version": "V6.5-V2", "timestamp": "2026-08-08T21:26:39.965059", "timestamp": "2026-08-08T23:52:08.862775", "config": { "som_grid": [ 6,2 unmodified lines 4 ], "n_neurons": 864, "hidden_dim": 256, "vocab_size": 4096, "n_hypotheses": 8, "hidden_dim": 1024, "vocab_size": 16384, "n_hypotheses": 16, "n_trials": 3, "hyp_train_steps": 20, "hyp_train_steps": 30, "stream_batch_size": 100, "meta_conhecimento": 6000, "meta_punicão": 1000, "meta_conhecimento": 8000, "meta_punicão": 2000, "conhecimento_datasets": [ "dominguesm/restore-punctuation-ptbr-dataset", "carolina-c4ai/corpus-carolina",31 unmodified lines "init_done": true }, "fp16_benchmark": { "best_time_ms": 94.09655899980862, "avg_time_ms": 97.57540749978943, "best_tflops": 1.3603047907443706, "avg_tflops": 1.3118059486482412, "best_time_ms": 91.0796530006337, "avg_time_ms": 91.46852800040506, "best_tflops": 1.4053632812930177, "avg_tflops": 1.3993884322641899, "matrix_size": 4000.0 }, "v2_verification": {20 unmodified lines "all_pass": true }, "fase_1_conhecimento_summary": { "total_samples": 3300, "meta_atingida": false, "elapsed_s": 425.32095551490784, "storage_critical_stopped": true "total_samples": 8000, "meta_atingida": true, "elapsed_s": 722.1084952354431, "storage_critical_stopped": false }, "fase_2_punicão_summary": { "total_samples": 0, "meta_atingida": false, "elapsed_s": 0.0, "punishment_events": 0, "hypotheses_trainings": 0, "delta_applications": 0, "skipped": true "total_samples": 2000, "meta_atingida": true, "elapsed_s": 507.18996810913086, "punishment_events": 120, "hypotheses_trainings": 60, "delta_applications": 60, "skipped": false }, "attention_eval_summary": { "active": true, "logic_functional": true, "n_calls": 3441, "n_calls": 10680, "assessment": "PASS" }, "predict_fix_summary": {9 unmodified lines "n_with_think": 3, "answer_rate": 1.0, "think_rate": 1.0, "avg_latency_ms": 3.060022989908854, "avg_reasoning_length": 1030.0 "avg_latency_ms": 11.263132095336914, "avg_reasoning_length": 1026.0 }, "model_states_saved_to": "/home/z/my-project/BiGRU_T_version/v6_5_v2_model_states.pt", "save_info": { "saved": true, "path": "/home/z/my-project/BiGRU_T_version/v6_5_v2_model_states.pt", "size_mb": 40.959502, "size_mb": 220.174132, "reason": "end_of_training_v2", "step": 225, "total_samples": 3300, "step": 700, "total_samples": 10000, "n_tensors": 7, "n_buffer_tail": 128 }, "final_v2_metrics": { "version": "V2-dynamic", "n_hypotheses": 8, "n_hypotheses_active": 8, "max_n_hypotheses": 16, "n_trials": 3, "hyp_train_steps": 20, "n_hypotheses": 16, "n_hypotheses_active": 16, "max_n_hypotheses": 32, "n_trials": 6, "hyp_train_steps": 30, "hyp_lr": 0.0001, "delta_scale": 0.009999999776482582, "n_generators": 16, "delta_scale": 0.0010000000474974513, "n_generators": 32, "punishment_count": 0, "success_count": 0, "training_ready": true, "classifier_trained": false, "ewc_reference_set": false, "training_ready": false, "classifier_trained": true, "ewc_reference_set": true, "buffer_size": 256, "dynamic_adaptation": { "loss_history_len": 0, "loss_history_len": 8, "loss_stats": { "slope": 0.0, "volatility": 0.0, "mean": 0.0, "n": 0 "slope": NaN, "volatility": NaN, "mean": NaN, "std": NaN, "n": 8 }, "punishment_rate": 0.0, "punishment_window_size": 0, "n_adaptations": 0, "punishment_rate": 1.0, "punishment_window_size": 12, "n_adaptations": 20, "limits": { "min_n_hypotheses": 4, "max_n_hypotheses": 16, "max_n_hypotheses": 32, "min_n_trials": 1, "max_n_trials": 6, "min_hyp_train_steps": 5, "max_hyp_train_steps": 60 "min_hyp_train_steps": 10, "max_hyp_train_steps": 80 }, "last_5_adaptations": [] "last_5_adaptations": [ { "trigger": "punishment", "step": 115, "before": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "after": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "adapted": false, "rules_fired": [], "loss_stats": { "slope": NaN, "volatility": NaN, "mean": NaN, "std": NaN, "n": 8 }, "punishment_rate": 1.0 }, { "trigger": "auto", "step": 116, "before": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "after": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "adapted": false, "rules_fired": [], "loss_stats": { "slope": NaN, "volatility": NaN, "mean": NaN, "std": NaN, "n": 8 }, "punishment_rate": 1.0 }, { "trigger": "punishment", "step": 117, "before": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "after": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "adapted": false, "rules_fired": [], "loss_stats": { "slope": NaN, "volatility": NaN, "mean": NaN, "std": NaN, "n": 8 }, "punishment_rate": 1.0 }, { "trigger": "auto", "step": 118, "before": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "after": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "adapted": false, "rules_fired": [], "loss_stats": { "slope": NaN, "volatility": NaN, "mean": NaN, "std": NaN, "n": 8 }, "punishment_rate": 1.0 }, { "trigger": "punishment", "step": 119, "before": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "after": { "n_hypotheses": 16, "n_trials": 6, "hyp_train_steps": 30 }, "adapted": false, "rules_fired": [], "loss_stats": { "slope": NaN, "volatility": NaN, "mean": NaN, "std": NaN, "n": 8 }, "punishment_rate": 1.0 } ] } }}17 unmodified lines1819202122212223242526272828293031313233341 unmodified line3637383940394041424344454646474849495051521 unmodified line5455565758575859606162636464656667676869701 unmodified line7273747576757677787917 unmodified lines "context_provided": false, "system_prompt_used": false, "few_shot_examples": false, "som_prediction": "unpunctuated", "reasoning_length": 1028, "som_prediction": "short_text", "reasoning_length": 1024, "has_think": true, "has_plan": true, "has_answer": true, "has_decompose": true, "think_preview": "Analisando a query: 'Luva de Pedreiro Távila'\nIdentificando o tipo de problema e requisitos.\nDeterminando se ferramentas são necessárias.", "answer_preview": "prediction=unpunctuated | BMU=(4, 4, 5, 0)", "answer_preview": "prediction=short_text | BMU=(0, 0, 0, 0)", "raw_response_preview": "<think>\nAnalisando a query: 'Luva de Pedreiro Távila'\nIdentificando o tipo de problema e requisitos.\nDeterminando se ferramentas são necessárias.\n</think>\n<plan>\nPlano de resolução:\n1. Decompor o problema em sub-tarefas\n2. Identificar ferramentas necessárias (disponíveis: som_query, buffer_stats)\n3. Executar sub-tarefas em sequência\n4. Monitorar resultados\n5. Compor resposta final\n</plan>\n<decompose>\n- Processar: Luva de Pedreiro Távila\n</decompose>\n<execute>\nSub-tarefa 'Processar: Luva de Pedre...", "n_tags": 4, "latency_ms": 3.1023025512695312 "latency_ms": 9.467601776123047 }, { "query": "Lula reserva valor",1 unmodified line "context_provided": false, "system_prompt_used": false, "few_shot_examples": false, "som_prediction": "unpunctuated", "reasoning_length": 998, "som_prediction": "short_text", "reasoning_length": 994, "has_think": true, "has_plan": true, "has_answer": true, "has_decompose": true, "think_preview": "Analisando a query: 'Lula reserva valor'\nIdentificando o tipo de problema e requisitos.\nDeterminando se ferramentas são necessárias.", "answer_preview": "prediction=unpunctuated | BMU=(4, 4, 5, 0)", "answer_preview": "prediction=short_text | BMU=(0, 0, 0, 0)", "raw_response_preview": "<think>\nAnalisando a query: 'Lula reserva valor'\nIdentificando o tipo de problema e requisitos.\nDeterminando se ferramentas são necessárias.\n</think>\n<plan>\nPlano de resolução:\n1. Decompor o problema em sub-tarefas\n2. Identificar ferramentas necessárias (disponíveis: som_query, buffer_stats)\n3. Executar sub-tarefas em sequência\n4. Monitorar resultados\n5. Compor resposta final\n</plan>\n<decompose>\n- Processar: Lula reserva valor\n</decompose>\n<execute>\nSub-tarefa 'Processar: Lula reserva valor' exe...", "n_tags": 4, "latency_ms": 3.0732154846191406 "latency_ms": 11.906862258911133 }, { "query": "Amazonas força-tarefa vítimas",1 unmodified line "context_provided": false, "system_prompt_used": false, "few_shot_examples": false, "som_prediction": "unpunctuated", "reasoning_length": 1064, "som_prediction": "short_text", "reasoning_length": 1060, "has_think": true, "has_plan": true, "has_answer": true, "has_decompose": true, "think_preview": "Analisando a query: 'Amazonas força-tarefa vítimas'\nIdentificando o tipo de problema e requisitos.\nDeterminando se ferramentas são necessárias.", "answer_preview": "prediction=unpunctuated | BMU=(4, 4, 5, 0)", "answer_preview": "prediction=short_text | BMU=(0, 0, 0, 0)", "raw_response_preview": "<think>\nAnalisando a query: 'Amazonas força-tarefa vítimas'\nIdentificando o tipo de problema e requisitos.\nDeterminando se ferramentas são necessárias.\n</think>\n<plan>\nPlano de resolução:\n1. Decompor o problema em sub-tarefas\n2. Identificar ferramentas necessárias (disponíveis: som_query, buffer_stats)\n3. Executar sub-tarefas em sequência\n4. Monitorar resultados\n5. Compor resposta final\n</plan>\n<decompose>\n- Processar: Amazonas força-tarefa vítimas\n</decompose>\n<execute>\nSub-tarefa 'Processar: A...", "n_tags": 4, "latency_ms": 3.0045509338378906 "latency_ms": 12.414932250976562 } ], "summary": {1 unmodified line "n_with_think": 3, "answer_rate": 1.0, "think_rate": 1.0, "avg_latency_ms": 3.060022989908854, "avg_reasoning_length": 1030.0 "avg_latency_ms": 11.263132095336914, "avg_reasoning_length": 1026.0 }, "quality_assessment": { "model_not_helped": true,kohonen_learning_system.py+97-52
v6_5_v2_attention_eval.json+5-5
v6_5_v2_model_states.ptAdded+3
v6_5_v2_model_states_after_conhecimento.ptAdded+3
v6_5_v2_phases_eval.json
v6_5_v2_predict_fix_eval.json+39-12
v6_5_v2_report.json+172-50
v6_5_v2_user_questions.json+14-14