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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Cognexis
|
| 2 |
+
|
| 3 |
+
**A Compute-Adaptive Recurrent-Depth Large Language Model**
|
| 4 |
+
|
| 5 |
+
Cognexis is a decoder-only language model architecture that separates *reasoning depth* from *parameter count*. Instead of scaling depth exclusively by stacking more transformer layers, Cognexis reuses a shared recurrent transformer block for a configurable number of iterations at inference time. The same checkpoint serves requests at different quality, latency, and compute budgets β making loop count a runtime control knob rather than a fixed architectural constant.
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## Table of Contents
|
| 10 |
+
|
| 11 |
+
1. [Core Idea](#core-idea)
|
| 12 |
+
2. [Architecture](#architecture)
|
| 13 |
+
3. [Loop Modes](#loop-modes)
|
| 14 |
+
4. [Model Configurations](#model-configurations)
|
| 15 |
+
5. [Evaluation Metrics](#evaluation-metrics)
|
| 16 |
+
6. [Quick Start](#quick-start)
|
| 17 |
+
7. [Project Structure](#project-structure)
|
| 18 |
+
8. [Specification](#specification)
|
| 19 |
+
9. [Safety and Observability](#safety-and-observability)
|
| 20 |
+
10. [Known Limitations](#known-limitations)
|
| 21 |
+
11. [License](#license)
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## Core Idea
|
| 26 |
+
|
| 27 |
+
In a standard transformer, reasoning depth is hard-coupled to parameter count β deeper models need more unique weights. Cognexis decouples these by routing every sequence through:
|
| 28 |
+
|
| 29 |
+
1. A **Prelude** of conventional transformer blocks (unique parameters).
|
| 30 |
+
2. A **shared recurrent core** applied *N* times (one shared parameter set, reused across all *N* iterations).
|
| 31 |
+
3. A **Coda** of conventional transformer blocks (unique parameters).
|
| 32 |
+
|
| 33 |
+
```
|
| 34 |
+
input_text
|
| 35 |
+
-> tokenizer.encode
|
| 36 |
+
-> token_ids
|
| 37 |
+
-> embedding(token_ids)
|
| 38 |
+
-> prelude(hidden) # unique params, runs once
|
| 39 |
+
-> recurrent_core(hidden) # shared params, runs N times
|
| 40 |
+
-> coda(hidden) # unique params, runs once
|
| 41 |
+
-> lm_head(hidden)
|
| 42 |
+
-> logits
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
The **effective depth** is:
|
| 46 |
+
|
| 47 |
+
```
|
| 48 |
+
effective_depth = num_prelude_blocks + N * num_recurrent_blocks + num_coda_blocks
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Increasing `N` deepens the computation without adding new parameters. The compute-adaptive scheduler can then decide *at runtime* how much depth each request actually needs.
|
| 52 |
+
|
| 53 |
+
---
|
| 54 |
+
|
| 55 |
+
## Architecture
|
| 56 |
+
|
| 57 |
+
Cognexis follows a five-stage pipeline. Each stage is a separate, testable module.
|
| 58 |
+
|
| 59 |
+
### Tokenizer
|
| 60 |
+
|
| 61 |
+
Converts raw text into token IDs using a subword tokenizer (SentencePiece Unigram by default). The tokenizer is part of the model contract β it is bundled with every checkpoint and validated by checksum. Required special tokens: `BOS`, `EOS`, `PAD`, `UNK`, `EOD`. Instruction-tuned deployments add role markers: `<|system|>`, `<|user|>`, `<|assistant|>`, `<|tool|>`, `<|end|>`.
|
| 62 |
+
|
| 63 |
+
### Embedding
|
| 64 |
+
|
| 65 |
+
Maps token IDs to dense vectors of size `hidden_dim`. Uses **rotary positional encoding (RoPE)** applied inside attention, not learned absolute positions. Embedding weights are **weight-tied** with the LM head by default, reducing parameter count and keeping input/output token representations aligned.
|
| 66 |
+
|
| 67 |
+
### Prelude
|
| 68 |
+
|
| 69 |
+
A stack of conventional transformer blocks with unique parameters. It builds stable, contextual token representations before recurrence begins. Without a capable Prelude, the recurrent core would need to simultaneously handle early lexical processing and deep iterative refinement, increasing instability and weakening depth generalization.
|
| 70 |
+
|
| 71 |
+
### Recurrent Core
|
| 72 |
+
|
| 73 |
+
The defining Cognexis component: **one shared transformer block** applied repeatedly. Each iteration refines the hidden state under the same causal mask. Shared parameters mean:
|
| 74 |
+
|
| 75 |
+
- Gradients accumulate from all loop unrolls into the same weights.
|
| 76 |
+
- Checkpoints store exactly one recurrent block β never one copy per loop.
|
| 77 |
+
- Stability controls (residual scaling, gating, spectral monitoring) are required.
|
| 78 |
+
|
| 79 |
+
Optional input injection anchors recurrence to the original Prelude output `h0`, preventing drift toward generic fixed points at high loop counts.
|
| 80 |
+
|
| 81 |
+
### Coda
|
| 82 |
+
|
| 83 |
+
A final stack of conventional transformer blocks with unique parameters. Integrates the refined recurrent state, performs cross-token mixing, and prepares representations for the LM head. If `num_coda_blocks = 0`, recurrent output flows directly to final norm and logits β valid but quality-affecting.
|
| 84 |
+
|
| 85 |
+
### LM Head
|
| 86 |
+
|
| 87 |
+
Linear projection from hidden states to vocabulary logits. Weight-tied to the token embedding by default. Loss is standard next-token cross-entropy, with masking for PAD tokens, non-assistant prompt tokens in SFT, and packed-document boundaries.
|
| 88 |
+
|
| 89 |
+
---
|
| 90 |
+
|
| 91 |
+
## Loop Modes
|
| 92 |
+
|
| 93 |
+
Cognexis supports three loop execution modes, selectable at request time:
|
| 94 |
+
|
| 95 |
+
| Mode | Description |
|
| 96 |
+
|------|-------------|
|
| 97 |
+
| `fixed` | Every sequence runs the configured loop count. Baseline for training, debugging, and deterministic production. |
|
| 98 |
+
| `adaptive_sequence` | A scheduler decides when to halt for the whole sequence. Simpler execution model than token-wise. |
|
| 99 |
+
| `adaptive_token` | Each token position may halt independently while others continue. More compute-efficient for heterogeneous sequences; more complex cache/masking implementation. |
|
| 100 |
+
|
| 101 |
+
All modes enforce hard bounds: the scheduler may stop early, but **never exceeds `max_loops`** or the request compute budget.
|
| 102 |
+
|
| 103 |
+
### Scheduler Modes
|
| 104 |
+
|
| 105 |
+
The adaptive scheduler can be:
|
| 106 |
+
|
| 107 |
+
- **rule-based** β halts using thresholds on hidden-state delta, confidence, entropy, or budgets.
|
| 108 |
+
- **value-head** β halts using a small learned head predicting marginal improvement per loop.
|
| 109 |
+
- **hybrid** β combines rule-based hard stops with value-head gain-per-cost predictions.
|
| 110 |
+
- **oracle** β research-only; uses unavailable future information for analysis only.
|
| 111 |
+
|
| 112 |
+
**Recommended for production:** conservative `hybrid` with hard bounds and `min_loops` enforced before any halt decision.
|
| 113 |
+
|
| 114 |
+
---
|
| 115 |
+
|
| 116 |
+
## Model Configurations
|
| 117 |
+
|
| 118 |
+
| Model | Hidden Size | Attention Heads | Prelude Blocks | Recurrent Blocks | Coda Blocks | Max Loops (train) | Parameters |
|
| 119 |
+
|-------|------------|----------------|---------------|-----------------|-------------|-------------------|-----------|
|
| 120 |
+
| Cognexis-8B | 4096 | 32 | 8 | 1 | 8 | 12 | ~8 B |
|
| 121 |
+
| Cognexis-64B | 8192 | 64 | 10 | 1 | 10 | 16 | ~64 B |
|
| 122 |
+
| Cognexis-256B | 12288 | 96 | 12 | 1 | 12 | 20 | ~256 B |
|
| 123 |
+
| Cognexis-1.28T | 16384 | 128 | 16 | 1 | 16 | 24 | ~1.28 T |
|
| 124 |
+
|
| 125 |
+
The recurrent core always uses a single shared block. Larger models increase `hidden_dim`, head counts, block counts, and training loop budgets. Effective depth is tunable at inference independently of parameter count.
|
| 126 |
+
|
| 127 |
+
---
|
| 128 |
+
|
| 129 |
+
## Evaluation Metrics
|
| 130 |
+
|
| 131 |
+
Cognexis evaluation reports both **quality** and **compute** together.
|
| 132 |
+
|
| 133 |
+
### Quality Metrics
|
| 134 |
+
|
| 135 |
+
- Perplexity and negative log-likelihood
|
| 136 |
+
- Exact match and multiple-choice accuracy
|
| 137 |
+
- Pass@k for code generation
|
| 138 |
+
- Task-specific generation metrics (BLEU, ROUGE, rubric scores)
|
| 139 |
+
|
| 140 |
+
### Compute Metrics
|
| 141 |
+
|
| 142 |
+
- Loops executed per request (mean, median, p90, p99)
|
| 143 |
+
- Prefill and decode latency
|
| 144 |
+
- Approximate FLOPs by stage
|
| 145 |
+
- Peak memory and KV cache memory
|
| 146 |
+
- Scheduler overhead
|
| 147 |
+
|
| 148 |
+
### Depth-Aware Metrics
|
| 149 |
+
|
| 150 |
+
| Metric | Formula | Interpretation |
|
| 151 |
+
|--------|---------|----------------|
|
| 152 |
+
| **DEI** (Depth Efficiency Index) | `(M(Nβ) - M(Nβ)) / (C(Nβ) - C(Nβ))` | Quality gain per extra unit of compute. Higher = better returns from additional loops. |
|
| 153 |
+
| **LSP** (Loop Saturation Point) | `argmax_N DEI(N)` | Depth where marginal returns peak. Preferred default loop budget. |
|
| 154 |
+
| **OT** (Overthinking Threshold) | `min { d : M(d+1) < M(d) - tolerance }` | First depth where extra loops harm quality. Scheduler must stop before this. |
|
| 155 |
+
| **DGR** (Depth Gain Ratio) | `(M(N_max) - M(N_min)) / |M(N_min)|` | Total improvement from shallow to maximum depth. |
|
| 156 |
+
|
| 157 |
+
DEI, LSP, OT, and DGR are task-dependent β different tasks saturate and overthink at different depths.
|
| 158 |
+
|
| 159 |
+
---
|
| 160 |
+
|
| 161 |
+
## Quick Start
|
| 162 |
+
|
| 163 |
+
### Tokenize
|
| 164 |
+
|
| 165 |
+
```rust
|
| 166 |
+
use cognexis::tokenizer::Tokenizer;
|
| 167 |
+
|
| 168 |
+
let tokenizer = Tokenizer::from_artifact("tokenizer.json")?;
|
| 169 |
+
let ids = tokenizer.encode("The recurrent core", EncodeOptions::default())?;
|
| 170 |
+
let text = tokenizer.decode(&ids, DecodeOptions::default())?;
|
| 171 |
+
```
|
| 172 |
+
|
| 173 |
+
### Generate (Fixed Loop Mode)
|
| 174 |
+
|
| 175 |
+
```rust
|
| 176 |
+
use cognexis::{CognexisModel, GenerationRequest, LoopMode, SamplingOptions};
|
| 177 |
+
|
| 178 |
+
let model = CognexisModel::from_checkpoint("checkpoint/", &ServeConfig::load("serve.yaml")?)?;
|
| 179 |
+
|
| 180 |
+
let request = GenerationRequest {
|
| 181 |
+
input_ids: tokenizer.encode("Explain transformers", EncodeOptions::default())?,
|
| 182 |
+
max_new_tokens: 128,
|
| 183 |
+
loop_options: LoopOptions {
|
| 184 |
+
mode: LoopMode::Fixed(8),
|
| 185 |
+
..Default::default()
|
| 186 |
+
},
|
| 187 |
+
sampling: SamplingOptions::default()
|
| 188 |
+
.with_temperature(0.7)
|
| 189 |
+
.with_top_p(0.9),
|
| 190 |
+
};
|
| 191 |
+
|
| 192 |
+
for event in model.generate_streaming(request)? {
|
| 193 |
+
println!("{}", event.text_delta);
|
| 194 |
+
}
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
### Generate (Adaptive Loop Mode)
|
| 198 |
+
|
| 199 |
+
```rust
|
| 200 |
+
let request = GenerationRequest {
|
| 201 |
+
input_ids: ids,
|
| 202 |
+
max_new_tokens: 128,
|
| 203 |
+
loop_options: LoopOptions {
|
| 204 |
+
mode: LoopMode::Adaptive {
|
| 205 |
+
min_loops: 2,
|
| 206 |
+
max_loops: 16,
|
| 207 |
+
},
|
| 208 |
+
..Default::default()
|
| 209 |
+
},
|
| 210 |
+
sampling: SamplingOptions::default(),
|
| 211 |
+
};
|
| 212 |
+
// Scheduler halts when confidence is high and predicted marginal gain is low.
|
| 213 |
+
```
|
| 214 |
+
|
| 215 |
+
### Training
|
| 216 |
+
|
| 217 |
+
```bash
|
| 218 |
+
cognexis train --config configs/train.yaml
|
| 219 |
+
```
|
| 220 |
+
|
| 221 |
+
### Evaluation
|
| 222 |
+
|
| 223 |
+
```bash
|
| 224 |
+
cognexis eval --config configs/eval.yaml --checkpoint checkpoint/
|
| 225 |
+
|
| 226 |
+
# Loop scaling study
|
| 227 |
+
cognexis eval loop-scaling --config configs/eval.yaml --depths 1,2,4,8,12
|
| 228 |
+
```
|
| 229 |
+
|
| 230 |
+
---
|
| 231 |
+
|
| 232 |
+
## Project Structure
|
| 233 |
+
|
| 234 |
+
```
|
| 235 |
+
cognexis/
|
| 236 |
+
βββ cognexis-spec/ # Full engineering specification (28 documents)
|
| 237 |
+
β βββ spec01_overview.md
|
| 238 |
+
β βββ spec02_tokenizer.md
|
| 239 |
+
β βββ spec03_embedding.md
|
| 240 |
+
β βββ spec04_attention.md
|
| 241 |
+
β βββ spec05_feedforward.md
|
| 242 |
+
β βββ spec06_transformer_block.md
|
| 243 |
+
β βββ spec07_prelude.md
|
| 244 |
+
β βββ spec08_recurrent_core.md
|
| 245 |
+
β βββ spec09_coda.md
|
| 246 |
+
β βββ spec10_lm_head.md
|
| 247 |
+
β βββ spec11_config.md
|
| 248 |
+
β βββ spec12_data_loading.md
|
| 249 |
+
β βββ spec13_curriculum.md
|
| 250 |
+
β βββ spec14_distributed_training.md
|
| 251 |
+
β βββ spec15_stability_normalization.md
|
| 252 |
+
β βββ spec16_prefill_decode.md
|
| 253 |
+
β βββ spec17_scheduler_design.md
|
| 254 |
+
β βββ spec18_tokenwise_scheduling.md
|
| 255 |
+
β βββ spec19_value_head.md
|
| 256 |
+
β βββ spec20_evaluation_metrics.md
|
| 257 |
+
β βββ spec21_loop_scaling.md
|
| 258 |
+
β βββ spec22_ablation.md
|
| 259 |
+
β βββ spec23_instruction_tuning.md
|
| 260 |
+
β βββ spec24_safety_monitoring.md
|
| 261 |
+
β βββ spec25_glossary.md
|
| 262 |
+
β βββ spec26_implementation_outline.md
|
| 263 |
+
β βββ spec27_limitations_future.md
|
| 264 |
+
β βββ spec28_conclusion.md
|
| 265 |
+
β βββ cognexis_white_paper.md # High-level narrative
|
| 266 |
+
β βββ white_paper_references.md
|
| 267 |
+
β
|
| 268 |
+
βββ cognexis/ # Rust implementation
|
| 269 |
+
βββ Cargo.toml
|
| 270 |
+
βββ src/
|
| 271 |
+
tokenizer.rs # Subword encoding/decoding, special tokens, chat templates
|
| 272 |
+
embedding.rs # Token embeddings, RoPE position IDs
|
| 273 |
+
attention.rs # MHA, GQA, MQA, sliding-window, KV cache
|
| 274 |
+
feedforward.rs # SwiGLU, GeGLU, GELU, ReLU MLPs
|
| 275 |
+
transformer_block.rs# Pre-norm composition, residual scaling, gating
|
| 276 |
+
prelude.rs # Prelude stage (multiple unique blocks)
|
| 277 |
+
recurrent_core.rs # Shared recurrent block, input injection, loop execution
|
| 278 |
+
coda.rs # Coda stage (multiple unique blocks)
|
| 279 |
+
lm_head.rs # Vocabulary projection, weight tying, cross-entropy loss
|
| 280 |
+
stability.rs # RMSNorm, LayerNorm, residual scaling, spectral monitoring
|
| 281 |
+
scheduler.rs # Fixed, rule-based, value-head, hybrid schedulers
|
| 282 |
+
tokenwise.rs # Token-wise loop allocation and active masking
|
| 283 |
+
value_head.rs # Learned gain predictor for adaptive scheduling
|
| 284 |
+
prefill_decode.rs # Autoregressive inference: prefill, decode, cache management
|
| 285 |
+
config.rs # Typed YAML/JSON config with validation
|
| 286 |
+
data_loading.rs # Sharded dataset streaming, document packing, shuffling
|
| 287 |
+
curriculum.rs # Loop curriculum: warm-up, depth ramp, sampling distributions
|
| 288 |
+
distributed_training.rs # FSDP, tensor parallelism, pipeline staging
|
| 289 |
+
evaluation.rs # Evaluation harness, task traits, metric computation
|
| 290 |
+
loop_scaling.rs # Loop scaling experiment runner
|
| 291 |
+
ablation.rs # Ablation study framework and config management
|
| 292 |
+
instruction_tuning.rs # SFT data formats, chat templates, assistant-only loss masking
|
| 293 |
+
safety.rs # Input/output filtering, policy enforcement, compute budgets
|
| 294 |
+
lib.rs # Top-level exports and public API
|
| 295 |
+
attention.rs # Attention variants
|
| 296 |
+
feedforward.rs # FFN activations
|
| 297 |
+
stability.rs # Normalization
|
| 298 |
+
tokenizer.rs # Tokenization
|
| 299 |
+
config.rs # Configuration
|
| 300 |
+
prefill_decode.rs # Inference
|
| 301 |
+
scheduler.rs # Scheduling
|
| 302 |
+
data_loading.rs # Data loading
|
| 303 |
+
curriculum.rs # Loop curriculum
|
| 304 |
+
distributed_training.rs # Distributed training
|
| 305 |
+
evaluation.rs # Evaluation
|
| 306 |
+
loop_scaling.rs # Loop scaling
|
| 307 |
+
ablation.rs # Ablations
|
| 308 |
+
instruction_tuning.rs # Instruction tuning
|
| 309 |
+
safety.rs # Safety
|
| 310 |
+
transformer_block.rs
|
| 311 |
+
embedding.rs
|
| 312 |
+
prelude.rs
|
| 313 |
+
recurrent_core.rs
|
| 314 |
+
coda.rs
|
| 315 |
+
lm_head.rs
|
| 316 |
+
tokenwise.rs
|
| 317 |
+
value_head.rs
|
| 318 |
+
lib.rs
|
| 319 |
+
```
|
| 320 |
+
|
| 321 |
+
---
|
| 322 |
+
|
| 323 |
+
## Specification
|
| 324 |
+
|
| 325 |
+
The `cognexis-spec/` directory contains the complete engineering specification for Cognexis, written as 28 focused documents. It is the authoritative implementation contract β all conforming implementations must satisfy the requirements documented there.
|
| 326 |
+
|
| 327 |
+
Documents are divided into five groups:
|
| 328 |
+
|
| 329 |
+
| Group | Documents | Coverage |
|
| 330 |
+
|-------|-----------|----------|
|
| 331 |
+
| Core Components | spec01βspec10 | Tokenizer, embedding, attention, FFN, transformer block, Prelude, recurrent core, Coda, LM head |
|
| 332 |
+
| System Stack | spec11βspec16 | Configuration, data loading, curriculum, distributed training, stability/normalization, prefill/decode |
|
| 333 |
+
| Scheduling | spec17βspec19 | Adaptive scheduler design, token-wise allocation, value head |
|
| 334 |
+
| Evaluation & Ops | spec20βspec24 | Evaluation metrics/protocols, loop scaling, ablation, instruction tuning, safety/monitoring |
|
| 335 |
+
| Project | spec25βspec28 | Glossary, implementation outline, limitations/future work, conclusion |
|
| 336 |
+
|
| 337 |
+
Key invariants every implementation must preserve:
|
| 338 |
+
|
| 339 |
+
- Token IDs are identical between training and inference for the same tokenizer and normalization settings.
|
| 340 |
+
- Recurrent core weights are shared across all loop iterations (one checkpoint tensor, not N copies).
|
| 341 |
+
- Causal masking is enforced in every attention path at every loop.
|
| 342 |
+
- `min_loops` and `max_loops` are enforced as hard bounds regardless of scheduler mode.
|
| 343 |
+
- Evaluation reports quality and compute together; quality alone is incomplete.
|
| 344 |
+
- Safety policies wrap generation regardless of loop mode.
|
| 345 |
+
|
| 346 |
+
---
|
| 347 |
+
|
| 348 |
+
## Safety and Observability
|
| 349 |
+
|
| 350 |
+
**Cognexis inherits all standard LLM safety concerns and adds recurrent-specific risks.**
|
| 351 |
+
|
| 352 |
+
### Required Safety Controls
|
| 353 |
+
|
| 354 |
+
- Input policy checks and prompt injection detection before prefill.
|
| 355 |
+
- Output policy checks after generation.
|
| 356 |
+
- Special-token injection prevention.
|
| 357 |
+
- Hard compute budget limits: max prompt tokens, max generated tokens, max loops, wall-clock timeout.
|
| 358 |
+
- Safety risk signals in scheduler halt decisions.
|
| 359 |
+
- Safety metrics measured across loop counts (depth can affect refusal accuracy).
|
| 360 |
+
|
| 361 |
+
### Required Observability
|
| 362 |
+
|
| 363 |
+
Structured logs must include (without raw prompt/output text by default):
|
| 364 |
+
|
| 365 |
+
- Request ID, checkpoint ID, tokenizer checksum.
|
| 366 |
+
- Prompt and generation token counts.
|
| 367 |
+
- Loop mode, loop count distribution, halt reasons.
|
| 368 |
+
- Prefill and decode latency.
|
| 369 |
+
- Safety filter actions, error/stop reason.
|
| 370 |
+
|
| 371 |
+
Exposed metrics: requests/sec, tokens/sec, mean loops, loop histogram, halt reason counts, refusal rate, budget exhaustion rate, non-finite activation count, error rate by category.
|
| 372 |
+
|
| 373 |
+
Tracing spans: tokenization, prefill, each recurrent loop, scheduler observation, Coda, LM head, sampling, safety filtering, streaming emission.
|
| 374 |
+
|
| 375 |
+
---
|
| 376 |
+
|
| 377 |
+
## Known Limitations
|
| 378 |
+
|
| 379 |
+
See `cognexis-spec/spec27_limitations_future.md` for the full list. Key items:
|
| 380 |
+
|
| 381 |
+
- **Stability at high loop counts.** Repeated application can explode norms, collapse to uninformative fixed points, or oscillate. Requires residual scaling, gating, spectral monitoring, and gradient clipping.
|
| 382 |
+
- **Latency variability.** Adaptive scheduling produces variable response times, which complicates SLA-driven serving.
|
| 383 |
+
- **Scheduler generalization.** Learned schedulers may halt incorrectly on out-of-distribution prompts. Conservative fallback policies are required.
|
| 384 |
+
- **Overthinking.** Quality can degrade beyond a threshold depth. The Overthinking Threshold varies by task and must be measured empirically.
|
| 385 |
+
- **KV cache subtlety.** Recurrent hidden states change with loop index, making cache reuse more error-prone than standard transformers. Correctness-first recomputation may be necessary.
|
| 386 |
+
- **Token-wise efficiency.** Masked dense token-wise execution is simple and correct but saves little compute. Hardware-appropriate sparse kernels are future work.
|
| 387 |
+
- **Training complexity.** Loop curricula, recurrent gradient handling, and scheduler training add overhead not present in standard decoder-only training.
|
| 388 |
+
|
| 389 |
+
Cognexis does not make deeper reasoning free. It makes compute cost *explicit, measurable, and controllable*. Implementations must preserve stability, report depth efficiency honestly, and enforce runtime budgets and safety policies.
|
| 390 |
+
|
| 391 |
+
---
|
| 392 |
+
|
| 393 |
+
## License
|
| 394 |
+
|
| 395 |
+
See `LICENSE` file.
|
| 396 |
+
---
|
| 397 |
+
license: other
|
| 398 |
+
license_name: dosl-iie-1.0
|
| 399 |
+
license_link: LICENSE
|
| 400 |
+
---
|