Instructions to use waspflannel/Qwen3-1.7B-Looped-K4L2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use waspflannel/Qwen3-1.7B-Looped-K4L2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="waspflannel/Qwen3-1.7B-Looped-K4L2", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("waspflannel/Qwen3-1.7B-Looped-K4L2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use waspflannel/Qwen3-1.7B-Looped-K4L2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "waspflannel/Qwen3-1.7B-Looped-K4L2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "waspflannel/Qwen3-1.7B-Looped-K4L2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/waspflannel/Qwen3-1.7B-Looped-K4L2
- SGLang
How to use waspflannel/Qwen3-1.7B-Looped-K4L2 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 "waspflannel/Qwen3-1.7B-Looped-K4L2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "waspflannel/Qwen3-1.7B-Looped-K4L2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "waspflannel/Qwen3-1.7B-Looped-K4L2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "waspflannel/Qwen3-1.7B-Looped-K4L2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use waspflannel/Qwen3-1.7B-Looped-K4L2 with Docker Model Runner:
docker model run hf.co/waspflannel/Qwen3-1.7B-Looped-K4L2
Qwen3-1.7B-Looped-K4L2
This is an experiment: Qwen3-1.7B rebuilt as a looped model. Its 20 middle layers are replaced by one shared 10-layer block that runs twice. It was then distilled from the original model so it behaves like it.
The goal is to see whether open models can be made smaller in memory without retraining them from scratch. It is a research checkpoint, not a chat model. Read the limitations before using it.
Training code: https://github.com/waspflannel/looped-distill
How it is built
original: [0 1 2 3] [4 ... 13 | 14 ... 23] [24 25 26 27]
looped: [0 1 2 3] [shared block S0..S9, pass 1 | same block, pass 2] [24 25 26 27]
- The first 4 and last 4 layers stay unique.
- The 20 middle layers become one shared block of 10 layers, run 2 times. Each token still goes through 28 layer passes, so compute per token is about the same as the original. The saving is in memory, not speed.
- Each pass has its own small LoRA (rank 64, alpha 128) on all seven linear layers (q, k, v, o, gate, up, down). This lets the two passes behave a little differently while sharing almost all of their weights.
- Starting point: each shared layer was the average of the two original layers it replaces. Each pass's LoRA started as a rank-64 SVD approximation of the difference between the original layer and that average.
- The KV cache keeps one slot per pass (28 slots, like the original), so
generateworks as usual.
| Parameters | |
|---|---|
| Qwen3-1.7B (original) | 1,720.6M |
| Embeddings and final norm (tied with the output layer, frozen) | 311.2M |
| Unique layers (8) | 402.7M |
| Shared block (10 layers) | 503.4M |
| Per-pass LoRAs (2 x 10 layers) | 49.8M |
| Looped model, total | 1,267.0M (26% smaller) |
How it was trained
- Teacher: the original Qwen3-1.7B, frozen.
- Loss: full-vocabulary KL divergence between the teacher's and the student's next-token distributions (temperature 1, no cross-entropy term).
- Data: 150M tokens of FineWeb-Edu (
sample-10BT), packed into 1,024-token sequences. Every 100th document was held out for evaluation. - 4,577 steps of 32,768 tokens. AdamW, learning rate 5e-5 for the layers and 2e-4 for the LoRAs, 200 warmup steps, cosine decay, gradient clip 1.0.
- Trained: unique layers, shared block and LoRAs. Embeddings and the final norm stayed frozen.
- Hardware: one A100 40GB on Google Colab, about 4.2 hours of training at about 10k tokens/s.
Results
All numbers are from the final step (4,577), measured on the same GPU setup for both models.
| Held-out FineWeb-Edu perplexity (64 x 1,024 tokens) | MMLU (200 questions, 0-shot) | GSM8K (100 problems) | |
|---|---|---|---|
| Qwen3-1.7B (teacher) | 17.87 | 62.0% | 84.0% |
| This looped model | 20.07 | 29.0% | 0.0% |
On the kind of text it was trained on, the looped model is within about 12% of the original's perplexity while being 26% smaller. That part worked.
The knowledge and math scores did not carry over. MMLU at 29% is close to the 25% you get by guessing, and it got no GSM8K problems right.
Limitations
- It only saw web text. The distillation data was FineWeb-Edu articles, so the model learned to copy the teacher's article-style writing but not its question answering, chat format or step-by-step math. Mixing math and instruction data into the distillation set is the obvious next step and has not been tried yet.
- Not a chat or reasoning model. It may follow the Qwen3 chat template loosely, but answers are often repetitive or wrong. Use it for plain text continuation and for research on looped architectures.
- Small evals. MMLU used 200 random questions and GSM8K used 100 problems, so each score has a margin of a few points.
- Same compute as the original. Looping saves weight memory, not FLOPs. Each token still runs 28 layer passes.
- Custom code. Loading it needs
trust_remote_code=True. The modeling file is small and builds on the standard Qwen3 layers intransformers. It is not supported by llama.cpp, vLLM or other runtimes. - It inherits any biases and failure modes of Qwen3-1.7B and of web text.
How to use it
Tested with transformers 5.24 and torch 2.15 on CPU.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
repo = "waspflannel/Qwen3-1.7B-Looped-K4L2"
tokenizer = AutoTokenizer.from_pretrained(repo, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True, dtype=torch.bfloat16)
inputs = tokenizer("The water cycle is the process by which", return_tensors="pt")
output = model.generate(**inputs, max_new_tokens=60, do_sample=False)
print(tokenizer.decode(output[0], skip_special_tokens=True))
The evaluation above ran with float32 weights under bfloat16 autocast. Loading in plain bfloat16 gives very close but not identical numbers.
Files
model.safetensors: all weights in bfloat16, with the shared block stored once.config.json: the Qwen3-1.7B config plusunique_layers,loops,lora_rankandlora_alpha.configuration_looped_qwen3.py,modeling_looped_qwen3.py: the model code.- Tokenizer files: unchanged from Qwen/Qwen3-1.7B.
Credits
- Base model: Qwen/Qwen3-1.7B (Apache-2.0).
- Data: HuggingFaceFW/fineweb-edu.
- Ideas: Inkling 2 (looped core), Relaxed Recursive Transformers (averaged shared layers with per-loop LoRA and SVD init).
- Downloads last month
- 28