CompiledTapeTrainingStep<T>

Helpers & Utilities · AiDotNet.Training

Compiled training step — auto-compiles the forward + backward pass on the first step, then replays the compiled plan on subsequent steps for near-zero overhead training.

How it works:

  • Step 1 (tracing): Enables GraphMode, traces the forward pass + loss computation

through the layer stack, compiles a CompiledTrainingPlan with backward pass, and executes it.

  • Steps 2+ (replay): Calls plan.Step() which replays the compiled forward + backward

as flat delegate arrays with pre-allocated gradient buffers. Zero allocation, zero dispatch overhead.

Recompilation triggers:

  • Input shape changes (different batch size, sequence length, etc.)
  • Explicit Invalidate() call (model structure changed)
  • Compilation failure (falls back to eager TapeTrainingStep for that shape)

Methods

Method Summary
Exception GetLastFallbackException() AiDotNet#1395: read the last exception that caused TryStepWithFusedOptimizer to fall back, or null if the most recent fallback was due to one of the explicit return-false paths (plan switch, config drift, EnableCompilation=false, etc.)…
T Step(IReadOnlyList<ITrainableLayer<T>> layers, Tensor<T> input, Tensor<T> target, T learningRate, Func<Tensor<T>, Tensor<T>> forward, Func<Tensor<T>, Tensor<T>, Tensor<T>> computeLoss, object owner) Executes a single compiled training step.
long GetFusedStepCount() Gets the count of successful fused-step executions on the calling thread.
void Invalidate()
void ResetFusedStepCount() Resets the fused-step counter on the calling thread to zero.