Instructions to use Qwen/Qwen3-Coder-Next with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen3-Coder-Next with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/Qwen3-Coder-Next") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-Coder-Next") model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-Coder-Next") 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen3-Coder-Next with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen3-Coder-Next" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen3-Coder-Next", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Qwen/Qwen3-Coder-Next
- SGLang
How to use Qwen/Qwen3-Coder-Next 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 "Qwen/Qwen3-Coder-Next" \ --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": "Qwen/Qwen3-Coder-Next", "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 "Qwen/Qwen3-Coder-Next" \ --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": "Qwen/Qwen3-Coder-Next", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Qwen/Qwen3-Coder-Next with Docker Model Runner:
docker model run hf.co/Qwen/Qwen3-Coder-Next
"num_experts_per_tok": 10 这个设置是领导拍脑袋拍出来的吗?
#12
by cloudyu - opened
我把模型转成了MLX mxfp8格式,gemini帮我测试了一下,虽然不太严谨,但是体感上16专家更胜一筹。
测试代码如下
import mlx.core as mx
from mlx_lm import load, generate
model_path = "./MLX-Qwen3-Coder-Next-mxfp8"
# 1. 加载模型(仅加载一次)
print("正在加载模型...")
model, tokenizer = load(model_path)
def test_config(top_k_value, test_prompt):
print(f"\n{'='*20} 正在测试 num_experts_per_tok: {top_k_value} {'='*20}")
# 2. 动态修改 MoE 专家激活数
# Qwen 架构在 MLX 中的 MLP 层通常包含 num_experts_per_tok 属性
for layer in model.model.layers:
if hasattr(layer, 'mlp'):
# 强制覆盖属性
layer.mlp.num_experts_per_tok = top_k_value
# 3. 极简调用,避开所有 temp/temperature 参数名冲突
# mlx_lm 会使用默认的 top_p=1.0 和 temp=0.0 (greedy decoding)
response = generate(
model,
tokenizer,
prompt=test_prompt,
max_tokens=1024,
verbose=True # 实时显示生成过程
)
return response
# 编写一个更有难度的代码测试题,容易看出逻辑代差
test_prompt = """
请实现一个 Python 类 AsyncBuffer:
1. 初始化参数 max_size。
2. 实现 async def put(self, item) 和 async def get(self)。
3. 实现 async def close()。
4. 要求:
- 缓冲区满时 put 阻塞,空时 get 阻塞。
- close() 后,put 立即抛出异常。
- close() 后,get 允许继续取走存量数据,直到取空。
- 取空且已关闭后,所有 get 抛出 BufferClosed 异常。
- 严禁使用 asyncio.Queue,请手动使用 asyncio.Condition 或 asyncio.Event 实现以展示底层逻辑。
"""
try:
# 运行对比
res_10 = test_config(10, test_prompt)
print("\n\n")
res_16 = test_config(16, test_prompt)
print("\n" + "="*50)
print("对比完成!请观察 num_experts_per_tok 从 10 变为 16 后,")
print("代码的异常处理逻辑、注释完整度以及生成的流畅度。")
print("="*50)
except Exception as e:
print(f"\n运行中出错: {e}")
cloudyu changed discussion status to closed
"num_experts_per_tok": 10 这个设置是领导拍脑袋拍出来的吗?