tiny ramdom models
Collection
141 items • Updated • 10
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]:]))How to use tiny-random/qwen3.8-moe with vLLM:
# 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?"
}
]
}'docker model run hf.co/tiny-random/qwen3.8-moe
How to use tiny-random/qwen3.8-moe with SGLang:
# 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?"
}
]
}'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?"
}
]
}'How to use tiny-random/qwen3.8-moe with Docker Model Runner:
docker model run hf.co/tiny-random/qwen3.8-moe
This tiny model is intended for debugging. It is randomly initialized using the configuration adapted from 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 |
SGLang (✅ verified)
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
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))
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)
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)
)
)
This repo is generated by GPT-6.1-Sol
Base model
Qwen/Qwen3.8-2.4T-A95B