Instructions to use CloudGoat/Samothrace-4B-Preview with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CloudGoat/Samothrace-4B-Preview with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="CloudGoat/Samothrace-4B-Preview")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("CloudGoat/Samothrace-4B-Preview", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use CloudGoat/Samothrace-4B-Preview with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "CloudGoat/Samothrace-4B-Preview" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CloudGoat/Samothrace-4B-Preview", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/CloudGoat/Samothrace-4B-Preview
- SGLang
How to use CloudGoat/Samothrace-4B-Preview 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 "CloudGoat/Samothrace-4B-Preview" \ --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": "CloudGoat/Samothrace-4B-Preview", "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 "CloudGoat/Samothrace-4B-Preview" \ --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": "CloudGoat/Samothrace-4B-Preview", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use CloudGoat/Samothrace-4B-Preview with Docker Model Runner:
docker model run hf.co/CloudGoat/Samothrace-4B-Preview
Samothrace-4B-Preview
Samothrace-4B-Preview is Qwen3.5-4B with its middle layers looped. Layers 8β19 (three blocks of 3Γ Gated DeltaNet + 1Γ full attention) run twice (K=2); layers 0β7 and 20β31 run once. The second pass uses its own LoRA (r=16) and a learned per-channel gate:
h β h + a β (Core(h; W + ΞWβ) β h) a β R^2560, initialised to 0
With a = 0 the model is bit-identical to Qwen3.5-4B, so the loop starts from the pretrained model and only learns how much of the second pass to mix in. The repo holds only the trainable part (11.4M parameters, fp32): the base weights are pulled from Qwen/Qwen3.5-4B.
Results
| K=1 (= base Qwen3.5-4B) | K=2 (Samothrace-4B-Preview) | K=3 | |
|---|---|---|---|
| MATH-500 (n=144) | 23.6% | 42.4% | 39.6% |
| HumanEval (n=164, pass@1) | 85.4% | 87.2% | 86.0% |
| Mean generated tokens, MATH-500 | 2,347 | 1,980 | 2,011 |
| Mean generated tokens, HumanEval | 1,166 | 518 | 553 |
Setup: greedy decoding, thinking mode, 2,048-token thinking budget with budget forcing (then up to 384 answer tokens), the same problems for every K. MATH-500 is a random 144-problem subset (the run hit its compute budget); HumanEval is complete. K=3 was trained jointly (same run, separate LoRA) and did not beat K=2, so K=2 is the released setting.
Read with care: K=1 is the untouched base model, so the K=1βK=2 gain mixes the effect of SFT (much shorter, less truncated thinking) with the effect of the loop. A same-budget non-looped LoRA control has not been run yet. The 2,048-token thinking cap truncates most MATH-500 solutions for every K, so absolute numbers sit well below Qwen3.5-4B's full-budget scores.
Training
- SFT, 10.0M tokens (3,418 samples, β€ 6,144 tokens): math 3.0M (DAPO-Math Qwen3-235B-Thinking rejection distill), code 3.5M (Qwen3.5-27B DeepCoder SFT, hardtests Qwen3.5-27B), agent 3.5M (Nemotron-SFT-Agentic-v2, multi-step tool calling and interactive agent).
- K sampled per sample (K=2 35%, K=3 65%); shortcut-consistency KL(p_K3 β p_K2) on 20% of K=3 samples.
- AdamW, LoRA lr 2e-4, gate lr 3e-3, cosine schedule, fp16 with loss scaling. 7.5 h on Kaggle 2Γ T4 (DDP), query-chunked attention and per-layer activation checkpointing; 0 OOM skips. Final mean |a| = 0.092.
Held-out SFT-distribution loss (samples not used in training), K=1 / K=2 / K=3: math 0.297 / 0.248 / 0.246, code (DeepCoder) 0.390 / 0.299 / 0.292, code (hardtests) 0.883 / 0.676 / 0.657, agent tool-calling 0.704 / 0.581 / 0.574, interactive agent 0.671 / 0.469 / 0.460.
Usage
Requires transformers with Qwen3.5 support. flash-linear-attention is recommended on GPU.
from huggingface_hub import snapshot_download
import sys
path = snapshot_download("CloudGoat/Samothrace-4B-Preview")
sys.path.insert(0, path)
from samothrace_inference import load_samothrace, generate
model, tok = load_samothrace(path) # downloads Qwen/Qwen3.5-4B, applies the K=2 loop
print(generate(model, tok, "Find all real x with x^2 - 5x + 6 = 0.", max_new_tokens=4096))
Files: modeling_samothrace.py (looped model, per-step LoRA, loop-aware KV / DeltaNet cache), samothrace_inference.py (loader + simple decoding), samothrace_k2_adapter.safetensors, samothrace_config.json.
Decoding costs about 1.4Γ a plain Qwen3.5-4B forward per token (44 of 32 layers' worth of compute), and the loop adds its own KV / recurrent-state slots for the second pass.
Limitations
- Research release; no safety tuning beyond the base model.
- Evaluated on small subsets with a short thinking budget; no AIME / LiveCodeBench / BFCL numbers yet.
- RL (GRPO) stage not yet applied.
