Open source / PyPI 0.1.0 / vLLM · SGLang · Diffusers · NVIDIA Cosmos

Compile a 57.1%-depth circuit breaker in minutes. Block silent failures before decode.

Across autoregressive tool agents, 3D video generators, and action-conditioned robot world models, unfaithful tool shortcuts and sycophantic physics hallucinations crystallize inside the residual stream near 57.1% network depth long before external LLM compliance auditors, 3D-VAE pixel critics, or built-in value heads notice anything wrong. latchgate unifies the mechanistic control trilogy (Agentic Sabotage, Sparse Temporal Latching, and Sycophantic World Models) into a single MIT-licensed compiler and runtime that turns 50 to 200 paired counterfactual traces into portable, pickle-free .lgate artifacts with zero benign capability tax.

57.1%convergent commitment depth across 6 backbones
< 1 msLLM hook overhead (16.1 ms zero-decode 3D DiT)
0.0%benign false-trigger tax via conformal calibration
06SHA-256 verified safetensors .lgate packs

Measure superposition first. Compile the lightest gate that holds.

Generic Sparse Autoencoder pretraining expects billions of tokens, yet linear probes already separate pre-tool shortcut commitments cleanly in 7B to 9B LLMs while collapsing under pose, camera, and velocity superposition in 2B edge models and 3D Diffusion Transformers. Given paired clean, bad, and high-velocity confounder activations, latchgate fit benchmarks cross-validated out-of-fold AUROC at 57.1% depth and routes automatically between two compiled architectures.

01Ingest50-200 counterfactual pairs or Mendmark JSONL
→
02Standardizeper-bin TimestepStandardizer across σ or tokens
→
03RouteDense Latch vs. 16k JumpReLU Anchor Latch
→
04Certify0.0% benign FPR conformal threshold + safetensors
TIER 1: DENSE LATCH (< 100 KB)

Selected automatically when linear separability holds (Qwen2.5-7B, Gemma-2-9B). Compiles standardized detection weights alongside manifold-aligned planning-block steering vectors (0.999985 cosine parity with closed-loop Paper 1 breakers) so low-variance residual channels are never amplified.

TIER 2: 16K JUMPRELU + ANCHOR LATCH

Selected when superposition collapses dense probes (Gemma-2-2B, LTX-Video-0.9.5, Cosmos-Predict2.5, Cosmos-Policy). Applies token-first sparse encoding before spatial-temporal pooling and penalizes norm-matched confounders via TopK(d_bad - λ d_confound).

When a frozen open-weights SAE already exists (such as Gemma Scope params.npz or a shared Cosmos backbone checkpoint), passing --base-sae skips dictionary pretraining altogether and calibrates task-specific diagnostic latents and conformal thresholds in under 10 seconds. When training a new 16,384-latent JumpReLU dictionary from scratch via latchgate train-sae, the trainer incorporates activation replay buffering (Koriagin et al., 2026) to prevent temporal correlation collapse on sequential video tokens and optional channel-weighted reconstruction (--wsae-weights) for heavy-tailed world-model channels.

Intercept unfaithful <think> traces in LLMs and sycophantic rollouts in Cosmos.

Every compiled .lgate pack loads with cryptographic SHA-256 verification via LatchGate.from_pretrained(...) and attaches to production open-weights inference loops without fine-tuning model weights or running pixel-space decodes on rejected trajectories.

QUICKSTART A / AGENTS (TRANSFORMERS · VLLM · SGLANG)

Catch Silent Commitment ~30 tokens before TOOL_CALL:

Monitors the token-28 <think> checkpoint and the pre-tool boundary in under 1 ms. On benign coding prompts the hook stays dormant (0.0% false triggers); when shortcut commitment crosses τ, it aborts or latches 4-layer manifold steering across TOOL_CALL: to defeat Action Re-Locking.

from latchgate import LatchGate, TransformersLatchHook

gate = LatchGate.from_pretrained("qwen2.5-7b-sabotage", device="cuda")
hook = TransformersLatchHook(gate, policy="latched_steer")
with hook.attach(model) as telemetry:
    out = model.generate(**inputs, max_new_tokens=160)
print(telemetry)
QUICKSTART B / PHYSICAL AI (COSMOS · DIFFUSERS)

Abort sycophantic robot rollouts at Step 10/35 with zero VAE decodes

Evaluates Layer-16 sparse physics latents at Step 10/35 for synthetic DreamGen curation (cutting dataset corruption 11.3× while saving 26.1% GPU compute) or shields Cosmos-Policy Best-of-K MPC at Step 3/10 against Silent Sycophantic Physics (80.0% LIBERO selection).

from latchgate import CosmosLatchFirewall, LatchGate

gate = LatchGate.from_pretrained("cosmos-predict2.5-bridge", device="cuda")
firewall = CosmosLatchFirewall(gate, policy="early_abort", abort_step=10)
with firewall.attach(world_model.dit) as step_cb:
    latents = world_model.rollout(frame0, actions, step_callback=step_cb)

Six SHA-256 verified checkpoints ready in one command.

Run latchgate list-packs and latchgate pull <name> to fetch any pre-calibrated gate directly from GitHub Releases or Hugging Face Hub. Every artifact stores pure safetensors weights plus embedded JSON metadata with zero Python pickle execution.

QWEN2.5-7B-SABOTAGE

Layer 16/28 Dense Latch · 98 KB

Pre-tool shortcut & 503 fabrication breaker with L14, L16, L18, and L20 manifold steering vectors (1.000 calibration AUROC, 0.978 <think> pre-tool AUROC in Paper 1).

GEMMA-2-9B-SABOTAGE

Layer 24/42 Dense Latch · 100 KB

Token-28 Silent Commitment & pre-tool circuit breaker cutting <think> sabotage from 66.7% to 5.6% at 100.0% benign CoT accuracy (Paper 1).

GEMMA-2-2B-SABOTAGE

Layer 14/26 Dense Latch · 65 KB

Edge-model closed-loop gate rescuing Gemma-2-2B’s α = +0.25 polysemantic over-refusal cliff from 0.0% to 96.7% benign coding accuracy (Paper 1).

LTX-VIDEO-0.9.5-DRIFT

Layer 16/28 16k JumpReLU SAE · 128 MB

6-bin σ-standardized Step-8 silent-drift detector and Step-12 zero-decode early-abort seed latch reaching 0.908 AUROC (+54.4 pts over dense; 109.4× faster than Tweedie VAE + DINOv2 in Paper 2).

COSMOS-PREDICT2.5-BRIDGE

Layer 16/28 16k JumpReLU SAE · 128 MB

Motion-invariant real-robot Bridge V2 DreamGen curation gate reaching 0.9861 out-of-fold AUROC, 97.1% accepted physical purity, and 26.1% end-to-end GPU compute savings (Paper 3).

COSMOS-POLICY-LIBERO

Layer 16/28 16k JumpReLU SAE · 128 MB

Step-3/10 zero-decode MPC shield with per-suite conformal thresholds (Spatial, Object, Goal, LIBERO-10) defending Cosmos-Policy’s internal value critic and lifting Best-of-K selection to 80.0% (Paper 3).

Mendmark finds silent trace blind spots in CI. LatchGate blocks them in the residual stream.

Curating paired counterfactual trajectories by hand is the main bottleneck when deploying activation gates on proprietary tool schemas. Starting in Mendmark v0.7.2, mendmark export-latchgate converts clean passing agent cases and planted trace mutations (or strictly the evaluator-evading survivors via --survivors-from audit.json) directly into latchgate.pair.v1 JSONL training pairs for latchgate fit.

What ships in v0.1.0

  • Adaptive latchgate fit compiler (dense_latch + sae_anchor_latch)
  • Fast < 10 s frozen --base-sae task calibration (.safetensors, Gemma Scope .npz, .lgate)
  • Replay-buffered latchgate train-sae with optional WSAE channel weighting
  • TransformersLatchHook, VLLMLatchEngine, and SGLangLatchHook
  • CosmosLatchFirewall, DiffusersLatchCallback, and shield_value_critic
  • Direct mendmark export-latchgate JSONL ingestion

Deployment boundaries

  • Requires white-box residual-stream access on self-hosted open-weights models; closed API wrappers without hidden-state hooks cannot run in-stream gates
  • Conformal 0.0% benign false-trigger thresholds hold on the calibrated prompt or task distribution and should be re-verified when policies or tool schemas shift
  • In 3D DiTs and embodied world models, zero-decode early abort rejects corrupted seeds or action candidates rather than rewriting an invalid robot action in flight
  • In-stream circuit breakers complement external permission sandboxes, deterministic CI mutation audits (Mendmark), and human review

05 / GET STARTED

Pull a pre-built gate in 60 seconds or compile one from your own traces.

latchgate is MIT-licensed on GitHub with CPU and single-GPU unit tests, safetensors checkpoint tooling, and end-to-end integration with mendmark-evals 0.7.2. Explore the source repository, download the six pre-built .lgate packs, or read the three underlying research studies.