Following the V7-gem methodology you flagged: instead of blindly wiring
backward gradients for two possibly-redundant features (G10 redundant
with spectral_norm, G6 redundant with NoisyNets/ensemble-KL), this commit
makes both forward-only and exposes their values via HEALTH_DIAG so we
can MEASURE whether they're producing meaningful signal before committing
to the full backward integration.
Three coordinated changes:
1) G10 temporal_consistency_penalty rewritten graph-safe
(experience_kernels.cu)
Was: multi-block kernel with cross-block atomicAdd into a single scalar,
and a Rust wrapper that called cuMemsetD32Async to zero it before each
launch. cuMemsetD32Async is NOT capturable in CUDA Graph, so wiring
into submit_aux_ops would break graph capture.
Now: per-sample loss buffer [B], one thread per sample, no atomic, no
memset. Caller reduces with the existing c51_loss_reduce_kernel
(single-thread sequential sum) for the scalar. Same pattern as G12
predictive_coding_loss + reduce. Fully graph-safe, fully deterministic.
2) Rust wrappers updated (gpu_dqn_trainer.rs)
- compute_branch_independence: drop the cuMemsetD32Async (G6 was
already graph-safe — single-block kernel writes scalar via
overwrite, not accumulation; the memset was unnecessary)
- compute_temporal_consistency: switch to two-step (per-sample +
reduce) to match the new kernel signature; drop cuMemsetD32Async
- New temporal_per_sample_buf field [B] alongside the existing
temporal_penalty_buf scalar
- Three new readback methods (sync DtoH, epoch-boundary only):
branch_indep_loss_value() — G6
temporal_loss_value() — G10
predictive_loss_value() — G12 (was unread previously)
3) Wired into the training loop
- submit_aux_ops calls compute_branch_independence + compute_temporal_consistency
right after compute_predictive_coding_loss (G12). Forward-only — no
backward gradient flows yet.
- FusedTrainingCtx::read_gem_losses() — pass-through accessor that
calls all three trainer-level readbacks at once.
- HEALTH_DIAG line gained a `gems [g6_branch_indep=X g10_temporal=Y
g12_predictive=Z]` suffix so each epoch's penalty magnitudes are
visible. Sync DtoH happens once per epoch (batch boundary), so the
overhead is negligible (~3 × ~1µs).
What this gives us:
- Empirical evidence of whether G6/G10 gem signals are nonzero
- A clean baseline for deciding whether to wire backward (V7
methodology: measure, then commit)
- G12 predictive loss is now also visible (was wired backward in
earlier commit but the loss scalar itself was never logged)
Smoke test:
- 6 trials passed
- Best Sharpe variance: [15.72, 31.94] (wider than G12-only [17.99,
19.56]) — likely cuBLAS algorithm reselection from the new kernel
launches changing graph timing; not a correctness issue
- Tests pass; HEALTH_DIAG now logs gem values per epoch
Next session can run a 5-trial multi-trial test, look at the HEALTH_DIAG
gems line, and decide:
- If g10_temporal ≈ 0 → G10 redundant with spectral_norm; delete
- If g10_temporal nonzero → wire backward
- Same logic for g6_branch_indep
Files touched:
crates/ml/src/cuda_pipeline/experience_kernels.cu (-30 / +48)
crates/ml/src/cuda_pipeline/gpu_dqn_trainer.rs (+87 / -31)
crates/ml/src/trainers/dqn/fused_training.rs (+25)
crates/ml/src/trainers/dqn/trainer/training_loop.rs (+10 / +3)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>