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
Make creation examples standalone with public dependencies
Browse files- .meta.json +1 -2
- README.md +40 -11
.meta.json
CHANGED
|
@@ -5,7 +5,6 @@
|
|
| 5 |
"kernels": "0.17.0",
|
| 6 |
"safetensors": "0.8.0",
|
| 7 |
"sglang": "0.5.23.dev384+g9ab74b851",
|
| 8 |
-
"tiny-random": "0.2.0",
|
| 9 |
"torch": "2.14.1",
|
| 10 |
"transformers": "5.19.0"
|
| 11 |
-
}
|
|
|
|
| 5 |
"kernels": "0.17.0",
|
| 6 |
"safetensors": "0.8.0",
|
| 7 |
"sglang": "0.5.23.dev384+g9ab74b851",
|
|
|
|
| 8 |
"torch": "2.14.1",
|
| 9 |
"transformers": "5.19.0"
|
| 10 |
+
}
|
README.md
CHANGED
|
@@ -79,13 +79,14 @@ print(tokenizer.decode(output[0, inputs["input_ids"].shape[1]:], skip_special_to
|
|
| 79 |
|
| 80 |
```python
|
| 81 |
import json
|
|
|
|
| 82 |
from pathlib import Path
|
|
|
|
| 83 |
|
| 84 |
import torch
|
| 85 |
-
from huggingface_hub import hf_hub_download
|
| 86 |
-
from
|
| 87 |
-
|
| 88 |
-
from tiny_random.qwen_utils import add_qwen_mtp, save_random_qwen_checkpoint, compact_qwen_tokenizer, check_qwen_repo_size
|
| 89 |
|
| 90 |
source_model_id = "Qwen/Qwen3.8-2.4T-A95B"
|
| 91 |
save_folder = "/tmp/tiny-random/qwen38-moe"
|
|
@@ -105,12 +106,40 @@ raw.update(
|
|
| 105 |
(folder / "config.json").write_text(json.dumps(raw, indent=2))
|
| 106 |
config = AutoConfig.from_pretrained(folder)
|
| 107 |
model = AutoModelForCausalLM.from_config(config, dtype=torch.bfloat16)
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
```
|
| 115 |
|
| 116 |
</details>
|
|
@@ -133,7 +162,6 @@ Qwen3.8 MoE: 8 backbone layers + 1 MTP layer; hidden_size=16
|
|
| 133 |
- kernels: 0.17.0
|
| 134 |
- safetensors: 0.8.0
|
| 135 |
- sglang: 0.5.23.dev384+g9ab74b851
|
| 136 |
-
- tiny-random: 0.2.0
|
| 137 |
- torch: 2.14.1
|
| 138 |
- transformers: 5.19.0
|
| 139 |
|
|
@@ -141,5 +169,6 @@ Qwen3.8 MoE: 8 backbone layers + 1 MTP layer; hidden_size=16
|
|
| 141 |
|
| 142 |
- 2026-10-23: Initial version.
|
| 143 |
- 2026-10-23: Reduced all repo files below 50 MB; GPU-validated TP=2, MTP and CUDA Graph.
|
|
|
|
| 144 |
|
| 145 |
This repo is generated by GPT-6.1-Sol
|
|
|
|
| 79 |
|
| 80 |
```python
|
| 81 |
import json
|
| 82 |
+
from copy import deepcopy
|
| 83 |
from pathlib import Path
|
| 84 |
+
from shutil import copyfile
|
| 85 |
|
| 86 |
import torch
|
| 87 |
+
from huggingface_hub import hf_hub_download, list_repo_files
|
| 88 |
+
from safetensors.torch import save_file
|
| 89 |
+
from transformers import AutoConfig, AutoModelForCausalLM, set_seed
|
|
|
|
| 90 |
|
| 91 |
source_model_id = "Qwen/Qwen3.8-2.4T-A95B"
|
| 92 |
save_folder = "/tmp/tiny-random/qwen38-moe"
|
|
|
|
| 106 |
(folder / "config.json").write_text(json.dumps(raw, indent=2))
|
| 107 |
config = AutoConfig.from_pretrained(folder)
|
| 108 |
model = AutoModelForCausalLM.from_config(config, dtype=torch.bfloat16)
|
| 109 |
+
backbone = model.model
|
| 110 |
+
text = backbone.config
|
| 111 |
+
def norm():
|
| 112 |
+
return type(backbone.norm)(text.hidden_size, text.rms_norm_eps).to(torch.bfloat16)
|
| 113 |
+
model.mtp = torch.nn.ModuleDict({
|
| 114 |
+
"pre_fc_norm_embedding": norm(),
|
| 115 |
+
"pre_fc_norm_hidden": norm(),
|
| 116 |
+
"fc": torch.nn.Linear(2 * text.hidden_size, text.hidden_size, bias=False, dtype=torch.bfloat16),
|
| 117 |
+
"layers": torch.nn.ModuleList([deepcopy(backbone.layers[-1])]),
|
| 118 |
+
"norm": norm(),
|
| 119 |
+
})
|
| 120 |
+
with torch.no_grad():
|
| 121 |
+
for name, param in sorted(model.named_parameters()):
|
| 122 |
+
if name.endswith("A_log"):
|
| 123 |
+
param.zero_()
|
| 124 |
+
elif name.endswith("dt_bias"):
|
| 125 |
+
param.fill_(1)
|
| 126 |
+
elif "norm" in name and name.endswith("weight"):
|
| 127 |
+
param.fill_(1 if "visual" in name or ".linear_attn.norm." in name else 0)
|
| 128 |
+
elif name.endswith("bias"):
|
| 129 |
+
param.zero_()
|
| 130 |
+
else:
|
| 131 |
+
torch.nn.init.normal_(param, mean=0, std=0.02)
|
| 132 |
+
state = {name: value.detach().cpu().contiguous() for name, value in model.state_dict().items()}
|
| 133 |
+
save_file(state, folder / "model.safetensors", metadata={"format": "pt"})
|
| 134 |
+
# Preserve tokenizer, processor and generation assets exactly as published.
|
| 135 |
+
assets = {
|
| 136 |
+
"tokenizer.json", "tokenizer_config.json", "special_tokens_map.json",
|
| 137 |
+
"vocab.json", "merges.txt", "added_tokens.json", "chat_template.jinja",
|
| 138 |
+
"chat_template.json", "preprocessor_config.json", "processor_config.json",
|
| 139 |
+
"video_preprocessor_config.json", "generation_config.json",
|
| 140 |
+
}
|
| 141 |
+
for name in sorted(set(list_repo_files(source_model_id, revision=source_revision)) & assets):
|
| 142 |
+
copyfile(hf_hub_download(source_model_id, name, revision=source_revision), folder / name)
|
| 143 |
```
|
| 144 |
|
| 145 |
</details>
|
|
|
|
| 162 |
- kernels: 0.17.0
|
| 163 |
- safetensors: 0.8.0
|
| 164 |
- sglang: 0.5.23.dev384+g9ab74b851
|
|
|
|
| 165 |
- torch: 2.14.1
|
| 166 |
- transformers: 5.19.0
|
| 167 |
|
|
|
|
| 169 |
|
| 170 |
- 2026-10-23: Initial version.
|
| 171 |
- 2026-10-23: Reduced all repo files below 50 MB; GPU-validated TP=2, MTP and CUDA Graph.
|
| 172 |
+
- 2026-10-23: Creation examples use only public dependencies; source assets are copied unchanged.
|
| 173 |
|
| 174 |
This repo is generated by GPT-6.1-Sol
|