conditioning
conditioning
¶
Conditioning cache for static context (observations, encoder features).
Conditioning information does not change between forward calls — whether consumed via cross-attention, joint attention, or prefix concatenation. The cache is computed once before generation starts and reused unchanged across all forward calls.
ConditioningLayerCache
dataclass
¶
Per-layer K/V cache for static conditioning (computed once, reused).
Stores precomputed projections for conditioning information that does not change between forward calls. Populated once before generation starts.
Attributes:
| Name | Type | Description |
|---|---|---|
keys |
Tensor
|
Precomputed keys (B, kv_heads, S, head_dim). |
values |
Tensor
|
Precomputed values (B, kv_heads, S, head_dim). |
queries |
Tensor | None
|
Precomputed queries (B, heads, S, head_dim). Populated when conditioning participates bidirectionally (both streams attend to each other). None when conditioning is only attended to. |
ConditioningCache
dataclass
¶
Multi-layer conditioning cache for static context.
Attributes:
| Name | Type | Description |
|---|---|---|
layers |
list[ConditioningLayerCache | None]
|
One ConditioningLayerCache (or None) per decoder layer. |
CacheableLayer
¶
Bases: Protocol
Layer that can precompute conditioning K/V projections.
precompute_conditioning_kv
¶
Project encoded features to cacheable conditioning keys and values.
precompute_conditioning
¶
Precompute conditioning K/V for all layers.
Calls each layer's precompute_conditioning_kv to project encoder features through cross-attention K/V weights once, for reuse across forward calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layers
|
Iterable[CacheableLayer]
|
Decoder layers satisfying CacheableLayer protocol. |
required |
encoded_features
|
Tensor
|
Encoder features (B, memory_length, D). |
required |
Returns:
| Type | Description |
|---|---|
ConditioningCache
|
ConditioningCache with one ConditioningLayerCache per layer. |