Clarit.ai logoClarit.ai Home
    Back
    Clarit.ai logo
    Clarit.ai small logo
    Engram

    Engram: Technical Deep-Dive

    Engram adds persistent state infrastructure to SGLang, the high-performance LLM serving engine used across 400,000+ GPUs worldwide. It targets Mamba and Mamba2 hybrid models specifically, turning their hidden state from disposable inference overhead into a durable memory asset.

    System design

    Architecture

    ┌─────────────────────────────────────────────────┐
    │                 OpenAI-Compatible API            │
    ├─────────────────────────────────────────────────┤
    │              SGLang Serving Engine               │
    │    (scheduler, batching, tensor parallelism)     │
    ├──────────────┬──────────────────────────────────┤
    │  Engram      │  Snapshot Manager                 │
    │  Extensions  │  ├─ save / restore / list / delete│
    │              │  ├─ Conversation Tracker           │
    │              │  └─ Snapshot Hooks & Policies      │
    │              ├──────────────────────────────────┤
    │              │  Tier Manager                     │
    │              │  ├─ VRAM  (hot, ~2ms restore)     │
    │              │  ├─ RAM   (warm, ~10ms restore)   │
    │              │  └─ Disk  (cold, ~50ms restore)   │
    │              ├──────────────────────────────────┤
    │              │  Mamba State Extensions            │
    │              │  ├─ MambaRadixCache (dual LRU)    │
    │              │  ├─ HybridReqToTokenPool          │
    │              │  └─ Mamba2Metadata                │
    ├──────────────┴──────────────────────────────────┤
    │              Mamba / Mamba2 Models                │
    │    (pure SSM, dense hybrid, MoE hybrid)          │
    └─────────────────────────────────────────────────┘
    Components

    Core components

    MambaRadixCache

    A dual-LRU cache system that manages Mamba pool slots with automatic eviction when memory fills up. Supports copy-on-write semantics and tombstone nodes for safe concurrent access.

    Snapshot Tiering (WARM + COLD)

    WARM tier (host RAM): Auto-snapshot captures full final state via pre-free hook before memory release. COLD tier (disk): safetensors + JSON metadata per turn, supports startup preload.

    Stateful Generate Pipeline

    Modified scheduler creates synthetic requests for continued conversations, bypassing normal tokenization.

    Per-Request Correlation

    Futures-based system ensuring concurrent requests don't get mixed responses.

    HybridReqToTokenPool

    Unified pool managing both attention KV slots and Mamba SSM state slots per request.

    Validation

    Benchmark results

    Validated on H200 across the full test suite (77/82 pass, 0 regressions):

    MetricResult
    Token reduction93.8% average across 271 requests, zero failures
    Snapshot restore~2 ms warm restore (vs. 6.5 s full prefill at 128K context)
    Speedup at 128K~3,250× faster than full prefill
    Snapshot sizeConstant per model, regardless of context length
    Memory stabilityZero leaks, stable VRAM under sustained load
    Storage

    Snapshot sizes by model

    ModelParamsSnapshotNotes
    Nemotron-Cascade-2-30B30B~47 MBSmallest — MoE routing, fewer Mamba layers
    Granite 4.0-H-tiny4B~56 MBPrimary benchmark model
    Granite 4.0-H-small32B~146 MB36 Mamba layers, BF16
    Nemotron-3-Super-120B120B~5.3 GB88 layers, FP8, LatentMoE
    Qwen3-Coder-Next~75B~23.7 GBGLA recurrent state (not Mamba2)

    All sizes constant regardless of conversation length.

    Quality

    Test program summary

    11 phases, 5 model architectures, 150+ requests per model.

    PhaseDescriptionResult
    0Environment verificationPASS (10/12)
    1Stateless inference baselinePASS (7/7)
    2MambaPool unit testsPASS (5/5)
    3MambaRadixCache gauntletPASS (16/16)
    4Live server, no_buffer strategyPASS (5/5)
    5Mamba2Metadata integrityPASS (5/5)
    6extra_buffer strategyPARTIAL
    7Snapshot system E2EPASS (6/6)
    8True stateful inferencePASS — 93.8% savings
    9Gauntlet stress testsPASS — 271 req, 0 err
    10Cross-model scalingPASS (5 models)
    Integration

    API extensions

    Engram extends SGLang's API with snapshot management endpoints. All existing SGLang endpoints work unchanged.

    EndpointMethodDescription
    /save_snapshotPOSTSave current conversation state
    /restore_snapshotPOSTRestore a previously saved state
    /list_snapshotsGETList all saved snapshots
    /delete_snapshotDELETERemove a saved snapshot

    Server flags

    FlagDescription
    --enable-snapshot-persistenceEnable the snapshot system
    --snapshot-dir <path>Directory for snapshot storage
    --mamba-scheduler-strategyScheduler strategy (no_buffer, extra_buffer)

    Related: Synapse

    Synapse is a companion project under the Clarit.ai umbrella — an edge/mobile optimized inference engine based on llama.cpp. While Engram focuses on stateful serving for Mamba architectures on GPU infrastructure, Synapse targets constrained devices where power, bandwidth, and memory are limited. More details coming soon.

    Explore the code

    Engram is open source. Dive into the implementation, run the test suite, or contribute.

    ← Back to home
    Architecture overview →
    GitHub