#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[repr(u8)]
pub enum DepthTier {
Plasma = 0,
Hot = 1,
Warm = 2,
Cold = 3,
}
impl DepthTier {
pub fn max_layers(&self, total_layers: usize) -> usize {
match self {
DepthTier::Plasma => 1.min(total_layers),
DepthTier::Hot => 2.min(total_layers),
DepthTier::Warm => total_layers,
DepthTier::Cold => total_layers,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(u8)]
pub enum HlaMode {
#[default]
Standard,
Hla,
Ahla,
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum AttentionMode {
#[default]
Causal,
Bidirectional,
BlockCausal,
SpKv,
SpKvQuant,
DashAttn,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(u8)]
pub enum ModelArchitecture {
#[default]
Generic,
Gemma2,
Llama,
#[cfg(feature = "deltanet_inference")]
QwenDeltaNet,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum AttentionProjection {
#[default]
Full,
SharedKV,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum CacheLayout {
KV,
K,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(u8)]
pub enum WeightDtype {
#[default]
F32,
F16,
BF16,
}
#[allow(dead_code)]
#[repr(u8)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum DeltaRoutingMode {
#[default]
Off,
DeltaBlock,
DeltaAttnRes,
}
#[allow(dead_code)]
#[derive(Clone, Copy, Debug)]
pub struct DeltaRoutingConfig {
pub block_size: usize,
pub mode: DeltaRoutingMode,
}
impl Default for DeltaRoutingConfig {
fn default() -> Self {
Self {
block_size: 4,
mode: DeltaRoutingMode::Off,
}
}
}
#[cfg(feature = "deltanet_inference")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(u8)]
pub enum DeltaNetLayerType {
#[default]
Attention,
DeltaNet,
}
#[allow(dead_code)]
impl DeltaRoutingConfig {
pub fn delta_block(block_size: usize) -> Self {
Self {
mode: DeltaRoutingMode::DeltaBlock,
block_size,
}
}
pub fn is_enabled(&self) -> bool {
self.mode != DeltaRoutingMode::Off
}
}
#[derive(Clone, Copy, Debug)]
pub struct DashAttnConfig {
pub chunk_size: usize,
pub alpha: f32,
pub scaling_factor: f32,
pub sigma: f32,
pub estimate_diagonal: bool,
}
impl Default for DashAttnConfig {
fn default() -> Self {
Self {
chunk_size: 64,
alpha: 1.5,
scaling_factor: 1.0,
sigma: 1e6,
estimate_diagonal: true,
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#[repr(u8)]
pub enum RetrievalHeadRole {
#[default]
Local,
Retrieval,
}
#[derive(Clone, Copy, Debug)]
pub struct RtTurboConfig {
pub low_dim: usize,
pub sliding_window: usize,
pub sink_tokens: usize,
pub block_size: usize,
pub retrieval_head_ratio: f32,
pub top_p: f32,
pub calibration_mode: CalibrationMode,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)]
#[repr(u8)]
pub enum CalibrationMode {
#[default]
AttentionMass = 0,
CausalNecessity = 1,
AdaptiveCausal = 2,
}
impl Default for RtTurboConfig {
fn default() -> Self {
Self {
low_dim: 16,
sliding_window: 8192,
sink_tokens: 4,
block_size: 64,
retrieval_head_ratio: 0.15,
top_p: 0.9,
calibration_mode: CalibrationMode::default(),
}
}
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(u8)]
pub enum LoopMode {
#[default]
None,
WeightShared { loop_count: usize },
TrainingFree,
}
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[repr(u8)]
pub enum HybridPattern {
#[default]
Uniform,
Interleave { full_ratio: usize },
Bookend,
}
#[derive(Clone)]
pub struct SdpaOutputGate {
pub w_gate: Vec<f32>,
}
impl SdpaOutputGate {
pub fn new(n_heads: usize, head_dim: usize, dim: usize) -> Self {
Self {
w_gate: vec![0.0; n_heads * head_dim * dim],
}
}
pub fn forward(&self, attn_out: &mut [f32], dim: usize, temp: &mut [f32]) {
let n = attn_out.len();
debug_assert!(temp.len() >= n, "temp buffer too small");
debug_assert!(self.w_gate.len() >= n * dim, "gate weights too small");
crate::simd::simd_matvec(temp, &self.w_gate, attn_out, n, dim);
crate::simd::simd_scale_inplace(&mut temp[..n], -1.0);
crate::simd::simd_exp_inplace(&mut temp[..n]);
crate::simd::simd_add_scalar_inplace(&mut temp[..n], 1.0);
crate::simd::simd_reciprocal_inplace(&mut temp[..n]);
crate::simd::simd_scale_mul_inplace(attn_out, &temp[..n], 1.0);
}
}
#[derive(Clone)]
pub struct ResidualGate {
pub gates: Vec<f32>,
}
impl ResidualGate {
pub fn new(loop_count: usize, dim: usize) -> Self {
Self {
gates: vec![0.0; loop_count * dim],
}
}
}
#[cfg(feature = "sr2am_configurator")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
#[repr(u8)]
pub enum PlanningDecision {
PlanNew,
PlanExtend,
PlanSkip,
SpecHop { k: usize },
#[cfg(feature = "sia_feedback")]
HarnessUpdate,
#[cfg(feature = "sia_feedback")]
WeightUpdate,
}
#[cfg(feature = "sr2am_configurator")]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct ConfiguratorContext {
pub domain: usize,
pub entropy_bin: u8,
pub desperation_bin: u8,
pub epiplexity_bin: u8,
}
#[cfg(feature = "sr2am_configurator")]
impl ConfiguratorContext {
pub fn new(domain: usize, entropy_bin: usize) -> Self {
Self {
domain,
entropy_bin: (entropy_bin.min(9)) as u8,
desperation_bin: 0,
epiplexity_bin: 0,
}
}
pub fn with_desperation(mut self, desperation: f32) -> Self {
self.desperation_bin = ((desperation * 10.0).floor() as u8).min(9);
self
}
pub fn with_epiplexity(mut self, epiplexity: f32) -> Self {
self.epiplexity_bin = ((epiplexity * 10.0).floor() as u8).min(9);
self
}
pub fn from_entropy_epiplexity(domain: usize, entropy: f32, epiplexity: f32) -> Self {
let entropy_bin = ((entropy * 10.0).floor() as u8).min(9);
let epiplexity_bin = ((epiplexity * 10.0).floor() as u8).min(9);
Self {
domain,
entropy_bin,
desperation_bin: 0,
epiplexity_bin,
}
}
pub fn epiplexity_bin(epiplexity: f32) -> u8 {
((epiplexity * 10.0).floor() as u8).min(9)
}
}
#[repr(u8)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub enum ConvergenceSelector {
#[default]
BestQ,
MajorityVote,
Top1Converged,
BtRank,
}
#[derive(Clone, Copy, Debug, serde::Serialize, serde::Deserialize)]
#[cfg(feature = "wall_attention")]
pub struct WallConfig {
pub gate_bias: f32,
pub gate_max: f32,
pub use_key_projected: bool,
pub gate_proj_dim: usize,
}
#[cfg(feature = "wall_attention")]
impl Default for WallConfig {
fn default() -> Self {
Self {
gate_bias: 6.0,
gate_max: 0.87,
use_key_projected: true,
gate_proj_dim: 0,
}
}
}
#[cfg(feature = "wall_attention")]
impl WallConfig {
pub fn new() -> Self {
Self::default()
}
pub fn validate(&self, n_kv_heads: usize, head_dim: usize) -> Result<(), String> {
if self.gate_max <= 0.0 || self.gate_max >= 1.0 {
return Err(format!("gate_max must be in (0, 1), got {}", self.gate_max));
}
let expected_dim = n_kv_heads * head_dim;
if self.gate_proj_dim != 0 && self.gate_proj_dim != expected_dim {
return Err(format!(
"gate_proj_dim ({}) must equal n_kv_heads * head_dim ({})",
self.gate_proj_dim, expected_dim
));
}
Ok(())
}
pub fn with_dims(mut self, n_kv_heads: usize, head_dim: usize) -> Self {
self.gate_proj_dim = n_kv_heads * head_dim;
self
}
}
#[allow(dead_code)]
#[derive(Clone, Copy, Debug)]
pub struct ThinkingBudget {
pub max_tokens: u32,
pub collapse_threshold: u32,
pub efficiency_gamma: f32,
}
#[cfg(feature = "collapse_aware_thinking")]
impl Default for ThinkingBudget {
fn default() -> Self {
Self {
max_tokens: 4096,
collapse_threshold: 3,
efficiency_gamma: 0.5,
}
}
}