LoopQwen3-Contractive-4B
Recurrent Evolution of Qwen3
2 min readupdated
This new language model is built on Qwen/Qwen3-4B-Base without pre-training from scratch. The authors modified just 0.254% of the parameters, turning the central layers into a recurrent block featuring a fixed point and a self-blocking stop gate. The model can dynamically scale computation depth right during inference (test-time compute), improving logic and coding capabilities. This solution is ideal for developers and researchers who need deep reasoning from a compact model.
Key features
- Dynamic depth scaling: adjusting the cycle parameter allows for flexible, on-the-fly scaling of the effective network depth.
- Self-blocking gate: automatically fixes working memory upon completing reasoning tasks, cutting resource consumption by 44%.
- KV-cache preservation: full support for fast autoregressive generation across any recursion depth.
- Accuracy boost: steady gains in logic tasks, code debugging, and multi-step reasoning without any regression in baseline skills.
What you can do
- Test code generation: run complex Python tasks with increased recursion depth for error-free results.
- Explore latent reasoning: track the step-by-step trajectory of the self-blocking stop gate.
- Use the plugin: connect the lightweight 40 MB safetensors module to your already downloaded original
Qwen/Qwen3-4B-Basebase. - Integrate into pipelines: use the standard
transformersclass for local execution on accessible GPUs like the Tesla T4.
Example
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()
model.set_num_loops(3)
prompt = "What integer does this Python code print?\nx = 2\nfor _ in range(3):\n x = x * 2 + 1\nprint(x)\nOutput: "
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))
Read more
DetailsBenchmarks: 5-domain reasoning rose to 94% (compared to 74% for the base model), and code tracing reached 100%.
Requirements: runs on a single Tesla T4 (15 GB VRAM).
Limitations: requires
trust_remote_code=True support.License: Apache 2.0.










Comments