qwen3-next-moe-tiny-random
313
80.0B
—
by
yujiepan
Language Model
OTHER
80B params
New
313 downloads
Early-stage
Edge AI:
Mobile
Laptop
Server
179GB+ RAM
Mobile
Laptop
Server
Quick Summary
AI model with specialized capabilities.
Device Compatibility
Mobile
4-6GB RAM
Laptop
16GB RAM
Server
GPU
Minimum Recommended
75GB+ RAM
Code Examples
load the tokenizer and the modelpythontransformers
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
model_id = "yujiepan/qwen3-next-moe-tiny-random"
# load the tokenizer and the model
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
dtype="auto",
device_map="cuda",
)
# prepare the model input
prompt = "Give me a short introduction to large language model."
messages = [
{"role": "user", "content": prompt},
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=8,
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
content = tokenizer.decode(output_ids, skip_special_tokens=True)
print("content:", content)Codes to create this repo:pythontransformers
from copy import deepcopy
import torch
import torch.nn as nn
from transformers import (
AutoConfig,
AutoModelForCausalLM,
AutoTokenizer,
GenerationConfig,
pipeline,
set_seed,
)
source_model_id = "Qwen/Qwen3-Next-80B-A3B-Instruct"
save_folder = "/tmp/yujiepan/qwen3-next-moe-tiny-random"
tokenizer = AutoTokenizer.from_pretrained(
source_model_id, trust_remote_code=True,
)
tokenizer.save_pretrained(save_folder)
config = AutoConfig.from_pretrained(
source_model_id, trust_remote_code=True,
)
config._name_or_path = source_model_id
config.hidden_size = 8
config.intermediate_size = 32
config.head_dim = 32
config.num_key_value_heads = 8
config.num_attention_heads = 16
config.num_hidden_layers = 4
config.tie_word_embeddings = False
config.linear_num_key_heads = 8
config.linear_num_value_heads = 16
config.moe_intermediate_size = 32
config.num_experts = 32
config.num_experts_per_tok = 10
config.layer_types = config.layer_types[:4]
config.shared_expert_intermediate_size = 32
model = AutoModelForCausalLM.from_config(
config,
torch_dtype=torch.bfloat16,
trust_remote_code=True,
)
model.generation_config = GenerationConfig.from_pretrained(
source_model_id, trust_remote_code=True,
)
# MTP
model.mtp = nn.ModuleDict({
"pre_fc_norm_embedding": nn.RMSNorm(config.hidden_size),
"fc": nn.Linear(config.hidden_size * 2, config.hidden_size, bias=False),
"norm": nn.RMSNorm(config.hidden_size),
"pre_fc_norm_hidden": nn.RMSNorm(config.hidden_size),
"layers": nn.ModuleList([deepcopy(model.model.layers[3])]),
})
model = model.to(torch.bfloat16)
set_seed(42)
with torch.no_grad():
for name, p in sorted(model.named_parameters()):
torch.nn.init.normal_(p, 0, 0.1)
print(name, p.shape)
model.save_pretrained(save_folder)Deploy This Model
Production-ready deployment in minutes
Together.ai
Instant API access to this model
Production-ready inference API. Start free, scale to millions.
Try Free APIReplicate
One-click model deployment
Run models in the cloud with simple API. No DevOps required.
Deploy NowDisclosure: We may earn a commission from these partners. This helps keep LLMYourWay free.