微型随机 LlamaForCausalLM(llama,2 层,隐藏维度 16,词表 32000,约 1M 参数)适配 Huawei Ascend 910B npu:0,采用贪心解码。
hmellor/tiny-random-LlamaForCausalLMLlamaForCausalLM(model_type: llama)model.safetensors),fp32/bfloat16,AutoModelForCausalLMLlamaTokenizerFast(配合 AutoTokenizer)pip install -r requirements.txt
# Ensure weights are at /tmp/hmellor-tiny (auto-download fallback to HF mirror if missing)
python inference.py
python inference.py --mode validate
python inference.py --mode benchmark默认运行 3 条固定 prompt,贪心 max_new_tokens=16、do_sample=False,校验 CPU 与 NPU 的 token ids 和 logits。
Hello, my name is(6 tokens)The capital of France is(6 tokens)Once upon a time(5 tokens)add_bos_token=True,padding 回退使用 pad_token=<unk>torch.npu.is_available(): True(Ascend910_9362,device_count=2,目标 npu:0)next(model.parameters()).device == npu:0input_ids.device == npu:0,attention_mask.device == npu:0logits.device == npu:0,且 generate 输出的 device == npu:0torch.npu.synchronize(),首次运行单独包含编译实际运行(npu:0,float32,贪心):
model device (next param): npu:0
input_ids device CPU: cpu -> NPU: npu:0
output device: npu:0 shape (1, 22) etc.
CPU token ids == NPU token ids: True (all 3 prompts)
logits max_diff: ~1e-07 (fp32) < 1e-3 threshold
NPU decoded example: "Hello, my name is sogonnes^iginomer banроз efficient ..." (random tiny model)~1.04e-07 - 1.49e-07(fp32)<< 1e-3。text-generation(task-adaptation 路线)下的 token ids exact match。generate 前后调用 torch.npu.synchronize()。94.83 ms(32 tokens)93.33 ms 最大值:102.80 ms p50:94.09 ms p90/p95:102.80 ms~337 tokens/s(320 tokens / 0.948s)60.82 GiB / 61.27 GiB(微型模型开销可忽略)npu:0;无需多卡(1M 参数)。assets/agent_workflow.png – 工作流程 / 仓库结构assets/npu_device_call.png – torch.npu.is_available() 及设备验证assets/model_result.png – CPU 与 NPU Token ids 及性能

模型卡自动生成;继承上游许可证。