DCU BW1000 环境下 llama.cpp 推理 Qwen3-Coder 模型失败分析
环境评估
使用 llmfit 查看模型信息:
llmfit info stelterlab/Qwen3-Coder-30B-A3B-Instruct-AWQ
输出显示该模型为 MoE 架构,推荐量化格式为 Q8_0,默认 Q4_K_M。在 DCU BW1000 上运行需考虑显存限制,当前配置建议 CPU+GPU 混合模式。
安装 llama.cpp
克隆源代码:
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
cmake -B build
cmake --build build --config Release
编译完成后添加路径:
export PATH=/root/llama.cpp/build/bin:$PATH
若直接执行 make install 后报错提示缺少共享库(如 libmtmd.so.0),通常是因为未正确设置环境变量。确认路径加入后问题可解决。
模型下载
安装 ModelScope 并下载模型:
pip install modelscope
from modelscope import snapshot_download
snapshot_download('tclf90/Qwen3-Coder-30B-A3B-Instruct-AWQ', cache_dir="models")
推理尝试
使用 llama-cli
llama-cli -m models/tclf90/Qwen3-Coder-30B-A3B-Instruct-AWQ
报错信息显示无法读取模型文件魔数(magic)或加载失败。经排查,可能是模型路径或文件格式与 llama.cpp 预期不匹配。目标模型 stelterlab/Qwen3-Coder-30B-A3B-Instruct-AWQ 在部分仓库中可能不可用。
使用 transformers
尝试通过 Hugging Face Transformers 加载:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "/root/models/tclf90/Qwen3-Coder-30B-A3B-Instruct-AWQ"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
prompt = "Write a quick sort algorithm."
messages = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(**model_inputs, max_new_tokens=65536)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
content = tokenizer.decode(output_ids, skip_special_tokens=True)
print("content:", content)
运行时报错:
ImportError: Loading an AWQ quantized model requires gptqmodel. Please install it with `pip install gptqmodel`
尝试安装依赖:
pip install gptqmodel
构建失败,提示无法检测 torch 版本。尝试 conda 安装也报错包不可用:
PackagesNotFoundError: The following packages are not available from current channels:
- gptqmodel
总结
实验未能成功完成,主要原因如下:
- llama.cpp:模型文件路径或格式不匹配,导致加载失败。
- Transformers:AWQ 量化模型依赖
gptqmodel库,但在当前环境中无法安装该依赖,且可能存在 PyTorch 版本兼容性问题。
后续需调整量化方案或更换支持当前硬件的模型版本。

