pub enum RotationState {
Real(NoRotation),
Angle(Tensor<3>),
Quaternion(Tensor<4>),
Rotor(Tensor<4>),
}Expand description
The cumulative-rotation accumulator carried between calls in a Mamba-3 cache
— the variant matching the block’s RotationKind.
Real— nothing at all: a real transition has no cumulative rotation to carry.Angle— abelian per-pair cumulative RoPE angle, shape[batch, nheads, num_rope_angles](today’scum_angle).Quaternion— per-block cumulative unit quaternion, shape[batch, nheads, blocks, 4], produced byquat_cumprod.
This is the cache-level counterpart of RotationKind. It is defined here
(the rotation module owns the accumulator type); substituting it for the
pathway caches’ cum_angle_bha field happens together with the forward/step
wiring that consumes it.
Variants§
Real(NoRotation)
RotationKind::Real1D’s empty accumulator: a real transition composes
nothing between calls. It carries a NoRotation only because Burn’s
Module derive takes exactly one field per enum variant.
Angle(Tensor<3>)
Abelian RoPE cumulative angle, shape [batch, nheads, num_rope_angles].
Quaternion(Tensor<4>)
Quaternion cumulative rotation, shape [batch, nheads, blocks, 4].
Rotor(Tensor<4>)
SO(4) cumulative rotation, shape [batch, nheads, 2·blocks, 4]: the
left factors Qₜ = qₜ⊗⋯⊗q₁ in the first blocks entries of the block
axis, the right factors Tₜ = pₜ⊗⋯⊗p₁ in the second (see
split_rotor).
One tensor rather than two so the scan, the normalisation and the cache
plumbing stay single-call; the conjugation in v ↦ q v p̄ reverses the
right-hand order twice, so T accumulates with the very same
left-fold as Q and no reversed scan is needed.
Implementations§
Source§impl RotationState
impl RotationState
Sourcepub fn real() -> Self
pub fn real() -> Self
The empty accumulator of RotationKind::Real1D.
Sourcepub fn zeros_angle(
batch: usize,
nheads: usize,
num_rope_angles: usize,
device: &Device,
) -> Self
pub fn zeros_angle( batch: usize, nheads: usize, num_rope_angles: usize, device: &Device, ) -> Self
Zero-initialised abelian angle accumulator [batch, nheads, num_rope_angles].
Sourcepub fn identity_quaternion(
batch: usize,
nheads: usize,
blocks: usize,
device: &Device,
) -> Self
pub fn identity_quaternion( batch: usize, nheads: usize, blocks: usize, device: &Device, ) -> Self
Identity-initialised quaternion accumulator [batch, nheads, blocks, 4]
(every block is the identity quaternion (1, 0, 0, 0)).
Sourcepub fn expect_real(self) -> Self
pub fn expect_real(self) -> Self
Sourcepub fn angle(self) -> Tensor<3>
pub fn angle(self) -> Tensor<3>
Unwrap the abelian angle accumulator; panics if this is a quaternion.
Sourcepub fn identity_rotor(
batch: usize,
nheads: usize,
blocks: usize,
device: &Device,
) -> Self
pub fn identity_rotor( batch: usize, nheads: usize, blocks: usize, device: &Device, ) -> Self
Identity-initialised SO(4) accumulator [batch, nheads, 2·blocks, 4]
(both factors of every block are the identity quaternion (1, 0, 0, 0)).
Sourcepub fn identity(
kind: RotationKind,
batch: usize,
nheads: usize,
num_rope_angles: usize,
num_quat_blocks: usize,
device: &Device,
) -> Self
pub fn identity( kind: RotationKind, batch: usize, nheads: usize, num_rope_angles: usize, num_quat_blocks: usize, device: &Device, ) -> Self
The identity accumulator for kind — the one place a fresh cache’s
rotation state is built, for every pathway and both cache types.
Sourcepub fn quaternion(self) -> Tensor<4>
pub fn quaternion(self) -> Tensor<4>
Unwrap the quaternion accumulator; panics if this is an angle.
Sourcepub fn rotor(self) -> Tensor<4>
pub fn rotor(self) -> Tensor<4>
Unwrap the SO(4) accumulator ([batch, nheads, 2·blocks, 4], both
factors stacked); panics for any other variant.
Sourcefn quat_stack(self, kind: RotationKind) -> (Tensor<4>, usize)
fn quat_stack(self, kind: RotationKind) -> (Tensor<4>, usize)
The stacked quaternion accumulator for kind, together with the number
of state 4-blocks it covers — half its block axis for
RotationKind::Rotor4D, which stacks two factors there.
Panics on a variant the kind does not use: the two are the same rank and differ only in the length of one axis, so a mismatched cache would otherwise be reinterpreted rather than rejected.
Sourcepub fn sanity(&self)
pub fn sanity(&self)
Run the NaN/Inf guards on the held tensor.
Trait Implementations§
Source§impl AutodiffModule for RotationState
impl AutodiffModule for RotationState
Source§impl Clone for RotationState
impl Clone for RotationState
Source§impl Debug for RotationState
impl Debug for RotationState
Source§impl Display for RotationState
impl Display for RotationState
Source§impl Module for RotationState
impl Module for RotationState
Source§fn num_params(&self) -> usize
fn num_params(&self) -> usize
Source§fn visit<Visitor: ModuleVisitor>(&self, visitor: &mut Visitor)
fn visit<Visitor: ModuleVisitor>(&self, visitor: &mut Visitor)
Source§fn map<Mapper: ModuleMapper>(self, mapper: &mut Mapper) -> Self
fn map<Mapper: ModuleMapper>(self, mapper: &mut Mapper) -> Self
Source§fn collect_devices(&self, devices: Devices) -> Devices
fn collect_devices(&self, devices: Devices) -> Devices
Source§fn to_device(self, device: &Device) -> Self
fn to_device(self, device: &Device) -> Self
Source§fn fork(self, device: &Device) -> Self
fn fork(self, device: &Device) -> Self
§fn devices(&self) -> Vec<Device>
fn devices(&self) -> Vec<Device>
§fn freeze_group(self, group: ParamGroup) -> Self
fn freeze_group(self, group: ParamGroup) -> Self
require_grad to false for every parameter in the given group, leaving the rest
of the module untouched. Read more§fn unfreeze_group(self, group: ParamGroup) -> Self
fn unfreeze_group(self, group: ParamGroup) -> Self
require_grad to true for every parameter in the given group, leaving the rest
of the module untouched. Read more§fn train(self) -> Selfwhere
Self: AutodiffModule,
fn train(self) -> Selfwhere
Self: AutodiffModule,
§fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
fn quantize_weights(self, quantizer: &mut Quantizer) -> Self
§fn quantize_weights_group(
self,
quantizer: &mut Quantizer,
group: ParamGroup,
) -> Self
fn quantize_weights_group( self, quantizer: &mut Quantizer, group: ParamGroup, ) -> Self
§fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
fn apply_reparameterization<R>(self, reparameterizer: R) -> Selfwhere
Self: Sized,
R: Reparameterizer,
Reparameterizer]. Read more§fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
fn apply_lora(self, lora: Lora) -> Selfwhere
Self: Sized,
§fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
fn apply_qlora(self, qlora: QLora) -> Selfwhere
Self: Sized,
§fn into_record(self) -> ModuleRecordwhere
Self: Sized,
fn into_record(self) -> ModuleRecordwhere
Self: Sized,
ModuleRecord. Read more§fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
fn into_record_group(self, group: ParamGroup) -> ModuleRecordwhere
Self: Sized,
§fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
fn try_load_record(self, record: ModuleRecord) -> Result<Self, RecordError>where
Self: Sized,
ModuleRecord to this module, returning the loaded
module. Read more§fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
fn load_record(self, record: ModuleRecord) -> Selfwhere
Self: Sized,
ModuleRecord to this module, consuming and returning
it. Read more