模型名称: MooreThreads/MusaCoder-27B
模型链接: HuggingFace
模型描述: MusaCoder-27B 是一个 270 亿参数的代码生成大语言模型,基于 Qwen3_5 架构,支持线性注意力(Linear Attention)和全注意力(Full Attention)混合机制。支持文本生成和多模态(图像+文本)推理。
模型架构: Qwen3_5ForConditionalGeneration
输入规格:
输出规格:
| 依赖项 | 版本要求 | 说明 |
|---|---|---|
| Python | >= 3.10 | 推荐 3.11 |
| torch | >= 2.1.0 | PyTorch 框架 |
| torch-npu | == 2.9.0 | 昇腾 NPU 后端 |
| vllm | >= 0.18.0 | vLLM 推理引擎 (vllm-ascend) |
| transformers | >= 5.15.1 | HuggingFace Transformers (需支持 qwen3_5) |
| sentencepiece | >= 0.1.99 | Tokenizer 依赖 |
| protobuf | >= 3.20.0 | 序列化依赖 |
| Pillow | >= 9.0.0 | 图像处理 |
| 昇腾驱动 | CANN 8.5.1 | 推荐版本 |
安装命令:
pip install torch-npu==2.9.0 vllm==0.18.0 transformers>=5.15.1 sentencepiece protobuf Pillow# 检查 NPU 设备
npu-smi info
# 验证 torch_npu
python3 -c "import torch_npu; print(torch.npu.device_count(), torch.npu.get_device_name(0))"
# 验证 vllm-ascend
python3 -c "from vllm import LLM; print('vllm-ascend ready')"# 方式一:HuggingFace(推荐)
huggingface-cli download MooreThreads/MusaCoder-27B --local-dir /tmp/MooreThreads-MusaCoder-27B
# 方式二:AtomGit 镜像(HuggingFace 下载慢时使用)
# https://ai.gitcode.com/hf_mirrors/MooreThreads/MusaCoder-27B方式一:vLLM 服务(推荐)
vllm serve /tmp/MooreThreads-MusaCoder-27B \
--dtype bfloat16 \
--tensor-parallel-size 2 \
--max-model-len 8192 \
--max-num-seqs 16 \
--enforce-eager \
--limit-mm-per-prompt '{"image": 1, "video": 0}' \
--port 8000方式二:inference.py
python inference.py --model-path /tmp/MooreThreads-MusaCoder-27B --tp-size 2| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| --model-path | str | /tmp/MooreThreads-MusaCoder-27B | 模型 checkpoint 路径 |
| --tp-size | int | 2 | NPU 卡数(Tensor Parallel) |
| --max-model-len | int | 8192 | 最大序列长度 |
| --port | int | 8000 | API 服务端口 |
| --image | str | None | 多模态推理测试图片路径 |
# 文本生成
curl http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"/tmp/MooreThreads-MusaCoder-27B","messages":[{"role":"user","content":"Write a Python quicksort"}],"max_tokens":256}'
# 多模态推理
curl http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"/tmp/MooreThreads-MusaCoder-27B","messages":[{"role":"user","content":[{"type":"image_url","image_url":{"url":"data:image/jpeg;base64,..."}},{"type":"text","text":"Describe this image"}]}],"max_tokens":256}'vllm serve /tmp/MooreThreads-MusaCoder-27B --load-format dummy --dtype bfloat16 \
--tensor-parallel-size 2 --max-model-len 8192 --max-num-seqs 16 --enforce-eager
[OK] Server started after 129s
[OK] Stage A inference successful!vllm serve /tmp/MooreThreads-MusaCoder-27B \
--served-model-name MusaCoder-27B \
--dtype bfloat16 --tensor-parallel-size 2 \
--max-model-len 8192 --max-num-seqs 16 \
--enforce-eager --limit-mm-per-prompt '{"image":0,"video":0}' --port 8000
[OK] Model loaded: 12/12 shards (51.0GB)
[OK] KV cache: 236,544 tokens, max concurrency 68.56x
[OK] Engine init: 8.28s (profile + KV cache)
[OK] Application startup complete+------------------------------------------------------------------------------------------------+
| npu-smi 25.5.5 Version: 25.5.5 |
+---------------------------+---------------+----------------------------------------------------+
| NPU Name | Health | Power(W) Temp(C) Hugepages-Usage(page)|
| Chip Phy-ID | Bus-Id | AICore(%) Memory-Usage(MB) HBM-Usage(MB) |
+===========================+===============+====================================================+
| 7 Ascend910 | OK | 165.1 45 0 / 0 |
| 0 14 | 0000:0B:00.0 | 0 0 / 0 59623/ 65536 |
+---------------------------+---------------+----------------------------------------------------+
| 7 Ascend910 | OK | - 44 0 / 0 |
| 1 15 | 0000:0A:00.0 | 0 0 / 0 59380/ 65536 |
+===========================+===============+====================================================+
| NPU Chip | Process id | Process name | Process memory(MB) |
+===========================+===============+====================================================+
| 7 0 | 344520 | VLLMWorker_TP | 56565 |
| 7 1 | 344521 | VLLMWorker_TP | 56565 |
+===========================+===============+====================================================+运行命令:
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"MusaCoder-27B","messages":[{"role":"user","content":"Write a Python function to compute Fibonacci numbers using dynamic programming."}],"temperature":0.7,"max_tokens":512}'输出(Stage B 真实权重):
{
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "We are going to write a function that calculates the nth Fibonacci number using dynamic programming. The Fibonacci sequence is defined as: F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) for n >= 2.\\n\\nWe can use dynamic programming to avoid recalculating the same values multiple times...",
"refusal": null
},
"finish_reason": "length"
}],
"usage": {"prompt_tokens": 23, "completion_tokens": 512, "total_tokens": 535}
}性能: 512 tokens in 64.5s → 7.94 tokens/s
运行命令:
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"MusaCoder-27B","messages":[{"role":"user","content":"def quicksort(arr):\\n \\"\\"\\"Sort an array using quicksort algorithm.\\"\\"\\"\\n "}],"temperature":0.7,"max_tokens":256}'输出(Stage B 真实权重):
{
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "We are going to implement the quicksort algorithm. Steps:\\n 1. If the array has 0 or 1 element, it is already sorted.\\n 2. Otherwise, choose a pivot (we will choose the middle element for simplicity)...",
"refusal": null
},
"finish_reason": "length"
}],
"usage": {"prompt_tokens": 26, "completion_tokens": 256, "total_tokens": 282}
}性能: 256 tokens in 34.2s → 7.48 tokens/s
运行命令:
curl -s http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"MusaCoder-27B","messages":[{"role":"user","content":"What are the main differences between Python and C++? List at least 5 key differences."}],"temperature":0.7,"max_tokens":512}'输出(Stage B 真实权重):
{
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "We are going to list at least 5 key differences between Python and C++. Let's think about the major aspects: compilation, typing, memory management, performance, and syntax.\\n\\n1. **Compilation vs Interpretation**: C++ is compiled; Python is interpreted...",
"refusal": null
},
"finish_reason": "length"
}],
"usage": {"prompt_tokens": 29, "completion_tokens": 512, "total_tokens": 541}
}性能: 512 tokens in 73.5s → 6.96 tokens/s



qwen3_5 模型类型--enforce-eager 跳过preprocessor_config.json 和 tokenizer 文件