Expand description
katgpt-types — Shared configuration, RNG, math utilities, SIMD kernels, and inference types for the katgpt-rs / riir-engine superset.
Pure substrate leaf crate. No katgpt-* dependencies — only fastrand,
blake3, serde, half. This is the foundational layer (types + SIMD
kernels) that every other katgpt-* crate (and riir-engine) builds on.
The types and simd modules are co-located because types::math
calls simd kernels (softmax / rmsnorm / matmul) and simd::ternary
uses types::TernaryWeights — they form a tight bidirectional leaf that
cannot be split further without breaking the cycle.
Originally a single 5,148-line types.rs inside katgpt-core (2.5× the
2048-line ceiling), split into topic-specific submodules. The full public
surface is re-exported here so consumers can use katgpt_types::* paths
directly.
Spun out of katgpt-core::types (Issue 007 Phase E Tier 1 #2) as a
standalone publishable crate mirroring the katgpt-dec / katgpt-transformer
template.
§Module layout
enums— small config enums (DepthTier, HlaMode, AttentionMode, …) plus WallConfig / ThinkingBudgetconfig— theConfigstruct (~1.5k lines),InferenceOverrides, andkv_dimrng— XorShift64 PRNGmath— SIMD-accelerated softmax / rmsnorm / matmul / sample_token (legacy home; candidates for relocation tokatgpt-simd::)lora— CPU-side LoRA adaptergpart— GPart Isometric Partition adapter (Research 227)domain— DomainLatent embedding (Plan 038)inference— InferenceResult, TaskType, ProposerTask, DataGatelooping— Training-Free Loop types (Plan 136)ternary— Bit-plane ternary weights (plasma_path)hydra— Hydra Adaptive Layer Budget typessense— ShardEmbedding (DEPRECATED, Issue 139) + sense composition types
Test modules live alongside their topic (e.g. rng::tests_rng) or in
tests_types.rs for cross-cutting tests.
Re-exports§
pub use kv_cache::QuantizedKVCache;pub use leaky_core::leaky_step;pub use math::sample_token;Deprecated pub use math::gegelu;pub use math::gegelu_tanh;pub use math::matmul;pub use math::matmul_f16;pub use math::matmul_f16_f16;pub use math::matmul_f16_f16_parallel;pub use math::matmul_f16_parallel;pub use math::matmul_parallel;pub use math::matmul_relu;pub use math::rmsnorm;pub use math::rmsnorm_with_gamma;pub use math::rmsnorm_with_gamma_eps;pub use math::sample_token_into;pub use math::silu;pub use math::softmax;pub use math::softmax_scaled;pub use math::swiglu;pub use math::swiglu_inplace;pub use merkle::HASH_SIZE;pub use merkle::MERKLE_OCTREE_BRANCHING;pub use merkle::MERKLE_OCTREE_DEPTH;pub use merkle::MERKLE_OCTREE_INTERNAL;pub use merkle::MERKLE_OCTREE_LEAVES;pub use merkle::MERKLE_OCTREE_NODES;pub use merkle::MerkleOctree;pub use merkle::MerkleProof;pub use slod::ScaleBoundary;pub use temporal::TemporalDerivativeKernel;pub use temporal::sigmoid_surprise_gate;
Modules§
- kv_
cache - QuantizedKVCache trait — shared extension point for all KV backends.
Promoted from
katgpt-rs/src/types.rs(Issue 015 Phase 1) so backend crates can depend on the trait without pulling the whole root crate. Quantized KV cache trait — shared extension point for all backends. - leaky_
core - Shared leaky-integrator / delta-rule step primitive (Plan 276 Phase 2 T2.1).
Pure inline math, zero deps. Consumed by both katgpt-micro-belief
(
LeakyIntegrator::step) and katgpt-core’s sense reconstruction (ReconstructionState::evolve_belief). Co-located here (the leaf) so both consumers can share the single source of truth without a cycle. Shared leaky-integrator / delta-rule step primitive (Plan 276 Phase 2, T2.1). - math
- SIMD-accelerated math primitives.
- merkle
- Merkle octree — hierarchical BLAKE3 commitment for KG latent octree nodes.
- simd
- SIMD-accelerated linear algebra kernels (NEON / AVX2 / WASM-SIMD128 /
scalar fallback). Co-located with
typesbecausetypes::mathcalls these kernels andsimd::ternaryusestypes::TernaryWeights. SIMD-accelerated linear algebra kernels for inference. - slod
- SLoD scale-boundary POD type — shared between katgpt-core’s SLoD operator (Plan 235) and katgpt-sense’s LOD router. Pure data, zero deps.
- temporal
- Temporal Derivative Kernel — Dual Fast/Slow Surprise Signal (Plan 277).
Structs§
- Config
- Transformer model configuration — superset of both katgpt-rs and riir-engine.
- Dash
Attn Config - Configuration for DashAttention adaptive sparse hierarchical attention. Controls α-entmax routing, chunk summarization, and routing bias.
- Inference
Overrides - Override DTO for applying per-domain inference budget to a
Config. - Inference
Result - Output of a single inference pass, with reward signal for feedback loop.
- Lora
Adapter - CPU-side LoRA adapter for inference.
Loads from the same binary format as
GpuLoraAdapter(Plan 008):[LORA(4) | version(4) | blake3(32) | payload...]where payload =[n_adapters(4) | rank(4) | alpha(4) | adapter_data...]and adapter_data =[in_dim(4) | out_dim(4) | a_f32s | b_f32s] - Lora
Pair - A loaded LoRA pair for modality-specific inference (Plan 025). Reader is active during bidirectional prefill, writer during causal decode. Switching is a reference swap — zero data movement.
- Residual
Gate - Per-loop residual scaling gate. h^(τ) = h̃^(τ) + ρ_τ ⊙ h^(τ-1) Zero-init so first iteration is h̃^(1) (no residual from “previous”).
- Rng
- XorShift64 PRNG — deterministic per seed.
- RtTurbo
Config - Configuration for RTPurbo retrieval head sparse decode.
- Sdpa
Output Gate - Head-specific sigmoid gate after SDPA, before Wo. Zero-initialized → starts at sigmoid(0) = 0.5 (neutral multiplicative identity).
- Sense
Module - Fixed-size sense module: KG latent octree + ternary direction vectors. ~232 bytes. BLAKE3 committed.
- Shard
Embedding Deprecated - Low-dimensional projection of NeuronShard style_weights for fast similarity search. Produced by Johnson-Lindenstrauss random orthogonal projection. 8 × f32 = 32 bytes — fits in cache line, suitable for SIMD cosine similarity.
- Ternary
Dir - Ternary direction vector: +1/0/-1 encoded as two bitmasks + row scale.
20 bytes each (u64, u64, f32).
#[repr(C)]required — embedded inSenseModulewhich hashes raw bytes. - Training
Free Loop Config - Configuration for training-free loop wrapper (Plan 136).
Enums§
- Attention
Mode - Attention mode for forward passes.
- Attention
Projection - Attention projection configuration. Controls whether K and V projections share weights (Q-K=V tying).
- Cache
Layout - KV cache layout (derived from AttentionProjection).
- Cache
Strategy - KV cache write strategy for the training-free loop.
- Calibration
Mode - Head-calibration score source (Plan 358, Research 362).
- Convergence
Selector - Selection strategy for width-scaled rollouts (EqR convergence-based selection).
- Depth
Tier - Adaptive depth tier mapping to layer count (Plan 284). Reuses ThermalPath naming convention from FlashAR Consensus (Plan 166).
- Dilation
Config - Dilation configuration for RAT+ bridge sparse attention. Controls stride D for KV cache access during decode.
- HlaMode
- Attention mode for HLA (Higher-order Linear Attention).
- Hybrid
Pattern - Hybrid attention pattern for looped inference. Controls which layers use full SDPA vs linear attention.
- Iteration
Mode - Iteration mode for the training-free loop window.
- Loop
Mode - Looped transformer mode — weight-shared layer repetition.
- Loop
Stability Mode - Loop stability mode for weight-shared looped inference (Plan 428).
- Model
Architecture - Model architecture selector for forward pass dispatch.
- Retrieval
Head Role - Head role classification for RTPurbo sparse decode.
- Sense
Kind - Kind of sense module for NPC brain composition.
- SubStep
Strategy - Sub-step integration strategy for the training-free loop.
- Weight
Dtype - Weight storage dtype (affects loading and dequantization).
Functions§
- kv_dim
- KV dimension: total float count per token in KV cache.
- lora_
apply - Apply LoRA delta in-place:
output += (alpha/rank) × B @ (A @ input)