Instructions to use tiny-random/qwen3.8-moe with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tiny-random/qwen3.8-moe with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tiny-random/qwen3.8-moe") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tiny-random/qwen3.8-moe") model = AutoModelForCausalLM.from_pretrained("tiny-random/qwen3.8-moe", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use tiny-random/qwen3.8-moe with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tiny-random/qwen3.8-moe" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tiny-random/qwen3.8-moe", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tiny-random/qwen3.8-moe
- SGLang
How to use tiny-random/qwen3.8-moe 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 "tiny-random/qwen3.8-moe" \ --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": "tiny-random/qwen3.8-moe", "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 "tiny-random/qwen3.8-moe" \ --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": "tiny-random/qwen3.8-moe", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use tiny-random/qwen3.8-moe with Docker Model Runner:
docker model run hf.co/tiny-random/qwen3.8-moe
File size: 13,012 Bytes
8f4aac0 c6b32c5 8f4aac0 c6b32c5 8f4aac0 eb13155 8f4aac0 c6b32c5 8f4aac0 c6b32c5 8f4aac0 eb13155 8f4aac0 eb13155 8f4aac0 ed0e498 8f4aac0 ed0e498 8f4aac0 ed0e498 8f4aac0 c6b32c5 8f4aac0 ed0e498 8f4aac0 0e7277f 8f4aac0 c6b32c5 9432ad1 ed0e498 9432ad1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | ---
library_name: transformers
base_model:
- Qwen/Qwen3.8-2.4T-A95B
---
This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from [Qwen/Qwen3.8-2.4T-A95B](https://huggingface.co/Qwen/Qwen3.8-2.4T-A95B).
Structural comparison with `Qwen/Qwen3.8-2.4T-A95B`:
| Feature | Source | Tiny |
|---|---|---|
| Input modalities | Text | Same |
| Vocabulary | 248,320 | Same; special-token IDs preserved |
| Backbone layers | 92 | 8 |
| Hidden size | 8,192 | 16 |
| Attention Q/KV heads; head dim | 64/4; 256 | 32/2; 128 |
| Attention cycle | 3 linear + 1 full | Same; two complete cycles |
| Linear-attention key/value heads | 16/128 | 2/16 |
| Linear-attention key/value head dim | 128/128 | Same |
| Routed experts / top-k | 512 / 10 | 32 / 10 |
| Shared experts | 1 | Same |
| Expert/shared intermediate size | 2,048 / 2,048 | 256 / 256 |
| MTP | 1 full-attention layer; shared embeddings | Same |
| Checkpoint format | BF16 | Same |
| File path | Size |
|------|------|
| model.safetensors | 25.9MB |
### Example usage:
- SGLang (✅ verified)
- Runs with TP=2, the embedded NEXTN/MTP layer, and CUDA Graph.
- Verified for text requests on two NVIDIA H20 GPUs;
see Test environment for dependency versions.
```bash
model_id=tiny-random/qwen3.8-moe
sglang serve \
--model-path $model_id \
--tp-size 2 \
--fp8-gemm-backend triton \
--moe-runner-backend triton \
--speculative-algorithm NEXTN \
--speculative-num-steps 3 \
--speculative-eagle-topk 1 \
--speculative-num-draft-tokens 4 \
--context-length 4096 \
--max-total-tokens 4096 \
--chunked-prefill-size 512 \
--mem-fraction-static 0.4 \
--cuda-graph-config '{"decode": {"bs": [1, 2, 4, 8]}}' \
--disable-custom-all-reduce
```
- Transformers (✅ verified)
```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "tiny-random/qwen3.8-moe"
model = AutoModelForCausalLM.from_pretrained(model_id, dtype=torch.bfloat16, device_map="cuda", attn_implementation="sdpa")
tokenizer = AutoTokenizer.from_pretrained(model_id)
inputs = tokenizer.apply_chat_template(
[{"role": "user", "content": "Hello"}], tokenize=True,
add_generation_prompt=True, return_dict=True, return_tensors="pt",
).to(model.device)
output = model.generate(**inputs, do_sample=False, max_new_tokens=10)
print(tokenizer.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
```
### Codes to create this repo (✅ verified):
<details><summary>Click to expand</summary>
```python
import json
from copy import deepcopy
from pathlib import Path
from shutil import copyfile
import torch
from huggingface_hub import hf_hub_download, list_repo_files
from safetensors.torch import save_file
from transformers import AutoConfig, AutoModelForCausalLM, set_seed
source_model_id = "Qwen/Qwen3.8-2.4T-A95B"
save_folder = "/tmp/tiny-random/qwen38-moe"
source_revision = '207bd685a7e3696cfaff12ded7c6a7ea0f88c996'
set_seed(42)
folder = Path(save_folder)
folder.mkdir(parents=True, exist_ok=True)
raw = json.loads(Path(hf_hub_download(source_model_id, "config.json", revision=source_revision)).read_text())
raw.update(
hidden_size=16, head_dim=128, num_hidden_layers=8,
layer_types=(["linear_attention"] * 3 + ["full_attention"]) * 2,
num_attention_heads=32, num_key_value_heads=2,
linear_num_key_heads=2, linear_num_value_heads=16,
linear_key_head_dim=128, linear_value_head_dim=128,
num_experts=32, moe_intermediate_size=256, shared_expert_intermediate_size=256,
)
(folder / "config.json").write_text(json.dumps(raw, indent=2))
config = AutoConfig.from_pretrained(folder)
model = AutoModelForCausalLM.from_config(config, dtype=torch.bfloat16)
backbone = model.model
text = backbone.config
def norm():
return type(backbone.norm)(text.hidden_size, text.rms_norm_eps).to(torch.bfloat16)
model.mtp = torch.nn.ModuleDict({
"pre_fc_norm_embedding": norm(),
"pre_fc_norm_hidden": norm(),
"fc": torch.nn.Linear(2 * text.hidden_size, text.hidden_size, bias=False, dtype=torch.bfloat16),
"layers": torch.nn.ModuleList([deepcopy(backbone.layers[-1])]),
"norm": norm(),
})
with torch.no_grad():
for name, param in sorted(model.named_parameters()):
if name.endswith("A_log"):
param.zero_()
elif name.endswith("dt_bias"):
param.fill_(1)
elif "norm" in name and name.endswith("weight"):
param.fill_(1 if "visual" in name or ".linear_attn.norm." in name else 0)
elif name.endswith("bias"):
param.zero_()
else:
torch.nn.init.normal_(param, mean=0, std=0.02)
state = {name: value.detach().cpu().contiguous() for name, value in model.state_dict().items()}
save_file(state, folder / "model.safetensors", metadata={"format": "pt"})
# Preserve tokenizer, processor and generation assets exactly as published.
assets = {
"tokenizer.json", "tokenizer_config.json", "special_tokens_map.json",
"vocab.json", "merges.txt", "added_tokens.json", "chat_template.jinja",
"chat_template.json", "preprocessor_config.json", "processor_config.json",
"video_preprocessor_config.json", "generation_config.json",
}
for name in sorted(set(list_repo_files(source_model_id, revision=source_revision)) & assets):
copyfile(hf_hub_download(source_model_id, name, revision=source_revision), folder / name)
```
</details>
### Printing the model:
<details><summary>Click to expand</summary>
```text
Qwen3_5MoeForCausalLM(
(model): Qwen3_5MoeTextModel(
(embed_tokens): Embedding(248320, 16)
(layers): ModuleList(
(0-2): 3 x Qwen3_5MoeDecoderLayer(
(linear_attn): Qwen3_5MoeGatedDeltaNet(
(conv1d): Conv1d(2560, 2560, kernel_size=(4,), stride=(1,), padding=(3,), groups=2560, bias=False)
(norm): Qwen3_5MoeRMSNormGated()
(out_proj): Linear(in_features=2048, out_features=16, bias=False)
(in_proj_qkv): Linear(in_features=16, out_features=2560, bias=False)
(in_proj_z): Linear(in_features=16, out_features=2048, bias=False)
(in_proj_b): Linear(in_features=16, out_features=16, bias=False)
(in_proj_a): Linear(in_features=16, out_features=16, bias=False)
)
(mlp): Qwen3_5MoeSparseMoeBlock(
(gate): Qwen3_5MoeTopKRouter()
(experts): Qwen3_5MoeExperts(
(act_fn): SiLUActivation()
)
(shared_expert): Qwen3_5MoeMLP(
(gate_proj): Linear(in_features=16, out_features=256, bias=False)
(up_proj): Linear(in_features=16, out_features=256, bias=False)
(down_proj): Linear(in_features=256, out_features=16, bias=False)
(act_fn): SiLUActivation()
)
(shared_expert_gate): Linear(in_features=16, out_features=1, bias=False)
)
(input_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
(post_attention_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
)
(3): Qwen3_5MoeDecoderLayer(
(self_attn): Qwen3_5MoeAttention(
(q_proj): Linear(in_features=16, out_features=8192, bias=False)
(k_proj): Linear(in_features=16, out_features=256, bias=False)
(v_proj): Linear(in_features=16, out_features=256, bias=False)
(o_proj): Linear(in_features=4096, out_features=16, bias=False)
(q_norm): Qwen3_5MoeRMSNorm((128,), eps=1e-06)
(k_norm): Qwen3_5MoeRMSNorm((128,), eps=1e-06)
)
(mlp): Qwen3_5MoeSparseMoeBlock(
(gate): Qwen3_5MoeTopKRouter()
(experts): Qwen3_5MoeExperts(
(act_fn): SiLUActivation()
)
(shared_expert): Qwen3_5MoeMLP(
(gate_proj): Linear(in_features=16, out_features=256, bias=False)
(up_proj): Linear(in_features=16, out_features=256, bias=False)
(down_proj): Linear(in_features=256, out_features=16, bias=False)
(act_fn): SiLUActivation()
)
(shared_expert_gate): Linear(in_features=16, out_features=1, bias=False)
)
(input_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
(post_attention_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
)
(4-6): 3 x Qwen3_5MoeDecoderLayer(
(linear_attn): Qwen3_5MoeGatedDeltaNet(
(conv1d): Conv1d(2560, 2560, kernel_size=(4,), stride=(1,), padding=(3,), groups=2560, bias=False)
(norm): Qwen3_5MoeRMSNormGated()
(out_proj): Linear(in_features=2048, out_features=16, bias=False)
(in_proj_qkv): Linear(in_features=16, out_features=2560, bias=False)
(in_proj_z): Linear(in_features=16, out_features=2048, bias=False)
(in_proj_b): Linear(in_features=16, out_features=16, bias=False)
(in_proj_a): Linear(in_features=16, out_features=16, bias=False)
)
(mlp): Qwen3_5MoeSparseMoeBlock(
(gate): Qwen3_5MoeTopKRouter()
(experts): Qwen3_5MoeExperts(
(act_fn): SiLUActivation()
)
(shared_expert): Qwen3_5MoeMLP(
(gate_proj): Linear(in_features=16, out_features=256, bias=False)
(up_proj): Linear(in_features=16, out_features=256, bias=False)
(down_proj): Linear(in_features=256, out_features=16, bias=False)
(act_fn): SiLUActivation()
)
(shared_expert_gate): Linear(in_features=16, out_features=1, bias=False)
)
(input_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
(post_attention_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
)
(7): Qwen3_5MoeDecoderLayer(
(self_attn): Qwen3_5MoeAttention(
(q_proj): Linear(in_features=16, out_features=8192, bias=False)
(k_proj): Linear(in_features=16, out_features=256, bias=False)
(v_proj): Linear(in_features=16, out_features=256, bias=False)
(o_proj): Linear(in_features=4096, out_features=16, bias=False)
(q_norm): Qwen3_5MoeRMSNorm((128,), eps=1e-06)
(k_norm): Qwen3_5MoeRMSNorm((128,), eps=1e-06)
)
(mlp): Qwen3_5MoeSparseMoeBlock(
(gate): Qwen3_5MoeTopKRouter()
(experts): Qwen3_5MoeExperts(
(act_fn): SiLUActivation()
)
(shared_expert): Qwen3_5MoeMLP(
(gate_proj): Linear(in_features=16, out_features=256, bias=False)
(up_proj): Linear(in_features=16, out_features=256, bias=False)
(down_proj): Linear(in_features=256, out_features=16, bias=False)
(act_fn): SiLUActivation()
)
(shared_expert_gate): Linear(in_features=16, out_features=1, bias=False)
)
(input_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
(post_attention_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
)
)
(norm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
(rotary_emb): Qwen3_5MoeTextRotaryEmbedding()
)
(lm_head): Linear(in_features=16, out_features=248320, bias=False)
(mtp): ModuleDict(
(pre_fc_norm_embedding): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
(pre_fc_norm_hidden): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
(fc): Linear(in_features=32, out_features=16, bias=False)
(layers): ModuleList(
(0): Qwen3_5MoeDecoderLayer(
(self_attn): Qwen3_5MoeAttention(
(q_proj): Linear(in_features=16, out_features=8192, bias=False)
(k_proj): Linear(in_features=16, out_features=256, bias=False)
(v_proj): Linear(in_features=16, out_features=256, bias=False)
(o_proj): Linear(in_features=4096, out_features=16, bias=False)
(q_norm): Qwen3_5MoeRMSNorm((128,), eps=1e-06)
(k_norm): Qwen3_5MoeRMSNorm((128,), eps=1e-06)
)
(mlp): Qwen3_5MoeSparseMoeBlock(
(gate): Qwen3_5MoeTopKRouter()
(experts): Qwen3_5MoeExperts(
(act_fn): SiLUActivation()
)
(shared_expert): Qwen3_5MoeMLP(
(gate_proj): Linear(in_features=16, out_features=256, bias=False)
(up_proj): Linear(in_features=16, out_features=256, bias=False)
(down_proj): Linear(in_features=256, out_features=16, bias=False)
(act_fn): SiLUActivation()
)
(shared_expert_gate): Linear(in_features=16, out_features=1, bias=False)
)
(input_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
(post_attention_layernorm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
)
)
(norm): Qwen3_5MoeRMSNorm((16,), eps=1e-06)
)
)
```
</details>
### Test environment:
- accelerate: 1.15.0
- flashinfer-python: 0.7.2
- huggingface_hub: 1.33.0
- kernels: 0.17.0
- safetensors: 0.8.0
- sglang: 0.5.23.dev384+g9ab74b851
- torch: 2.14.1
- transformers: 5.19.0
### Change log:
- 2026-10-23: Initial version.
- 2026-10-23: Reduced all repo files below 50 MB; GPU-validated TP=2, MTP and CUDA Graph.
- 2026-10-23: Creation examples use only public dependencies; source assets are copied unchanged.
This repo is generated by GPT-6.1-Sol |