Run this model with HF Jobs

Run qdk0901/LoopQwen3-Contractive-4B on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/qdk0901/LoopQwen3-Contractive-4B. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/qdk0901/LoopQwen3-Contractive-4B on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/qdk0901/LoopQwen3-Contractive-4B. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

Quantize for lower memory use

Use HF Jobs to create a 4-bit version of https://huggingface.co/qdk0901/LoopQwen3-Contractive-4B. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.

LoopQwen3-Contractive-4B

Open In Colab License: Apache 2.0

Try it live on a free T4 GPU in 1 click! Click Open In Colab above (or view demo_colab.ipynb) to test T=1..6 scaling and the live Self-Locking Gate s_t interactive Gradio playground.

Zero-Pretraining Architectural Retrofit of Qwen/Qwen3-4B-Base into a Self-Locking Contractive Fixed-Point Recurrent-Depth Transformer
้›ถไปŽๅคด้ข„่ฎญ็ปƒๆžถๆž„ๆ”น้€ ๏ผšๅŸบไบŽไฟกๆฏๅˆ†ๅฑ‚ๅฎšไฝ็š„ Qwen3-4B-Base ่‡ช้”ๅŽ‹็ผฉไธๅŠจ็‚น้€’ๅฝ’ๆŽจ็†ๅคงๆจกๅž‹


Highlights / ๆ ธๅฟƒไบฎ็‚น

Without pretraining from scratch and by modifying only 0.254% of parameters (keeping 28 out of 36 layers bit-for-bit frozen), we mechanically located the emergent High-Abstraction Reasoning Hub of Qwen/Qwen3-4B-Base at Layers L21โ€“L28 (causal peak at L24 Self-Attention + L25 MLP) and physically rewired the forward graph into a Recurrent-Depth Architecture with a Self-Locking Contractive Fixed-Point Bridge:

Prelude (L1โ€“L20, 100% Frozen)
   โ”€โ”€โ–ถ [ ContractiveLoopCore (L21โ€“L28) ร— T iterations ]   (Effective depth = 20 + 8ยทT + 8)
          โ””โ”€โ”€ m_t = m_{t-1} + s_t ยท (g_t โŠ™ (cand_t - m_{t-1}))
   โ”€โ”€โ–ถ Coda (L29โ€“L36, 100% Frozen)
  • Zero Domain Experts (No MoE / No Task Router): One single universal recurrent core works across open-ended coding, math, deductive logic, rule induction, and zero-CoT multi-hop latent reasoning.
  • Exact Loop-Aware KV-Cache (use_cache=True == use_cache=False): Disjoint KV-cache slots per loop step enable full-speed autoregressive generation at any test-time depth $T$ (36L, 44L, 52L, 60L, 68L, 76L effective layers).
  • Strictly Non-Regressing Test-Time Compute Scaling: On identical frozen weights, increasing internal loop depth $T = 1 \to 2 \to 3$ improves zero-CoT Python Code Tracing 80% โ†’ 90% โ†’ 100% and 50-problem 5-domain general reasoning 90% โ†’ 92% โ†’ 94% with 0 regressions, while maintaining 100% (12/12) pass@1 on executable Python function writing (exec() unit tests).
  • Learned Self-Locking Stopping Gate ($s_t \in (0, 1)$): Automatically locks fixed-point working memory ($m_t = m_{t-1}$) right after reasoning depth $D$ (D=1 โ†’ 1.02ร—, D=2 โ†’ 2.12ร—, D=3 โ†’ 3.27ร—, D=4 โ†’ 3.95ร—, unseen D=5 โ†’ 4.72ร—, unseen D=6 โ†’ 5.17ร—), cutting compute by 44% while outperforming fixed $T=6$ (67.9% vs 65.4%) and halving $T=1$ calibration error (ECE 40.7% โ†’ 18.7%, AUROC 72.1% โ†’ 82.5%).
  • Dual Distribution: Full standalone AutoModelForCausalLM(..., trust_remote_code=True) weights in the repo root AND a lightweight 40 MB plug-in in plugin/contractive_loop_core.safetensors for users who already have Qwen/Qwen3-4B-Base.

Benchmark Summary / ๆ ธๅฟƒ่ฏ„ๆต‹็ป“ๆžœ

All evaluations are strictly held-out (zero training overlap), evaluated on identical frozen weights by simply varying the test-time loop switch model.set_num_loops(T):

Benchmark (Held-Out, Zero Leakage) Original Qwen3-4B-Base (36L) LoopQwen3 T=1 (36L) LoopQwen3 T=2 (44L) LoopQwen3 T=3 (52L) Notes
Zero-CoT Python Code Tracing (N=10) 80.0% 80.0% 90.0% 100.0% Strict monotonic scaling (+20% vs T=1 & Base!)
Executable Python CodeGen exec() Pass@1 (N=12) 91.7% (11/12) 100.0% 100.0% 100.0% 12/12 unit tests pass across all T
5-Domain General Reasoning (Exp 12, N=50) 74.0% 90.0% 92.0% 94.0% +2 wins / 0 regressions (Word 100%, Logic 100%, Code 100%, Cross-Induct 90%, Pattern 80%)
OOD Rule & Recursive Closed-Form Folding (Exp 11, N=26) 57.7% 92.3% 92.3% 92.3% Recursive folding 100%, zero regression
General Symbolic Logic Retention 100.0% 100.0% โ€” 100.0% Zero catastrophic forgetting
Zero-CoT Pure-Latent Multi-Hop (Exp 15, D=1..6, N=240) 40.0% (Unseen D5,6: 11.2%) 37.1% 62.5% 66.3% Autonomous self-halting (s_t < 0.5, avg 3.38ร— loops): 67.9% (beats fixed T=6 65.4%, D1/D2 100%/100%)

Mechanistic Research Figures / ๆœบ็†ๅฎšไฝไธŽ็ผฉๆ”พๆ›ฒ็บฟ

1. Layer-Wise Information Hierarchy Localization (Qwen3-4B-Base, 36 Layers)

Master Information Hierarchy Map

2. Self-Locking Contractive Fixed-Point Scaling & Calibrated Halting (Experiment 19B)

Contractive Fixed-Point Scaling

3. Pure-Latent Multi-Hop Staircase Activation Up to Unseen 76 Effective Layers (Experiment 15)

Pure-Latent Multi-Hop Scaling

(Full 19-experiment Chinese research report included in REPORT_Qwen3_4B_Base.md.)


Quickstart / ๅฟซ้€ŸไธŠๆ‰‹

Option 1: Standard transformers Standalone Loading (Recommended)

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

repo_id = "qdk0901/LoopQwen3-Contractive-4B"
tokenizer = AutoTokenizer.from_pretrained(repo_id, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    repo_id,
    trust_remote_code=True,
    dtype=torch.float16,
    device_map="auto",
).eval()

# Adjust test-time latent compute depth dynamically on identical frozen weights!
model.set_num_loops(3)  # T=1 -> 36L, T=2 -> 44L, T=3 -> 52L, T=4 -> 60L ...

prompt = (
    "What integer does this Python code print?\n"
    "```python\n"
    "x = 2\n"
    "for _ in range(3):\n"
    "    x = x * 2 + 1\n"
    "print(x)\n"
    "```\n"
    "Output: "
)

inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
    out = model.generate(**inputs, max_new_tokens=16, do_sample=False, use_cache=True)
print(tokenizer.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))

Inspecting the Self-Locking Thinking Gate $s_t$ (p_done = 1 - s_t)

model.loop_core.record_halting_trace = True
model.set_num_loops(4)
with torch.no_grad():
    _ = model(**inputs, use_cache=False)
# s_t near 1.0 = still thinking; s_t < 0.5 = converged & locked!
print([round(s[0, -1, 0].item(), 3) for s in model.loop_core.last_s_trace])
model.loop_core.record_halting_trace = False

Option 2: Lightweight 40 MB Plug-in (Reuses Official Qwen/Qwen3-4B-Base)

See plugin/load_plugin.py and plugin/contractive_loop_core.safetensors (~40 MB).


Acknowledgements & License

Built directly atop Qwen/Qwen3-4B-Base under the Apache 2.0 License.
All experiments were conducted on a single Tesla T4 (15 GB VRAM) without pretraining from scratch.

Downloads last month
227
Safetensors
Model size
4B params
Tensor type
F16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for qdk0901/LoopQwen3-Contractive-4B

Finetuned
(577)
this model