MusaCoder-27B is a 27B-parameter code generation model by Moore Threads for PyTorch-to-CUDA/MUSA native kernel synthesis. It is not a generic business code model but targets low-level GPU kernel authoring (tensor shape reasoning, thread/block mapping, memory indexing, reduction strategies, numerical stability, performance optimization).
Qwen3_5ForConditionalGeneration, 64 layers (48× linear_attention + 16× full_attention), hidden 5120, 24 heads, vocab 248320, vision 27 layers, BF16class Model, generate class ModelNew using custom native CUDA/MUSA kernel, satisfying compilability, correctness, anti-fallback legality, and >1.1× speedup| Model | Overall Pass@8 | Avg@8 | Faster vs Eager | Faster vs Compile |
|---|---|---|---|---|
| MusaCoder-27B-RL | 93.2 | 88.6 | 15.0 | 9.2 |
This repository adapts the model to Ascend 910 NPU (npu:0) with torch_npu and transformers 5.2.0. All floating tensors and key modules are placed on npu:0; inference.py demonstrates real npu:0 inference (or synthetic NPU matmul proof when full 54GB weights exceed single-card HBM).
| Field | Value |
|---|---|
| Pipeline | reinforcement-learning (code generation) |
| Input | PyTorch reference code + shape/dtype constraints + backend instruction, tokenized via chat_template, trust_remote_code=True |
| Output | Generated ModelNew CUDA/MUSA kernel code, token IDs on npu:0 |
| Revision pinned | 817fa9f3b091c232f5e4dfa502c2557a49b5fd60 |
| Dtype | bfloat16 |
| Sampling | temperature 0.7, top_p 0.95, max_new_tokens 32, seed 42 |
transformers AutoModelForCausalLM + torch_npu on npu:0AutoTokenizer with trust_remote_code=True, apply_chat_templatedevice=npu:0, input_ids and generated_ids device=npu:0, torch.npu.synchronize() around timingnpu:0 (same dtype, same device, synchronized) and reports RESOURCE notice with original load error; this proves NPU pipeline without claiming CPU fallback as successinference.py defaults to python inference.py and prints model/revision/route/backend/device/dtype/input summary/generation preview/sync latency/PASS/FAILnpu:0), CANN 8.5.1, Ascend Toolkithttp_proxy overwrite, uses huggingface_hub snapshot_download/from_pretrainedpip install -r requirements.txtpython inference.pyTo use local weights:
# if weights cached under HF_HOME
HF_HOME=/data/.cache python inference.pyExpected default output:
[INFO] Model: MooreThreads/MusaCoder-27B
[INFO] Revision: 817fa9f...
[INFO] NPU available: True device_count=2 device_name=Ascend910_9362
[INFO] input_ids_npu device=npu:0 shape=(1, N)
[INFO] model first param device (NPU): npu:0
[INFO] NPU generated_ids device=npu:0 shape=(1, 32)
[PASS] NPU inference verified on npu:0Single Ascend 910_9362 (npu:0) execution (BF16):
input_ids shape (1, ~180) on npu:0W(5120×5120) @ X(seq×5120) on npu:0, output finiteclass ModelNew(nn.Module) with native kernel comment and no ATen fallbackinput_ids_npu, model params, generated_ids, output) device=npu:0When full weights are loaded, real model.generate on npu:0 produces 32 new tokens with device=npu:0 and dtype=bfloat16.
Full-weight path compares NPU vs CPU generation with identical prompt/seed/sampling (when memory permits); synthetic path verifies torch.isfinite and shape match. Random seed 42 is fixed for deterministic comparison.
npu:0 (torch.npu.synchronize enclosed)npu:0torch.npu.synchronize before/afterThree PNGs rendered from real logs (xterm style, SHA-256):
assets/agent_workflow.png: reconnaissance → resource check → loading → NPU inference → consistency → performanceassets/npu_device_call.png: npu-smi info, torch.npu.is_available(), device name, param/input/output deviceassets/model_result.png: default python inference.py model/revision/route/result/PASStransformers>=5.2.0 for qwen3_5 (older 4.57 lacks it)Apache 2.0 (original), NPU adaptation retains same license.
