Skip to main content

Custom Training Loop

Status:Preliminary
Tags:ImplementationTrainingGlobal Throttle
Last modified:

What this page covers

This page summarizes the custom online-training loop used by the ablation harness. The public entry point is BaseModel.train_instrumented(...); the implementation is orchestrated by enabol.nn.training.InstrumentedTrainer, with controller logic in enabol.nn.controller.

The first target is Experiment 1A: a one-layer, no-bias, floating-point linear regression test with scale drift.

Design Goals​

  • Use Keras models for the trainable layers.
  • Avoid model.fit.
  • Own the update step explicitly.
  • Flatten trainable parameters into one global vector theta.
  • Flatten gradients into one global vector G.
  • Compute the dynamic global throttle alpha(t).
  • Apply the full update vector with one shared scalar throttle.
  • Log every diagnostic needed to explain closed-loop stability.

Minimal Loop Shape​

Algorithm: MinimalInstrumentedTrainingLoop
  1. for each online step tt do
  2. xb,yb←sample_batch⁡()x_b, y_b \leftarrow \operatorname{sample\_batch}()
  3. with GradientTape do
  4. y^b←f(xb;θt)\hat{y}_b \leftarrow f(x_b; \theta_t)
  5. Lt←loss⁡(yb,y^b)L_t \leftarrow \operatorname{loss}(y_b, \hat{y}_b)
  6. end with
  7. Gt←∇θLtG_t \leftarrow \nabla_{\theta} L_t
  8. θt←flatten⁡(trainable variables)\theta_t \leftarrow \operatorname{flatten}(\text{trainable variables})
  9. Δraw←−ηGt\Delta_{\mathrm{raw}} \leftarrow -\eta G_t
  10. αt←controller⁡(θt,Gt,θt−1,Gt−1)\alpha_t \leftarrow \operatorname{controller}(\theta_t, G_t, \theta_{t-1}, G_{t-1})
  11. Δactual←αtΔraw\Delta_{\mathrm{actual}} \leftarrow \alpha_t \Delta_{\mathrm{raw}}
  12. θt+1←θt+Δactual\theta_{t+1} \leftarrow \theta_t + \Delta_{\mathrm{actual}}
  13. log_step⁡(Lt,θt,Gt,αt,…)\operatorname{log\_step}(L_t, \theta_t, G_t, \alpha_t, \ldots)
  14. end for
This is the conceptual loop; BaseModel.train_instrumented(...) adds quantization hooks and diagnostics.

First Model​

y=Axy = Ax y^=Wx\hat{y} = Wx

No bias is included in the first test. Bias is added only after the pure scale-drift Hessian story is validated.

First Controller​

C(t)=∥G(t)−G(t−1)∥∥θ(t)−θ(t−1)∥+εC(t) = \frac{ \lVert G(t) - G(t-1) \rVert }{ \lVert \theta(t) - \theta(t-1) \rVert + \varepsilon } S(t)=EMA⁡(C(t))S(t) = \operatorname{EMA}(C(t)) α(t)=clamp⁡(11+βS(t),αmin⁡,1)\alpha(t) = \operatorname{clamp} \left( \frac{1}{1 + \beta S(t)}, \alpha_{\min}, 1 \right)

Diagnostics​

The first implementation should log:

  • loss,
  • output error,
  • ||theta||,
  • ||G||,
  • raw update norm,
  • actual update norm,
  • curvature proxy C(t),
  • EMA signal S(t),
  • alpha(t),
  • effective learning rate alpha(t) * eta,
  • true Hessian metrics where feasible,
  • stability margin eta * lambda_max(H),
  • throttled stability margin alpha(t) * eta * lambda_max(H),
  • update cosine.

Notes​

Keep this page updated with code snippets once the harness stabilizes.