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=, add_generation_prompt=)
model_inputs = tokenizer([text], return_tensors=).to(model.device)
generated_ids = model.generate(**model_inputs, max_new_tokens=)
output_ids = generated_ids[][(model_inputs.input_ids[]):].tolist()
content = tokenizer.decode(output_ids, skip_special_tokens=)
(, content)

