Skip to main content

qualia_core_db/inference/
mod.rs

1//! `inference` category (reorg).
2
3// Inference-runtime components. These run model inference (a tensor program) — the underlying
4// mathematics now lives in `crate::solvers` (GEMM, activations, softmax, normalization, attention,
5// RoPE, FFN). The old `llm_*` names are kept as transitional aliases; "inference" is what these are.
6pub mod inference_agent;
7pub use inference_agent as llm_agent; // transitional alias
8pub mod inference_awq;
9pub use inference_awq as llm_awq; // transitional alias
10#[cfg(not(target_arch = "wasm32"))]
11pub mod inference_bench;
12#[cfg(target_arch = "wasm32")]
13pub mod inference_bench_wasm;
14#[cfg(not(target_arch = "wasm32"))]
15pub mod kv_capture;
16pub mod kv_dict;
17#[cfg(not(target_arch = "wasm32"))]
18pub mod kv_dict_runtime;
19#[cfg(not(target_arch = "wasm32"))]
20pub use inference_bench as llm_bench; // transitional alias
21#[cfg(target_arch = "wasm32")]
22pub use inference_bench_wasm as llm_bench; // transitional alias
23pub mod inference_eval;
24pub use inference_eval as llm_eval; // transitional alias
25#[cfg(feature = "gpu-runtime")]
26pub mod inference_gpu_profiler;
27#[cfg(feature = "gpu-runtime")]
28pub use inference_gpu_profiler as llm_gpu_profiler; // transitional alias
29pub mod inference_kernel_parity;
30pub use inference_kernel_parity as llm_kernel_parity; // transitional alias
31pub mod agent;
32#[cfg(not(target_arch = "wasm32"))]
33pub mod ambient_orchestration;
34pub mod compute_universe;
35#[cfg(target_os = "windows")]
36pub mod directml_bridge;
37pub mod domino_gbnf;
38pub mod ggml_quants;
39pub mod gguf_sharder;
40#[cfg(any(target_os = "macos", target_os = "ios"))]
41pub mod metal_bridge;
42pub mod moe;
43pub mod neuro_symbolic_sieve;
44#[cfg(feature = "vision-onnx")]
45pub mod onnx_runtime;
46pub mod operator_converter;
47pub mod operator_package;
48pub mod operator_runtime;
49pub mod orchestrator;
50pub mod qwen;
51#[cfg(not(target_arch = "wasm32"))]
52pub mod residency_planner;
53pub mod resident_model;
54pub mod safetensor;
55pub mod safetensor_loader;
56pub mod semantic_culler;
57pub mod spatial_sieve;
58pub mod tensor_roles;
59pub mod ternary;
60#[cfg(feature = "gpu-runtime")]
61pub mod ternary_gpu;
62/// Stage-by-stage library probe tests for the inference optim toolkit.
63#[cfg(test)]
64pub mod toolkit_probe;
65pub mod topk;
66// W2: exact CPU sampling chain (pure, wasm-safe — no GPU, no `rand`, no file I/O).
67pub mod sampler;
68// Multi-mode inference (portable / cuda-tc / quant-graph) — coexisting approaches.
69pub mod inference_modes;
70pub use inference_modes::{
71    active_inference_mode, apply_mode_toggles, bootstrap_inference_mode, fast_verify_html_default,
72    post_turn_verify_enabled, prefer_tensor_core_gemm, quant_graph_grounding_enabled,
73    rights_mode_enabled, sentinel_mid_decode_enabled, set_inference_mode, InferenceMode,
74};
75// Application profiles: interactive / live-fast / batch-overnight (no Ollama).
76pub mod application_profile;
77pub use application_profile::{
78    active_application_profile, apply_application_profile, bootstrap_application_profile,
79    set_application_profile, ApplicationProfile,
80};
81// Inference superiority lab (plan: inference-superiority-lab-and-toolset-plan.md).
82#[cfg(not(target_arch = "wasm32"))]
83pub mod lab;
84// Prepared native inference plan/run boundary, execution receipts, and bounded run artifacts.
85#[cfg(not(target_arch = "wasm32"))]
86pub mod runtime;
87// Post-turn verify / self-heal (FastVerify path).
88pub mod post_turn_verify;
89pub use post_turn_verify::{
90    maybe_verify_turn, return_html_as_text, verify_and_heal_turn, VerifiedTurn, VerifyCheck,
91};
92// Device-optimal path: passport benchmark → pick dx12/vulkan/metal/cuda lane + quant.
93#[cfg(not(target_arch = "wasm32"))]
94pub mod inference_path_selector;
95#[cfg(not(target_arch = "wasm32"))]
96pub use inference_path_selector::{
97    apply_inference_path_plan, bootstrap_optimal_inference_path, format_path_plan,
98    last_inference_path_plan, path_auto_enabled, resolve_inference_path_plan, run_path_select_cli,
99    ComputeLane, InferencePathPlan, QuantProfile,
100};
101// QuantGraph: selective fact grounding / repair after LLM proposal.
102pub mod quant_graph_grounding;
103pub use quant_graph_grounding::{
104    export_fact_quins, fact_count, ground_generation, load_facts_from_tsv, lookup_capital_object,
105    maybe_ground_generation, register_capital_fact, register_fact, reset_fact_store_to_defaults,
106    seed_facts_from_bundled, GroundingFact, GroundingResult, CTX_GROUNDING, P_CAPITAL_OF,
107};
108// Qualia-unique hybrid: graph route mask + fact draft + 10D query + deontic gate.
109pub mod qualia_hybrid;
110pub use qualia_hybrid::{
111    apply_graph_logit_bias, force_fact_tokens, graph_force_enabled, prepare_hybrid_decode,
112    propose_best_draft, propose_fact_draft, publish_graph_route_from_prompt,
113    publish_grounding_obligation, publish_prompt_query_tensor, GRAPH_LOGIT_BIAS,
114};
115// CUDA dense batch GEMM lane (mode=cuda); stub when feature off.
116#[cfg(all(not(target_arch = "wasm32"), feature = "cuda"))]
117pub mod cuda_lane;
118#[cfg(any(target_arch = "wasm32", not(feature = "cuda")))]
119pub mod cuda_lane_stub;
120#[cfg(all(not(target_arch = "wasm32"), feature = "cuda"))]
121pub use cuda_lane::{
122    cache_dense_weight, clear_weight_cache, dense_weight_cached, device_kv_ready,
123    ensure_device_kv_cache, preload_resident_blob, prepare_mega_pass_kernels,
124    q4k_device_weight_count, q4k_weight_resident, q8_0_gemv_oracle_into, try_cuda_batch_gemv,
125    try_cuda_batch_gemv_cached, try_cuda_batch_gemv_cached_only, try_cuda_mega_pass,
126    try_q4k_soa_attention_device, try_q4k_soa_ffn_block, try_q4k_soa_ffn_block_residual,
127    try_q4k_soa_fused_swiglu, try_q4k_soa_gemv, try_q4k_soa_qkv, try_q8_0_cuda_gemv,
128    warm_cuda_context, weight_cache_len, weight_fingerprint, MegaPassLayerDims,
129    MegaPassLayerWeights, MegaPassPlanView, MegaPassWeightLayout, MAX_DENSE_ELEMS,
130    Q8_0_BLOCK_BYTES, Q8_0_BLOCK_ELEMS,
131};
132#[cfg(any(target_arch = "wasm32", not(feature = "cuda")))]
133pub use cuda_lane_stub as cuda_lane;
134// W6a: prompt-lookup speculative decoding proposer (pure, wasm-safe).
135pub mod prompt_lookup;
136// A2: DOMINO speculative constrained decoding (prefix-trie token masking).
137pub mod speculative_decode;
138pub use speculative_decode::{
139    DominoMasker, GrammarState, GrammarStateMachine, TokenTrie, MAX_TRIE_DEPTH,
140};
141// A9: Semantic Skills — vectors, embeddings, scratchpads.
142pub mod semantic_skills;
143pub use semantic_skills::{
144    Scratchpad, ScratchpadEntry, ScratchpadError, SearchResult, StoredVector, TextEmbedder, Vector,
145    VectorStore, DEFAULT_SCRATCHPAD_TTL, EMBED_DIM, MAX_SCRATCHPAD_ENTRIES, MAX_VECTORS,
146};
147// N5: Cross-encoder reranker for candidate re-scoring.
148pub mod reranker;
149// Metal mega-pass orchestrator (Apple Silicon). Stub on non-macOS.
150pub mod metal_lane;
151// Paged KV cache: block-paged KV storage (vLLM-style). Re-exports `runtime::kv::paged`, so it
152// carries the same native-only gate as `runtime`.
153#[cfg(not(target_arch = "wasm32"))]
154pub mod paged_kv;
155#[cfg(feature = "gpu-runtime")]
156pub mod topk_gpu;
157// OMP sparse KV-cache decomposition builds on `crate::solvers` (dense linear
158// algebra), which is itself native-or-`wasm-scientific`; mirror that gate.
159#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-scientific"))]
160pub mod sparse_cache;
161// The thermal-eviction WAL is a file-backed `memmap2` mmap — fundamentally
162// native (no mmap'd files on wasm32).
163#[cfg(not(target_arch = "wasm32"))]
164pub mod thermal_wal;
165
166// W7: real GPU thermal/power telemetry + detect-and-recommend governor (native-only; NVML behind the
167// optional `nvml` feature). The module's own inner cfg makes it empty on wasm32.
168#[cfg(not(target_arch = "wasm32"))]
169pub mod thermal_telemetry;
170
171// Portable conditioning compiler (Prompt Precision P1C)
172pub mod conditioning;
173
174// Prompt precision evaluation and paired scoring (Prompt Precision P5)
175pub mod conditioning_eval;
176
177// Model mapping and precision optimization pipeline
178pub mod conditioning_opt;
179
180// Etalon-tensor accelerated inference bridge (forward arena, FlashAttention, sieve Top-K, DML/CUDA).
181#[cfg(feature = "gpu-runtime")]
182pub mod etalon_tensor_bridge;
183#[cfg(feature = "gpu-runtime")]
184pub use etalon_tensor_bridge::{
185    build_forward_arena_on, build_fused_attention_on, build_topk_pipeline_on,
186    online_softmax_rescale, AttentionParams, CapturedCudaMegaPass, CudaMegaPassExecutor,
187    DirectMlComputeLane, DmlGemmOp, DmlGemmParams, DmlLane, ForwardArena, ForwardMode,
188    FusedAttentionPipeline, KvCacheLayout, LogitMaskHeader, PagedKvBlockTable, QuantScheme,
189    TensorView, TopkParams, TopkReductionPipeline, FUSED_ATTENTION_WGSL, TOPK_REDUCTION_WGSL,
190};
191#[cfg(all(feature = "gpu-runtime", not(target_arch = "wasm32")))]
192pub use etalon_tensor_bridge::{
193    try_shared_forward_arena, try_shared_fused_attention, try_shared_topk_pipeline,
194};