Skip to content
fn

compiled_decode_step

→callable
compiled_decode_step(forward_fn: Callable[[Tensor, Tensor], Tensor], static_cache: StaticCache | EncoderDecoderCache)

Return a step(input_ids, cache_position) running one compiled decode.

Parameters

forward_fncallable
forward_fn(input_ids, cache_position) -> output — one decode forward that reads/writes static_cache internally (e.g. a model's single-token path). Must return a single Tensor (the decode logits / hidden state).
The cache whose per-layer self-attention buffers forward_fn writes via lucid.index_copy. Its buffers are rolled forward in place.

Returns

callable

step(input_ids, cache_position) -> Tensor. input_ids is the new token(s); cache_position is a fixed-shape (T,) int64 Tensor of absolute write indices. On a signature miss it (re)traces + compiles; otherwise it is a pure run + buffer write-back. Falls back to a plain eager forward_fn call if the decode graph cannot be compiled, and under grad mode when the step needs gradients (see the module notes).

Used by 3