本仓库包含 LiquidAI/LFM2-8B-A1B 模型在 华为昇腾 NPU 上的适配补丁和配置文件。
| 参数 | 值 |
|---|---|
| 原始模型 | LiquidAI/LFM2-8B-A1B |
| 架构类型 | lfm2_moe (Lfm2MoeForCausalLM) |
| 参数量 | 8B |
| 专家数 | 32 |
| 激活专家数 | 4 |
| Hidden Size | 2048 |
| 最大上下文 | 128K |
本适配解决了以下昇腾 NPU 兼容性问题:
| 检查项 | 状态 |
|---|---|
| NPU 驱动 | ✓ PASS |
| PyTorch NPU | ✓ PASS |
| vLLM 安装 | ✓ PASS |
| vllm-ascend 安装 | ✓ PASS |
| 补丁 | 状态 |
|---|---|
| forward_native 补丁 | ✓ PASS |
| causal_conv1d 替换 | ✓ PASS |
| short_conv op 注册 | ✓ PASS |
| 测试 | 状态 |
|---|---|
| ShortConv 导入 | ✓ PASS |
| ShortConv 类可用 | ✓ PASS |
| 模型配置加载 | ✓ PASS |
使用相同输入文本,分别在 GPU 和 昇腾 NPU 上运行推理,对比输出结果。
| 输入 | GPU 输出 | NPU 输出 | 精度误差 |
|---|---|---|---|
| "The capital of France is" | Paris | [待测试] | [待测试] |
| "1 + 1 equals" | 2 | [待测试] | [待测试] |
| "The largest planet is" | Jupiter | [待测试] | [待测试] |
⚠️ 精度误差目标: < 1%
python benchmark/precision_verify.py详细精度对比报告见: docs/precision_report.json
| 指标 | 值 |
|---|---|
| P50 延迟 | [待测试] ms |
| P90 延迟 | [待测试] ms |
| P99 延迟 | [待测试] ms |
| 指标 | 值 |
|---|---|
| QPS | [待测试] req/s |
| 成功率 | [待测试] % |
python benchmark/perf_benchmark.py详细性能报告见: docs/perf_report.json
推理正常输出的截图证据放在 screenshots/ 目录:
screenshots/
├── dummy_startup.png # 模型加载/启动截图
├── inference_1.png # 推理测试截图1
├── inference_2.png # 推理测试截图2
└── inference_3.png # 推理测试截图3⚠️ 请将推理正常输出的截图上传到此目录
运行推理:
python inference.py --prompt "The capital of France is"预期输出:
输入: The capital of France is
输出: Paris
[耗时: XXXms, tokens: X]MODEL_NAME/
├── inference.py # 推理脚本
├── readme.md # 本文件
├── prompts.jsonl # 测试提示词
├── patch_lfm2_moe.py # 核心适配补丁
├── model_config.yaml # 模型配置
├── run_lfm2_moe_ascend.sh # 服务启动脚本
├── benchmark/
│ ├── precision_verify.py # 精度验证脚本
│ └── perf_benchmark.py # 性能基准脚本
├── scripts/
│ └── setup_env.sh # 环境安装脚本
├── docs/
│ └── 昇腾适配测评报告.md # 详细测评报告
├── logs/
│ ├── dummy_startup.log # 启动日志
│ └── inference.log # 推理日志
└── screenshots/ # 截图证据(请上传)bash scripts/setup_env.shbash run_lfm2_moe_ascend.sh# 单条推理
python inference.py --prompt "Hello, how are you?"
# 交互式推理
python inference.py --interactive
# 批量推理
python inference.py --batch prompts.jsonl --output results.jsonpython benchmark/precision_verify.pypython benchmark/perf_benchmark.py本适配代码遵循 Apache 2.0 许可证。模型本身受 LiquidAI 原许可证约束。
适配版本: 2026-05-20