Text Generation
Transformers
English
recurrent-depth
looped-transformer
weight-tying
test-time-compute
latent-reasoning
mixture-of-experts
reproducible-research
negative-result
Instructions to use transilienceai/loop-surgery with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use transilienceai/loop-surgery with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="transilienceai/loop-surgery")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("transilienceai/loop-surgery", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use transilienceai/loop-surgery with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "transilienceai/loop-surgery" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "transilienceai/loop-surgery", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/transilienceai/loop-surgery
- SGLang
How to use transilienceai/loop-surgery with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "transilienceai/loop-surgery" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "transilienceai/loop-surgery", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "transilienceai/loop-surgery" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "transilienceai/loop-surgery", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use transilienceai/loop-surgery with Docker Model Runner:
docker model run hf.co/transilienceai/loop-surgery
|
Download reports/RESULTS.md from transilienceai/loop-surgery: direct link, hf CLI and curl.
- Browser
- Download file 3.22 kB
-
https://huggingface.co/transilienceai/loop-surgery/resolve/main/reports/RESULTS.md
- Command line
-
hf download hf://transilienceai/loop-surgery/reports/RESULTS.md
-
curl -L -o RESULTS.md https://huggingface.co/transilienceai/loop-surgery/resolve/main/reports/RESULTS.md
3.22 kB
| # Loop-surgery proof β RESULTS (2026-11-22) | |
| De-risks the crux of the "loop our security base" plan (`../inkling-like-training-plan.md`, Stage B): | |
| can we add Inkling's weight-tied middle-loop to a pretrained Qwen3 model **stably** (start == base) | |
| and **trainably** (gate opens, loop learns to help)? **Yes β proven on CPU, $0.** | |
| ## What's here | |
| - `loopify.py` β `loopify(model, start, end, n_passes, gate_init)` collapses decoder layers | |
| `[start:end)` into one weight-tied `LoopedMiddle` pseudo-layer that the stock | |
| `transformers` model.forward drives unchanged. Combines one-pass and K-pass results through a | |
| **zero-init interpolation gate**: `out = y1 + gate*(yK - y1)`, so `gate==0 β out == y1` exactly. | |
| - Eval fast-path short-circuits at `gate==0` (keeps the invariant exact and avoids KV-cache | |
| mutation under `generate`); training always runs the full gated path so the gate stays in the | |
| autograd graph and can open from exactly zero. | |
| - Needed a per-block `attention_type` (the model picks each layer's causal mask by it); asserts the | |
| block's layers share one type. | |
| - `prove_invariant.py` β the correctness checks. | |
| - `heal_demo.py` β the trainability / micro-heal check. | |
| ## Results (Qwen/Qwen3-0.6B, 28 layers, middle block = layers [9:18), 9 layers tied, 3 passes) | |
| **Surgery correctness (`prove_invariant.py`, eval):** | |
| | Check | Result | | |
| |---|---| | |
| | [1] INVARIANT β gate=0, 3 passes: `max|loopβbase|` logits | **0.000e+00 (bit-identical) β** | | |
| | [2] WIRED β gate=0.5: logits move | 7.28 β (loop flows) | | |
| | [3] PASSES β 3β5 passes @ gate=0.5 | 7.39 β (real depth dial) | | |
| | [4] GEN β greedy 24 tok @ gate=0 | identical to base β | | |
| **Trainability (`heal_demo.py`, train gate+middle-block, 30 steps, tiny corpus):** | |
| - Gate receives gradient immediately (`d(loss)/d(gate)` nonzero at step 1) and moves off zero. | |
| - Loss **5.69 β 0.77**; gate **0.0 β +0.125 (opened)**. | |
| - Bonus: by later steps `d(loss)/d(gate)` turns **negative** β once the tied block adapts slightly, | |
| the optimizer actively opens the loop because the extra passes start reducing loss. | |
| ## What this proves / does NOT prove | |
| - **Proven:** the zero-init-gate loop surgery is correct (start == base, bit-exact), the loop is a | |
| live test-time-depth dial, and the whole thing trains end-to-end with the gate opening from zero. | |
| The single biggest novelty-risk of Stage B is retired. | |
| - **NOT yet proven:** that a loop *measurably improves reasoning at matched visible tokens* β that | |
| needs a real heal on real tokens (continued-pretrain + on-policy distillation), i.e. GPU/Modal. | |
| The micro-heal above overfits a 6-sentence toy; it shows the mechanism trains, not that the loop | |
| wins on held data. | |
| ## Reproduce | |
| ```bash | |
| cd custom_models/loop_proof | |
| PYTHONPATH=. python3 prove_invariant.py | |
| PYTHONPATH=. python3 heal_demo.py | |
| ``` | |
| ## Next step (first GPU spend) | |
| Real small-model heal on Modal (loopify Qwen3-0.6B/1.7B β continue-train on tens of M tokens + | |
| on-policy distillation β eval looped vs non-looped at matched visible tokens on a held set). | |
| Est. a few GPU-hours on L40S/A100 β **$10β30**. Only after that wins do we loopify the 35B security | |
| base (the ~$low-thousands Phase 2). | |