fn
compiled_decode_step
→callablecompiled_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_ fncallableforward_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).static_ cacheStaticCache or EncoderDecoderCacheThe cache whose per-layer self-attention buffers
forward_fn writes
via lucid.index_copy. Its buffers are rolled forward in place.Returns
callablestep(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).