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.
6#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
7pub mod inference_agent;
8#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
9pub use inference_agent as llm_agent; // transitional alias
10pub mod inference_awq;
11pub use inference_awq as llm_awq; // transitional alias
12#[cfg(not(target_arch = "wasm32"))]
13pub mod inference_bench;
14#[cfg(all(target_arch = "wasm32", feature = "wasm-llm"))]
15pub mod inference_bench_wasm;
16#[cfg(not(target_arch = "wasm32"))]
17pub mod kv_capture;
18#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
19pub mod kv_dict;
20#[cfg(not(target_arch = "wasm32"))]
21pub mod kv_dict_runtime;
22#[cfg(not(target_arch = "wasm32"))]
23pub use inference_bench as llm_bench; // transitional alias
24#[cfg(all(target_arch = "wasm32", feature = "wasm-llm"))]
25pub use inference_bench_wasm as llm_bench; // transitional alias
26pub mod inference_eval;
27pub use inference_eval as llm_eval; // transitional alias
28#[cfg(any(not(target_arch = "wasm32"), feature = "gpu-runtime"))]
29pub mod inference_gpu_profiler;
30#[cfg(any(not(target_arch = "wasm32"), feature = "gpu-runtime"))]
31pub use inference_gpu_profiler as llm_gpu_profiler; // transitional alias
32pub mod inference_kernel_parity;
33pub use inference_kernel_parity as llm_kernel_parity; // transitional alias
34pub mod agent;
35#[cfg(not(target_arch = "wasm32"))]
36pub mod ambient_orchestration;
37pub mod compute_universe;
38#[cfg(target_os = "windows")]
39pub mod directml_bridge;
40#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
41pub mod ggml_quants;
42#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
43pub mod gguf_sharder;
44#[cfg(any(target_os = "macos", target_os = "ios"))]
45pub mod metal_bridge;
46#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
47pub mod neuro_symbolic_sieve;
48#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
49pub mod orchestrator;
50#[cfg(not(target_arch = "wasm32"))]
51pub mod residency_planner;
52#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
53pub mod resident_model;
54#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
55pub mod safetensor;
56pub mod semantic_culler;
57pub mod spatial_sieve;
58#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
59pub mod tensor_roles;
60#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
61pub mod ternary;
62#[cfg(not(target_arch = "wasm32"))]
63pub mod ternary_gpu;
64/// Stage-by-stage library probe tests for the inference optim toolkit.
65#[cfg(test)]
66pub mod toolkit_probe;
67#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-llm"))]
68pub mod topk;
69// W2: exact CPU sampling chain (pure, wasm-safe — no GPU, no `rand`, no file I/O).
70pub mod sampler;
71// Multi-mode inference (portable / cuda-tc / quant-graph) — coexisting approaches.
72pub mod inference_modes;
73pub use inference_modes::{
74    active_inference_mode, apply_mode_toggles, bootstrap_inference_mode, fast_verify_html_default,
75    post_turn_verify_enabled, prefer_tensor_core_gemm, quant_graph_grounding_enabled,
76    rights_mode_enabled, sentinel_mid_decode_enabled, set_inference_mode, InferenceMode,
77};
78// Application profiles: interactive / live-fast / batch-overnight (no Ollama).
79pub mod application_profile;
80pub use application_profile::{
81    active_application_profile, apply_application_profile, bootstrap_application_profile,
82    set_application_profile, ApplicationProfile,
83};
84// Inference superiority lab (plan: inference-superiority-lab-and-toolset-plan.md).
85#[cfg(not(target_arch = "wasm32"))]
86pub mod lab;
87// Prepared native inference plan/run boundary, execution receipts, and bounded run artifacts.
88#[cfg(not(target_arch = "wasm32"))]
89pub mod runtime;
90// Post-turn verify / self-heal (FastVerify path).
91pub mod post_turn_verify;
92pub use post_turn_verify::{
93    maybe_verify_turn, return_html_as_text, verify_and_heal_turn, VerifiedTurn, VerifyCheck,
94};
95// Device-optimal path: passport benchmark → pick dx12/vulkan/metal/cuda lane + quant.
96#[cfg(not(target_arch = "wasm32"))]
97pub mod inference_path_selector;
98#[cfg(not(target_arch = "wasm32"))]
99pub use inference_path_selector::{
100    apply_inference_path_plan, bootstrap_optimal_inference_path, format_path_plan,
101    last_inference_path_plan, path_auto_enabled, resolve_inference_path_plan, run_path_select_cli,
102    ComputeLane, InferencePathPlan, QuantProfile,
103};
104// QuantGraph: selective fact grounding / repair after LLM proposal.
105pub mod quant_graph_grounding;
106pub use quant_graph_grounding::{
107    export_fact_quins, fact_count, ground_generation, load_facts_from_tsv, lookup_capital_object,
108    maybe_ground_generation, register_capital_fact, register_fact, reset_fact_store_to_defaults,
109    seed_facts_from_bundled, GroundingFact, GroundingResult, CTX_GROUNDING, P_CAPITAL_OF,
110};
111// Qualia-unique hybrid: graph route mask + fact draft + 10D query + deontic gate.
112pub mod qualia_hybrid;
113pub use qualia_hybrid::{
114    apply_graph_logit_bias, force_fact_tokens, graph_force_enabled, prepare_hybrid_decode,
115    propose_best_draft, propose_fact_draft, publish_graph_route_from_prompt,
116    publish_grounding_obligation, publish_prompt_query_tensor, GRAPH_LOGIT_BIAS,
117};
118// CUDA dense batch GEMM lane (mode=cuda); stub when feature off.
119#[cfg(all(not(target_arch = "wasm32"), feature = "cuda"))]
120pub mod cuda_lane;
121#[cfg(any(target_arch = "wasm32", not(feature = "cuda")))]
122pub mod cuda_lane_stub;
123#[cfg(all(not(target_arch = "wasm32"), feature = "cuda"))]
124pub use cuda_lane::{
125    cache_dense_weight, clear_weight_cache, dense_weight_cached, device_kv_ready,
126    ensure_device_kv_cache, preload_resident_blob, prepare_mega_pass_kernels,
127    q4k_device_weight_count, q4k_weight_resident, q8_0_gemv_oracle_into, try_cuda_batch_gemv,
128    try_cuda_batch_gemv_cached, try_cuda_batch_gemv_cached_only, try_cuda_mega_pass,
129    try_q4k_soa_attention_device, try_q4k_soa_ffn_block, try_q4k_soa_ffn_block_residual,
130    try_q4k_soa_fused_swiglu, try_q4k_soa_gemv, try_q4k_soa_qkv, try_q8_0_cuda_gemv,
131    warm_cuda_context, weight_cache_len, weight_fingerprint, MegaPassLayerDims,
132    MegaPassLayerWeights, MegaPassPlanView, MegaPassWeightLayout, MAX_DENSE_ELEMS,
133    Q8_0_BLOCK_BYTES, Q8_0_BLOCK_ELEMS,
134};
135#[cfg(any(target_arch = "wasm32", not(feature = "cuda")))]
136pub use cuda_lane_stub as cuda_lane;
137// W6a: prompt-lookup speculative decoding proposer (pure, wasm-safe).
138pub mod prompt_lookup;
139// Metal mega-pass orchestrator (Apple Silicon). Stub on non-macOS.
140pub mod metal_lane;
141// Paged KV cache: block-paged KV storage (vLLM-style). Re-exports `runtime::kv::paged`, so it
142// carries the same native-only gate as `runtime`.
143#[cfg(not(target_arch = "wasm32"))]
144pub mod paged_kv;
145#[cfg(not(target_arch = "wasm32"))]
146pub mod topk_gpu;
147// OMP sparse KV-cache decomposition builds on `crate::solvers` (dense linear
148// algebra), which is itself native-or-`wasm-scientific`; mirror that gate.
149#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-scientific"))]
150pub mod sparse_cache;
151// The thermal-eviction WAL is a file-backed `memmap2` mmap — fundamentally
152// native (no mmap'd files on wasm32).
153#[cfg(not(target_arch = "wasm32"))]
154pub mod thermal_wal;
155
156// W7: real GPU thermal/power telemetry + detect-and-recommend governor (native-only; NVML behind the
157// optional `nvml` feature). The module's own inner cfg makes it empty on wasm32.
158#[cfg(not(target_arch = "wasm32"))]
159pub mod thermal_telemetry;