feat(sp18-v2): ISV-adaptive shrink-and-perturb at fold transition

Replaces the hardcoded `α=0.8 / σ=0.01` constants in `reset_for_fold`'s
`shrink_and_perturb` call with ISV-driven adaptive bounds per
`feedback_isv_for_adaptive_bounds` and `feedback_adaptive_not_tuned`.

The driving signal is the relative weight drift `||current - best||₂ /
||best||₂` already computed each epoch by the SP18 v2 weight-drift
diagnostic kernel (commit aab13a83f). Extended that kernel atomically
to also write α / σ into ISV[505] / ISV[506] from the same two block-
tree-reductions — single producer, single launch, single source of
truth. No new kernel; reuses `||best||₂` + `relative_drift` already
computed.

Added 2 ISV slots [505..507):

  [505] SHRINK_ALPHA_ADAPTIVE — drift-driven preservation factor.
        α = 1 - clamp(rel_drift, 1-MAX, 1-MIN). Small drift → α near
        MAX (preserve hard); large drift → α near MIN (shrink hard).

  [506] SHRINK_SIGMA_ADAPTIVE — scale-aware noise. σ tracks
        ||best||_RMS / RMS_REFERENCE so noise stays scale-relative as
        weight magnitudes evolve across folds.

Pearl-A first-observation bootstrap: sentinels 0.8 / 0.01 match prior
hardcoded values exactly. Cold-start path (first fold, no
`best_params_snapshot`) leaves slots at sentinels — bit-identical to
pre-fix behavior.

Bounds [SHRINK_ALPHA_MIN=0.5, SHRINK_ALPHA_MAX=0.95] +
[SHRINK_SIGMA_MIN=1e-4, SHRINK_SIGMA_MAX=0.1] are Category-1
dimensional safety floors per `feedback_isv_for_adaptive_bounds`.
Bilateral clamp per `pearl_symmetric_clamp_audit`.

Atomic in same commit per `feedback_no_partial_refactor` and
`feedback_wire_everything_up`:

  * 2 ISV slot constants + sentinels + bounds + lock test in
    `sp14_isv_slots.rs`.
  * `ISV_TOTAL_DIM` 505 → 507 + layout fingerprint seed bump in
    `gpu_dqn_trainer.rs`.
  * `state_layout.cuh` mirror for kernel-side reads.
  * `weight_drift_diag_kernel.cu` extended: 4-element output buffer
    `[l2_diff, rel, α_target, σ_target]` + ISV writes via
    `__threadfence_system()`.
  * `launch_weight_drift_diag` + `read_shrink_perturb_adaptive`
    plumbing; mapped-pinned 4-float buffer.
  * `reset_for_fold` reads ISV[505]/ISV[506] via `read_isv_signal_at`
    + defensive host-side clamp; replaces former hardcoded constants.
  * 2 fold-reset registry entries with dispatch arms (sentinel 0.8 /
    0.01 — Pearl-A bootstrap matches prior hardcoded for bit-
    identical cold-start).
  * Per-epoch HEALTH_DIAG `weight_drift` line extended with
    `alpha_adaptive` / `sigma_adaptive` for observability.
  * 8 behavioral tests (CPU-only oracle pinning the math contract).
  * `docs/dqn-wire-up-audit.md` — Invariant 7 audit entry.

`shrink_and_perturb` signature unchanged — kept as 2-arg
`(alpha, sigma)` so the 4 existing call sites compile without ripple
(3 in `training_loop.rs`, 1 in `fused_training.rs`). Only the
fold-transition site at `fused_training.rs::reset_for_fold` is
migrated to ISV reads in this commit; the 3 health-driven /
backtracking sites in `training_loop.rs` continue to use
`hyperparams.shrink_perturb_alpha/sigma` (different driving signal —
those are unhealthy-streak rescue interventions, not fold-transition
plasticity refresh; surfaced as a follow-up concern in
DONE_WITH_CONCERNS report).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
jgrusewski
2026-05-09 02:09:25 +02:00
parent aab13a83f2
commit 0b737ec30a
9 changed files with 776 additions and 71 deletions

File diff suppressed because one or more lines are too long