1use super::ModelLevers;
15use crate::layers::ops::gemv_sw;
16
17pub(super) fn from_values(
18 mut value: impl FnMut(&str) -> Option<String>,
19 mut present: impl FnMut(&str) -> bool,
20 shadow_topk: usize,
21 drafter: crate::model::drafter_context::DrafterContext,
22 draft_conf_tau: f32,
30 default_split_silu: bool,
34) -> ModelLevers {
35 fn opt_in(value: Option<&str>) -> bool {
36 value == Some("1")
37 }
38 fn opt_out(value: Option<&str>) -> bool {
39 value != Some("0")
40 }
41 fn opt_in_truthy(value: Option<&str>) -> bool {
42 value.is_some_and(|value| value == "1" || value.eq_ignore_ascii_case("true"))
43 }
44 fn opt_in_truthy_exact(value: Option<&str>) -> bool {
52 matches!(value, Some("1") | Some("true"))
53 }
54
55 ModelLevers {
56 max_decode_seqs: 1,
57 shadow_topk,
58 kv_poison: opt_in(value("ATLAS_KV_POISON").as_deref()),
59 drafter,
60 gdn_regresident: value("ATLAS_NO_GDN_REGRESIDENT").as_deref() != Some("1"),
61 gdn_batched_fla: opt_in(value("ATLAS_GDN_BATCHED_FLA").as_deref()),
62 gdn_wy17: opt_out(value("ATLAS_GDN_WY17").as_deref()),
63 gdn_wyn: opt_out(value("ATLAS_GDN_WYN").as_deref()),
64 ffn_small_m: opt_out(value("ATLAS_FFN_SMALLM").as_deref()),
65 gemv_sw: gemv_sw::gemv_sw_from(value("ATLAS_NO_GEMV_SW").as_deref()),
66 decode_ffn_via_gemm: opt_in(value("ATLAS_DECODE_FFN_VIA_GEMM").as_deref()),
67 holo_moe_down_fp4: opt_in_truthy(value("ATLAS_HOLO_MOE_DOWN_FP4").as_deref()),
68 holo_moe_gateup_fp4: opt_in_truthy(value("ATLAS_HOLO_MOE_GATEUP_FP4").as_deref()),
69 moe_union_stats: opt_in(value("ATLAS_MOE_UNION_STATS").as_deref()),
70 fp32_routing: opt_in(value("ATLAS_FP32_ROUTING").as_deref()),
71 fp32_gate: opt_in(value("ATLAS_FP32_GATE").as_deref()),
72 frankenstein_decode_via_prefill: opt_in(
73 value("ATLAS_FRANKENSTEIN_DECODE_VIA_PREFILL").as_deref(),
74 ),
75 k2_diag: opt_in(value("ATLAS_K2_DIAG").as_deref()),
76 dflash_debug_dump_full: opt_in(value("ATLAS_DFLASH_DEBUG_DUMP_FULL").as_deref()),
77 mtp_debug_norms: opt_in(value("ATLAS_MTP_DEBUG_NORMS").as_deref()),
78 draft_conf_tau,
79 decode_split_silu: crate::layers::ops::target_defaults::resolve_toggle(
88 default_split_silu,
89 None,
90 present("ATLAS_NO_DECODE_SPLIT_SILU"),
91 )
92 .value,
93 bf16_tc_prefill: present("ATLAS_BF16_TC_PREFILL"),
94 fp8_m64_prefill: present("ATLAS_FP8_M64_PREFILL"),
95 int8_prefill: present("ATLAS_INT8_PREFILL"),
96 int8_faith5: present("ATLAS_INT8_FAITH5"),
97 ffn_nvfp4_mmq: !present("ATLAS_NO_FFN_NVFP4_MMQ"),
98 ffn_nvfp4_mmq_down: !present("ATLAS_NO_FFN_NVFP4_MMQ_DOWN"),
99 ffn_mmq: present("ATLAS_FFN_MMQ"),
100 ffn_mmq_down_q4k: present("ATLAS_FFN_MMQ_DOWN_Q4K"),
101 fp4_prefill: present("ATLAS_FP4_PREFILL"),
102 prefill_v2: !present("ATLAS_DISABLE_PREFILL_V2"),
103 moe_grouped_cutlass: opt_in(value("ATLAS_HOLO_MOE_GROUPED_CUTLASS").as_deref()),
104 moe_grouped_down: opt_in(value("ATLAS_HOLO_MOE_GROUPED_DOWN").as_deref()),
105 moe_prefill_exact_tiles: match value("ATLAS_MOE_PREFILL_EXACT_TILES").as_deref() {
106 Some("0") => Some(false),
107 Some("1") => Some(true),
108 _ => None,
109 },
110 moe_prefill_max_load_factor: value("ATLAS_MOE_PREFILL_MAX_LOAD_FACTOR")
111 .as_deref()
112 .and_then(|v| v.parse::<usize>().ok())
113 .filter(|&factor| factor > 0),
114 moe_prefill_zero: opt_in(value("ATLAS_MOE_PREFILL_ZERO").as_deref()),
115 moe_prefill_fp8_down: opt_in(value("ATLAS_MOE_PREFILL_FP8_DOWN").as_deref()),
116 ssm_w4a4: !present("ATLAS_NO_SSM_W4A4"),
117 ssd: !present("ATLAS_NO_SSD"),
118 ssm_persistent: !present("ATLAS_NO_SSM_PERSISTENT"),
119 moe_zero_intermediates: !present("ATLAS_MOE_NO_ZERO_INTERMEDIATES"),
120 moe_max_m_tiles_estimate: present("ATLAS_MOE_MAX_M_TILES_ESTIMATE"),
121 moe_w4a4: present("ATLAS_MOE_W4A4"),
122 shared_w4a4: !present("ATLAS_NO_SHARED_W4A4"),
123 shared_w4a4_down: present("ATLAS_SHARED_W4A4_DOWN"),
124 dflash_contig_attn: opt_in(value("ATLAS_DFLASH_CONTIG_ATTN").as_deref()),
125 lora_eager: opt_in_truthy(value("ATLAS_LORA_EAGER").as_deref()),
126 lora_rotate: opt_in_truthy(value("ATLAS_LORA_ROTATE").as_deref()),
127 k4_diag: opt_in(value("ATLAS_K4_DIAG").as_deref()),
128 gemma4_diag: opt_in_truthy(value("ATLAS_DIAG_GEMMA4").as_deref()),
129 mla_perseq_fallback: opt_in_truthy_exact(value("ATLAS_MLA_PERSEQ_FALLBACK").as_deref()),
130 hc_perseq_decode: opt_in(value("ATLAS_HC_PERSEQ_DECODE").as_deref()),
131 decode_batch_log: opt_in(value("ATLAS_DECODE_BATCH_LOG").as_deref()),
132 ms_profile: opt_in(value("ATLAS_MS_PROFILE").as_deref()),
133 conc_hsd: opt_in_truthy_exact(value("ATLAS_CONC_HSD").as_deref()),
134 ssm_save_dump: present("ATLAS_SSM_SAVE_DUMP"),
135 ep_graphs: opt_in_truthy_exact(value("ATLAS_EP_GRAPHS").as_deref()),
136 gdn_decode_graph: opt_in_truthy_exact(value("ATLAS_GDN_DECODE_GRAPH").as_deref()),
137 bf16_tc_proj: present("ATLAS_BF16_TC_PROJ"),
138 weight_pre_rotated: opt_in_truthy(value("TQ_PLUS_WEIGHT_ROTATION").as_deref()),
139 ssm_ms_profile: opt_in(value("ATLAS_SSM_MS_PROFILE").as_deref()),
140 ssm_detail_profile: opt_in(value("ATLAS_SSM_DETAIL_PROFILE").as_deref()),
141 ssm_gemv_batch4: opt_out(value("ATLAS_SSM_GEMV_BATCH4").as_deref()),
142 gdn_fused_conv: opt_in(value("ATLAS_GDN_FUSED_CONV").as_deref()),
143 moe_legacy_pertoken_decode: opt_in(value("ATLAS_MOE_LEGACY_PERTOKEN_DECODE").as_deref()),
144 }
145}
146
147impl ModelLevers {
148 pub fn get() -> &'static Self {
166 static LEVERS: std::sync::OnceLock<ModelLevers> = std::sync::OnceLock::new();
167 LEVERS.get_or_init(Self::from_env)
168 }
169
170 pub fn from_env() -> Self {
177 from_values(
178 |var| std::env::var(var).ok(),
179 |var| std::env::var_os(var).is_some(),
180 crate::speculative::shadow_topk(),
181 crate::model::drafter_context::resolve_from_env(),
182 crate::speculative::draft_conf_tau(),
183 crate::layers::ops::target_defaults::declared().decode_split_silu,
184 )
185 }
186
187 pub fn defaults() -> Self {
191 Self {
192 max_decode_seqs: 1,
193 shadow_topk: 0,
194 kv_poison: false,
195 drafter: crate::model::drafter_context::DrafterContext::BOTH,
196 gdn_regresident: true,
197 gdn_wy17: true,
198 gdn_wyn: true,
199 ffn_small_m: true,
200 gemv_sw: true,
201 ssm_gemv_batch4: true,
206 decode_split_silu: true,
211 ffn_nvfp4_mmq: true,
212 ffn_nvfp4_mmq_down: true,
213 prefill_v2: true,
214 ssm_w4a4: true,
217 ssd: true,
218 ssm_persistent: true,
219 moe_zero_intermediates: true,
220 shared_w4a4: true,
221 ..Self::default()
222 }
223 }
224}