feat(D6/N6): ensemble as collapse oracle — pairwise Q-gap triggers plasticity

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-04-20 20:41:25 +02:00
parent 087c21050a
commit af9373ced9

View File

@@ -1943,6 +1943,37 @@ impl DQNTrainer {
self.last_ib_penalty = Some(ib_weight * ib_penalty_raw);
}
// D6/N6: Ensemble as collapse oracle.
// High ensemble_collapse_score ⇒ ensembles agree (often on uniform during collapse).
// When score > 0.8 AND we haven't already triggered N3 recently, force a plasticity
// injection — this shortcut catches collapse even when the moving-average of
// individual health inputs hasn't accumulated to 3 unhealthy epochs yet.
// Uses last_ens_disagreement (Path C scalar proxy — populated by A3 readback).
{
use crate::cuda_pipeline::learning_health::smoothstep;
let mean_pairwise_gap = self.last_ens_disagreement.unwrap_or(0.1);
let ensemble_collapse_score = 1.0 - smoothstep(0.01, 0.1, mean_pairwise_gap);
self.last_ensemble_collapse_score = Some(ensemble_collapse_score);
if ensemble_collapse_score > 0.8 && self.unhealthy_epoch_count < 3 {
tracing::info!(
"Ensemble collapse detected (score={:.2}): forcing plasticity injection",
ensemble_collapse_score
);
if let Some(ref mut fused) = self.fused_ctx {
let alpha = self.hyperparams.shrink_perturb_alpha as f32;
let sigma = self.hyperparams.shrink_perturb_sigma as f32;
match fused.shrink_and_perturb(alpha, sigma) {
Ok(()) => {
self.unhealthy_epoch_count = 0;
self.last_plasticity_ready = Some(false);
}
Err(e) => tracing::warn!("D6/N6 shrink_and_perturb failed: {e}"),
}
}
}
}
// HEALTH_DIAG: components are [0, 1] normalized. effective = hyperparams after health-adaptation. novels = mechanism states.
tracing::info!(
"HEALTH_DIAG[{}]: health={:.2} components [q_gap={:.2} q_var={:.2} atoms={:.2} grad_stable={:.2} ens_agree={:.2} grad_cos={:.2} spectral={:.2}] effective [cql_alpha={:.4} iqn_budget={:.2} cql_budget={:.2} c51_budget={:.2} tau={:.5} sarsa_tau={:.2} gamma={:.3} cf_ratio={:.2}] novels [distill={} barrier={:.3} plasticity={} ib={:.3} ensemble_collapse={:.2} contrarian={} meta_q_pred={:.2}]",