Skip to main content

Crate katgpt_types

Crate katgpt_types 

Source
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 / ThinkingBudget
  • config — the Config struct (~1.5k lines), InferenceOverrides, and kv_dim
  • rng — XorShift64 PRNG
  • math — SIMD-accelerated softmax / rmsnorm / matmul / sample_token (legacy home; candidates for relocation to katgpt-simd::)
  • lora — CPU-side LoRA adapter
  • gpart — GPart Isometric Partition adapter (Research 227)
  • domain — DomainLatent embedding (Plan 038)
  • inference — InferenceResult, TaskType, ProposerTask, DataGate
  • looping — Training-Free Loop types (Plan 136)
  • ternary — Bit-plane ternary weights (plasma_path)
  • hydra — Hydra Adaptive Layer Budget types
  • sense — 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 types because types::math calls these kernels and simd::ternary uses types::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.
DashAttnConfig
Configuration for DashAttention adaptive sparse hierarchical attention. Controls α-entmax routing, chunk summarization, and routing bias.
InferenceOverrides
Override DTO for applying per-domain inference budget to a Config.
InferenceResult
Output of a single inference pass, with reward signal for feedback loop.
LoraAdapter
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]
LoraPair
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.
ResidualGate
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.
RtTurboConfig
Configuration for RTPurbo retrieval head sparse decode.
SdpaOutputGate
Head-specific sigmoid gate after SDPA, before Wo. Zero-initialized → starts at sigmoid(0) = 0.5 (neutral multiplicative identity).
SenseModule
Fixed-size sense module: KG latent octree + ternary direction vectors. ~232 bytes. BLAKE3 committed.
ShardEmbeddingDeprecated
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.
TernaryDir
Ternary direction vector: +1/0/-1 encoded as two bitmasks + row scale. 20 bytes each (u64, u64, f32). #[repr(C)] required — embedded in SenseModule which hashes raw bytes.
TrainingFreeLoopConfig
Configuration for training-free loop wrapper (Plan 136).

Enums§

AttentionMode
Attention mode for forward passes.
AttentionProjection
Attention projection configuration. Controls whether K and V projections share weights (Q-K=V tying).
CacheLayout
KV cache layout (derived from AttentionProjection).
CacheStrategy
KV cache write strategy for the training-free loop.
CalibrationMode
Head-calibration score source (Plan 358, Research 362).
ConvergenceSelector
Selection strategy for width-scaled rollouts (EqR convergence-based selection).
DepthTier
Adaptive depth tier mapping to layer count (Plan 284). Reuses ThermalPath naming convention from FlashAR Consensus (Plan 166).
DilationConfig
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).
HybridPattern
Hybrid attention pattern for looped inference. Controls which layers use full SDPA vs linear attention.
IterationMode
Iteration mode for the training-free loop window.
LoopMode
Looped transformer mode — weight-shared layer repetition.
LoopStabilityMode
Loop stability mode for weight-shared looped inference (Plan 428).
ModelArchitecture
Model architecture selector for forward pass dispatch.
RetrievalHeadRole
Head role classification for RTPurbo sparse decode.
SenseKind
Kind of sense module for NPC brain composition.
SubStepStrategy
Sub-step integration strategy for the training-free loop.
WeightDtype
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)