部署文本生成模型
本指南将指导您如何在不同芯片架构的算力实例上部署文本生成大模型。我们将以 Qwen3 系列模型为例,重点介绍 Hugging Face Transformers、vLLM 和 SGLang 三种主流推理框架的部署流程。
推理框架概览
- Hugging Face Transformers:最基础、灵活的框架,适合快速原型设计、算法研究和微调。
- vLLM:专为生产环境设计的高吞吐量推理引擎,支持 PagedAttention,适合高并发服务。
- SGLang:针对复杂结构化生成(如 CoT、JSON 约束)优化的高性能引擎。
一、沐曦 (MetaX) 部署指南
本章节适用于 曦云 C500 等沐曦系列算力卡。
1. Hugging Face Transformers
1.1 环境准备
- 算力型号:曦云 C500 (64GB)
- 镜像选择:
PyTorch / 2.4.0 / Python 3.10 / maca 3.0.0.4

1.2 部署步骤
-
启动实例后,点击 JupyterLab 进入工作台。

-
新建一个
.ipynb(Notebook) 文件。
-
安装依赖:在第一个单元格运行以下命令。安装完成后,请务必重启内核 (Restart Kernel) 以使环境生效。
pip install accelerate
-
运行推理代码:沐曦环境支持直接加载挂载盘中的内置模型,无需下载。
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch
# 指定内置模型库路径 (无需下载)
model_name = "/mnt/moark-models/Qwen3-0.6B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
prompt = "Give me a short introduction to large language model."
messages = [{"role": "user", "content": prompt}]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
enable_thinking=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=32768
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
try:
index = len(output_ids) - output_ids[::-1].index(151668) # </think>
except ValueError:
index = 0
thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=True).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=True).strip("\n")
print("=== Thinking ===")
print(thinking_content)
print("\n=== Response ===")
print(content)执行结果示例:

2. vLLM 高性能推理
2.1 环境准备
- 镜像选择:
vLLM / vllm:0.10.0 / Python 3.10 / maca 3.1.0.7(注:请务必选择带有 vLLM 标识的专用镜像)

2.2 启动服务
-
通过 JupyterLab 打开终端 (Terminal)。
-
执行以下命令启动兼容 OpenAI 接口的服务:
# 使用内置模型路径,指定端口 8188
vllm serve /mnt/moark-models/Qwen3-0.6B --port 8188
-
当看到
Uvicorn running on http://0.0.0.0:8188字样时,服务启动成功。
3. SGLang 结构化推理
3.1 环境准备
- 镜像选择:
SgLang / sglang:0.4.8 / Python 3.10 / maca 3.1.0.8

3.2 启动服务
-
通过 JupyterLab 打开终端 (Terminal)。
-
执行以下命令启动服务:
# SGLang 启动命令
python -m sglang.launch_server \
--model-path /mnt/moark-models/Qwen3-0.6B \
--port 8188
-
服务启动成功界面:

二、燧原 (Enflame) 部署指南
本章节适用于 S60 等燧原系列算力卡。由于架构差异,部分操作需引入适配库。
1. Hugging Face Transformers
1.1 环境准备
- 算力型号:Enflame S60
- 镜像选择:
Ubuntu / 22.04 / Python 3.13 / ef 1.5.0.604

1.2 部署步骤
-
启动实例后,进入 JupyterLab。

-
新建一个
.ipynb(Notebook) 文件。
-
代码迁移关键点:必须在代码最前方引入
torch_gcu库。import torch
import torch_gcu
from torch_gcu import transfer_to_gcu
from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "/mnt/moark-models/Qwen3-0.6B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
prompt = "Explain quantum computing in simple terms."
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=512)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
response = tokenizer.decode(output_ids, skip_special_tokens=True)
print(response)