Qwen3-0.6B 推理使用说明
本目录包含基于 Axera NPU (AX650) 的 Qwen3-0.6B/1.7B, Qwen2.5-VL-3B, Qwen3-VL-2B 模型推理脚本。
文件说明
| 文件名 | 说明 |
|---|---|
infer_qwen3-0.6b.py |
Qwen3-0.6B 单次推理脚本 |
infer_ppl_qwen3-0.6b.py |
Qwen3-0.6B 困惑度(PPL)计算脚本 |
环境要求
硬件
- AX650 NPU 开发板
- M4N-Dock (爱芯派Pro)
软件
- Python 3.10
axengine- Axera NPU 推理引擎transformers- HuggingFace transformers 库ml_dtypes- bfloat16 数据类型支持tqdm- 进度条显示
安装依赖
-
刷系统
从https://pan.baidu.com/e/1-r6V352TIN8eqiFEIsUQoA?pwd=yskz下载系统镜像,并参考m4n刷系统进行系统烧录。
我使用的系统镜像名称为:
AX650_pipro_box_ubuntu_rootfs_desktop_V3.6.2_20250603154858_20250626183459.axp -
安装python依赖
bash
pip install whl/axengine-0.1.3-py3-none-any.whl
pip install -r whl/requirements.txt
模型准备
1. 获取原始模型
从 modelscope axera 下载模型
使用方法
1. 基本用法
bash
# 使用默认问题
python3 infer_qwen3-0.6b.py
# 指定自定义问题
python3 infer_qwen3-0.6b.py --question "你好,请介绍一下你自己"
# 指定模型路径
python3 infer_qwen3-0.6b.py \
--hf_model /path/to/qwen3_tokenizer \
--axmodel_path /path/to/qwen3-0.6b-ax650 \
--question "今天天气怎么样?"
2. 运行示例
bash
$ python3 infer_qwen3-0.6b.py
[INFO] Available providers: ['AxEngineExecutionProvider']
embeds dtype: bfloat16, embeds shape: (151936, 1024)
Init InferenceSession: 0%| | 0/28 [00:00<?, ?it/s][INFO] Using provider: AxEngineExecutionProvider
[INFO] Chip type: ChipType.MC50
[INFO] VNPU type: VNPUType.DISABLED
[INFO] Engine version: 2.12.0s
[INFO] Model type: 2 (triple core)
[INFO] Compiler version: 4.2 329f2f69
.
.
.
Init InferenceSession: 100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 28/28 [00:12<00:00, 2.30it/s]
[INFO] Using provider: AxEngineExecutionProvider
[INFO] Model type: 2 (triple core)
[INFO] Compiler version: 4.2 329f2f69
inputs:[NodeArg(name='input', dtype='bfloat16', shape=[1, 1, 1024])] outputs: [NodeArg(name='output', dtype='bfloat16', shape=[1, 1, 151936])]
model load done!
prefill token_len: 51
> /media/root/my_sdcard/1_aigc/axera_qwen2.5-1.5B-Instruct-python/infer_qwen3-0.6b.py(134)<module>()
-> input_prefill_len = 128
(Pdb) c
slice_indexs is [0]
slice prefill done 0
answer >> <think>
好的,用户问的是"你知道 `床前明月光,疑是地上霜`是谁写的吗?"。首先,我需要确认用户的问题是否正确,因为这句诗确实出自李白的《静夜思》。用户可能对这首诗的作者不太熟悉,或者想确认其出处。
接下来,我需要检查诗句的正确性。床前明月光,疑是地上霜,确实是李白的名句,出自《静夜思》。用户可能是在学习中文诗歌,或者在寻找诗句的出处,所以需要准确回答。
然后,考虑到用户可能需要更多信息,比如这首诗的背景或作者的生平,但问题只问了作者是谁,所以保持简洁回答即可。同时,要确保回答符合用户的要求,即保持人畜无害的AI助手形象,不带任何额外信息。
最后,确认回答的准确性,避免错误,比如确认诗句的正确出处,确保用户得到正确的信息。这样用户的问题就能得到准确的回答,同时保持对话的友好和专业。
</think>
参数说明
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
--hf_model |
str | /media/root/my_sdcard/1_aigc/Qwen3-0.6B/qwen3_tokenizer |
HuggingFace tokenizer 路径 |
--axmodel_path |
str | /media/root/my_sdcard/1_aigc/Qwen3-0.6B/qwen3-0.6b-ax650 |
Axera axmodel 路径 |
--question |
str | "你知道 床前明月光,疑是地上霜是谁写的吗?" |
用户问题 |