TorchLean API

NN.Runtime.Autograd.Torch.Core.Session.Lifecycle

Eager Session Lifecycle #

Create and reset sessions, and release the intermediates their CUDA tapes own. Parameter snapshots use Lean reference counting so a reset or update in one session cannot invalidate another session.

Resolve a CPU-only scalar before creating either kind of recorded session. Native carriers retain the requested device, so runtime failures are not converted to fallbacks. Explicit backend profiles are still validated against the effective device.

Instances For

    Allocate an eager session. A scalar carrier without native tensor support retains its arithmetic on CPU with a diagnostic. Native carriers still report GPU execution failures.

    Instances For

      Release a CUDA allocation; repeated release and later finalization are safe.

      Instances For

        Force-release a shape-erased CUDA buffer.

        Instances For
          @[reducible, inline]

          Device-resident gradients keyed by parameter leaf ids, with each leaf's shape.

          Instances For

            Release a sparse CUDA gradient map after an optimizer has consumed it.

            Instances For

              Run an action that borrows a sparse CUDA gradient map, then release every buffer in the map.

              The action must not retain a gradient buffer after it returns. Cleanup also runs when the action throws, which keeps optimizer failures from leaking device memory.

              Instances For

                Check that a shape-erased CUDA buffer has the number of elements promised by its shape.

                Instances For

                  Discard the current forward pass and invalidate its handles. Keep parameters and RNG state.

                  Owned CUDA intermediates are released before the tape drops its references. Parameter leaves can refer to the current mirror or an older recorded value, so their snapshots follow Lean reference counting and remain valid in any other session that still uses them. Resetting the tape neither empties LibTorch's allocator cache nor changes optimizer history.

                  Instances For