liuhongwei-2026/tiny-random-LlamaForCausalLM
Model Introduction
Files & versions
Pull Requests
Discussion
Analysis

hmellor/tiny-random-LlamaForCausalLM on Ascend NPU

模型适配 · 自然语言处理(NLP)· 因果语言模型 · vLLM-Ascend 服务化推理 · 昇腾 NPU

Beta 版本头信息

{hardware NPU}

1. 简介

  • 模型来源: hmellor/tiny-random-LlamaForCausalLM(AtomGit 镜像: https://ai.gitcode.com/hf_mirrors/hmellor/tiny-random-LlamaForCausalLM)
  • 模型类型: LlamaForCausalLM decoder-only 因果语言模型,基于 Llama 架构的极小随机权重版本,适用于文本生成 pipeline 验证、架构测试、CI 集成等场景。
  • 参数量: 1.06M(2 层 Transformer decoder,hidden_size=16,4 个注意力头,head_dim=64,intermediate_size=64,vocab=32000,max_position_embeddings=8192)
  • 分词器: Llama BPETokenizer(tokenizer.json)
  • 适配状态: SUCCESS
  • 适配说明: 为标准 LlamaForCausalLM 架构,采用 vLLM-Ascend(vLLM 昇腾后端插件)在本机昇腾 NPU 上完成零改造适配:直接加载官方 safetensors 权重,通过 OpenAI 兼容 API(/v1/completions)提供服务化推理,无需修改任何模型代码。
  • 适配时间: 2026-08-18
  • 硬件: {hardware NPU} Ascend 910B(torch_npu 2.9.0.post1,NPU 0)

2. 验证环境

组件版本
python3.11.14
torch2.9.0
torch-npu2.9.0.post1
vllm0.18.0
vllm-ascend0.18.0
transformers4.57.6
CANN8.5.1
NPUAscend 910B (Ascend910_9362) × 2(本次部署使用 NPU 0)
权重hmellor/tiny-random-LlamaForCausalLM(model.safetensors bf16 → vLLM 按 float16 加载,2.1 MB)

3. 适配方案

tiny-random-LlamaForCausalLM 是 LlamaForCausalLM 标准架构,vLLM 原生支持(llm_arch = LlamaForCausalLM), vLLM-Ascend 0.18.0 通过 VLLM_TARGET_DEVICE=ascend 自动激活昇腾平台插件,在 NPU 上 加载权重并完成 KV-cache 分配与推理,代码零改动。

关键启动参数(见 inference.py):

参数取值说明
--model本地权重路径 / HF repo id指定模型
--dtypefloat16权重精度
--max-model-len128最大上下文长度
--gpu-memory-utilization0.2显存/内存占用比例
--device-ids0使用的 NPU 设备号
--enforce-eager—关闭 graph 编译,保证开箱即用

注:本环境因 --model 位置参数不会覆盖 vLLM 内部默认模型(Qwen/Qwen3-0.6B), 脚本中必须显式传 --model,否则会尝试回连 huggingface.co。

4. 部署与使用

4.1 拉取权重

# 方式一:AtomGit 镜像(gitcode.com)
git clone https://gitcode.com/hf_mirrors/hmellor/tiny-random-LlamaForCausalLM.git

# 方式二:hf-mirror 镜像
HF_ENDPOINT=https://hf-mirror.com python -c "
from huggingface_hub import snapshot_download
snapshot_download('hmellor/tiny-random-LlamaForCausalLM', local_dir='./tiny-random-LlamaForCausalLM')
"

4.2 安装依赖

pip install -r requirements.txt

4.3 启动服务化推理

# 前台启动 OpenAI 兼容服务(默认端口 8000)
python inference.py --model /path/to/tiny-random-LlamaForCausalLM --port 8000 --device-ids 0

服务启动后提供:

  • GET /v1/models 模型列表/健康检查
  • POST /v1/completions 文本生成

4.4 客户端调用示例

# 健康检查
python inference.py --health --port 8000

# 自检生成
python inference.py --test --port 8000

# 或直接用 curl
curl http://localhost:8000/v1/completions \
  -H 'Content-Type: application/json' \
  -d '{"model":"tiny-random-LlamaForCausalLM","prompt":"The capital of France is","max_tokens":16,"temperature":0}'

4.5 离线快速验证(不起服务)

python inference.py --offline --model /path/to/tiny-random-LlamaForCausalLM

5. 服务化推理验证(NPU 实测)

5.1 离线生成(vLLM-Ascend 直接推理)

PROMPT : The capital of France is
OUTPUT :  Var populated kilometerзда moins합 meer weitiginomer clészewломNonMessages polynomialsantsåстWORD Legнаügelized

PROMPT : Machine learning is
OUTPUT :  sogonnes IN Fight explaografieoscidis Aer Р到 країelihoodчник Professional gru neighb\   Unit especie Stuart %cureno nuncaincludegraphics Sydneystabshow$). guessing

注:此模型为随机初始化权重(非训练版),输出为随机 token,属于正常现象。

5.2 OpenAI 兼容服务

/v1/models:

{"object":"list","data":[{"id":"tiny-random-LlamaForCausalLM","object":"model",
"created":1787028478,"owned_by":"vllm",
"root":"/opt/atomgit/models/hmellor/tiny-random-LlamaForCausalLM","parent":null,
"max_model_len":128,"permission":[...]}]}

/v1/completions:

PROMPT : The capital of France is
OUTPUT :  Var populated kilometerзда moins합 meer weitiginomer clészewломNonMessages polynomialsantsåстWORD Legнаügelized广Whodisragment volte miniotti vulner
USAGE  : prompt_tokens=6  completion_tokens=32

5.3 模型加载关键日志

INFO 08-21 07:24:53 [model_runner_v1.py:2565] Starting to load model /opt/atomgit/models/hmellor/tiny-random-LlamaForCausalLM...
INFO 08-21 07:24:53 [default_loader.py:384] Loading weights took 0.01 seconds
INFO 08-21 07:24:54 [model_runner_v1.py:2592] Loading model weights took 0.0049 GB
INFO 08-21 07:24:56 [worker.py:357] Available KV cache memory: 12.21 GiB
INFO:     Application startup complete.

6. 证据截图

截图素材待补充(assets/ 目录):

截图说明
assets/agent_workflow.png适配/部署流程图
assets/npu_device_call.pngNPU 设备调用截图(npu-smi info / 日志中的 NPU 状态)
assets/model_result.png模型推理结果截图(completions 返回)

7. 参考

  • 官方模型卡: https://huggingface.co/hmellor/tiny-random-LlamaForCausalLM
  • 镜像仓库: https://ai.gitcode.com/hf_mirrors/hmellor/tiny-random-LlamaForCausalLM
  • 适配仓库: https://ai.atomgit.com/liuhongwei-2026/tiny-random-LlamaForCausalLM