qualia_core_db/inference/lab/
audit_path.rs1use crate::inference_modes::{
4 active_inference_mode, post_turn_verify_enabled, prefer_tensor_core_gemm,
5 quant_graph_grounding_enabled, sentinel_mid_decode_enabled,
6};
7use crate::llm_bench::{
8 attention_o_fuse_enabled, attention_preproject_enabled, coop_gemv_enabled, ffn_fusion_enabled,
9 ffn_fusion_in_resident, kv_int8_enabled, resident_decode_enabled, resident_prefill_enabled,
10 resident_weights_enabled,
11};
12
13#[derive(Debug, Clone)]
14pub struct HotPathAudit {
15 pub resident_decode: bool,
16 pub resident_prefill: bool,
17 pub resident_weights: bool,
18 pub coop_gemv: bool,
19 pub ffn_fusion_flag: bool,
20 pub ffn_fusion_in_resident_decode: bool,
21 pub kv_int8: bool,
22 pub attention_preproject: bool,
23 pub attention_o_fuse: bool,
24 pub prefer_cuda_gemm: bool,
25 pub cuda_caps: bool,
26 pub mode: String,
27 pub post_turn_verify: bool,
28 pub sentinel_mid: bool,
29 pub quant_graph: bool,
30 pub timestamps_supported: bool,
31 pub gpu_profile_env: bool,
32 pub notes: Vec<String>,
33}
34
35pub fn audit_hot_path() -> HotPathAudit {
37 let mut notes = Vec::new();
38 let ffn_flag = ffn_fusion_enabled();
39 let ffn_in_resident = ffn_fusion_in_resident();
42 if ffn_flag && !ffn_in_resident {
43 notes.push(
44 "ffn_fusion flag ON but last resident plan did not fuse (unsupported quant or plan not built yet) — T-A1 partial"
45 .into(),
46 );
47 }
48 if ffn_in_resident {
49 notes.push(
50 "T-A1/T-A1b: fused_ffn in resident (coop entry when QUALIA_LLM_COOP_GEMV on)".into(),
51 );
52 }
53
54 let cuda_caps = crate::wgsl_forge::dispatch::caps().cuda;
55 if prefer_tensor_core_gemm() && !cuda_caps {
56 notes.push("mode prefers CUDA GEMM but cuda caps=false".into());
57 }
58 if prefer_tensor_core_gemm() && cuda_caps {
59 notes.push(
60 "CUDA lane available for densify/Q4 GEMV; full hidden-on-device layer stack still open"
61 .into(),
62 );
63 }
64
65 let timestamps_supported = crate::gpu_context::shared_gpu().timestamps_supported;
66 let gpu_profile_env = std::env::var("QUALIA_LLM_GPU_PROFILE")
67 .map(|v| v == "1" || v.eq_ignore_ascii_case("true"))
68 .unwrap_or(false);
69
70 if !resident_decode_enabled() {
71 notes.push("resident_decode OFF — legacy multi-fence path".into());
72 }
73 if !coop_gemv_enabled() {
74 notes.push("coop_gemv OFF — naive GEMV".into());
75 }
76
77 HotPathAudit {
78 resident_decode: resident_decode_enabled(),
79 resident_prefill: resident_prefill_enabled(),
80 resident_weights: resident_weights_enabled(),
81 coop_gemv: coop_gemv_enabled(),
82 ffn_fusion_flag: ffn_flag,
83 ffn_fusion_in_resident_decode: ffn_in_resident,
84 kv_int8: kv_int8_enabled(),
85 attention_preproject: attention_preproject_enabled(),
86 attention_o_fuse: attention_o_fuse_enabled(),
87 prefer_cuda_gemm: prefer_tensor_core_gemm(),
88 cuda_caps,
89 mode: active_inference_mode().as_str().to_string(),
90 post_turn_verify: post_turn_verify_enabled(),
91 sentinel_mid: sentinel_mid_decode_enabled(),
92 quant_graph: quant_graph_grounding_enabled(),
93 timestamps_supported,
94 gpu_profile_env,
95 notes,
96 }
97}
98
99impl HotPathAudit {
100 pub fn format_report(&self) -> String {
101 let yn = |b: bool| if b { "yes" } else { "NO " };
102 let mut s = String::from("Hot-path wiring audit\n");
103 s.push_str(&format!(" mode: {}\n", self.mode));
104 s.push_str(&format!(
105 " resident_decode: {}\n",
106 yn(self.resident_decode)
107 ));
108 s.push_str(&format!(
109 " resident_prefill: {}\n",
110 yn(self.resident_prefill)
111 ));
112 s.push_str(&format!(
113 " resident_weights: {}\n",
114 yn(self.resident_weights)
115 ));
116 s.push_str(&format!(
117 " coop_gemv: {}\n",
118 yn(self.coop_gemv)
119 ));
120 s.push_str(&format!(
121 " ffn_fusion flag: {}\n",
122 yn(self.ffn_fusion_flag)
123 ));
124 s.push_str(&format!(
125 " ffn_fusion in resident: {} (must be yes for T-A1 done)\n",
126 yn(self.ffn_fusion_in_resident_decode)
127 ));
128 s.push_str(&format!(
129 " kv_int8: {}\n",
130 yn(self.kv_int8)
131 ));
132 s.push_str(&format!(
133 " attention_preproject: {}\n",
134 yn(self.attention_preproject)
135 ));
136 s.push_str(&format!(
137 " attention_o_fuse: {}\n",
138 yn(self.attention_o_fuse)
139 ));
140 s.push_str(&format!(
141 " prefer_cuda_gemm: {}\n",
142 yn(self.prefer_cuda_gemm)
143 ));
144 s.push_str(&format!(
145 " cuda_caps: {}\n",
146 yn(self.cuda_caps)
147 ));
148 s.push_str(&format!(
149 " post_turn_verify: {}\n",
150 yn(self.post_turn_verify)
151 ));
152 s.push_str(&format!(
153 " sentinel_mid: {}\n",
154 yn(self.sentinel_mid)
155 ));
156 s.push_str(&format!(
157 " quant_graph: {}\n",
158 yn(self.quant_graph)
159 ));
160 s.push_str(&format!(
161 " timestamps_supported: {}\n",
162 yn(self.timestamps_supported)
163 ));
164 s.push_str(&format!(
165 " QUALIA_LLM_GPU_PROFILE: {}\n",
166 yn(self.gpu_profile_env)
167 ));
168 if !self.notes.is_empty() {
169 s.push_str(" notes:\n");
170 for n in &self.notes {
171 s.push_str(&format!(" - {n}\n"));
172 }
173 }
174 s
175 }
176}
177
178#[cfg(test)]
179mod tests {
180 use super::*;
181
182 #[test]
183 fn audit_runs() {
184 let a = audit_hot_path();
185 let r = a.format_report();
186 assert!(r.contains("resident_decode"));
187 assert!(r.contains("ffn_fusion in resident"));
188 }
189}