# Qwen3.5
## 论文
[Qwen3.5](https://qwen.ai/blog?id=qwen3.5)
## 模型简介
Qwen3.5 通过异构基础设施实现高效的原生多模态训练:在视觉与语言组件上解耦并行策略,避免统一方案带来的低效。利用稀疏激活实现跨模块计算重叠,在混合文本-图像-视频数据上相比纯文本基线达到近 100% 的训练吞吐。在此基础上,原生 FP8 流水线对激活、MoE 路由与 GEMM 运算采用低精度,并通过运行时监控在敏感层保持 BF16,实现约 50% 的激活显存降低与超过 10% 的加速,并稳定扩展至数万亿 token。
为了持续释放强化学习的潜力,构建了可扩展的异步强化学习框架,支持 Qwen3.5 全尺寸模型,并全面覆盖文本、多模态及多轮交互场景。通过训推分离架构的解耦式设计,该框架显著提升了硬件利用率,实现了动态负载均衡和细粒度的故障恢复。配合 FP8 训推、Rollout 路由回放、投机采样以及多轮 Rollout 锁定等技术,进一步优化了系统吞吐,提高了训推一致性。通过系统与算法协同设计,该框架在严格控制样本陈旧性的基础上有效缓解了数据长尾问题,提高了训练曲线的稳定性和性能上限。此外,框架面向原生智能体工作流设计,能够实现稳定、无缝的多轮环境交互,消除了框架层的调度中断。这种解耦设计使得系统能够扩展百万级规模的 Agent 脚手架与环境,从而显著增强模型的泛化能力。上述优化最终取得了 3×–5× 的端到端加速,展现了卓越的稳定性、高效率与可扩展性。
## 环境依赖
| 软件 | 版本 |
| :------: |:-----------------------------------------:|
| DTK | 26.04 |
| python | 3.10.12 |
| transformers | 5.8.0 |
| vllm | 0.18.1+das.dtk2604 |
| triton | 3.6.0+das.opt1.dtk2604 |
| torch | 2.10.0+das.opt1.dtk2604 |
| SGLang | 0.5.10rc0+das.opt2.alpha.dtk2604 |
- **vLLM当前仅支持定制镜像:** : harbor.sourcefind.cn:5443/dcu/admin/base/custom:vllm0.18.1-ubuntu22.04-dtk26.04-py3.10-20260510-2242
- **SGLang推理请使用:** harbor.sourcefind.cn:5443/dcu/admin/base/custom:sglang0.5.10rc0-ubuntu22.04-dtk26.04-py3.10-20260518
- 挂载地址`-v` 根据实际模型情况修改
```bash
docker run -it \
--shm-size 200g \
--network=host \
--name qwen3.5 \
--privileged \
--device=/dev/kfd \
--device=/dev/dri \
--device=/dev/mkfd \
--group-add video \
--cap-add=SYS_PTRACE \
--security-opt seccomp=unconfined \
-u root \
-v /opt/hyhal/:/opt/hyhal/:ro \
-v /path/your_code_data/:/path/your_code_data/ \
harbor.sourcefind.cn:5443/dcu/admin/base/custom:vllm0.18.1-ubuntu22.04-dtk26.04-py3.10-20260510-2242 bash
```
更多镜像可前往[光源](https://sourcefind.cn/#/service-list)下载使用。
关于本项目DCU显卡所需的特殊深度学习库可从[光合](https://developer.sourcefind.cn/tool/)开发者社区下载安装。
## 预训练权重
**请根据`支持的DCU型号`选择对应模型下载,FP8模型仅在BW1100/BW1101上支持,其他型号请勿使用!**
| 模型名称 | 权重大小 | 数据类型 | 支持的DCU型号 | 最低卡数需求 | 下载地址 |
|:------:|:----:|:----------:|:----------:|:------:|:---------------------:|
| Qwen3.5-397B-A17B | 397B | BF16 | K100AI,BW1000 | 16 | [Hugging Face](https://huggingface.co/Qwen/Qwen3.5-397B-A17B) |
| Qwen3.5-397B-A17B-INT8 | 397B | INT8 | BW1000 | 8 | [ModelScope](https://www.modelscope.cn/models/metax-tech/Qwen3.5-397B-A17B-W8A8) |
| Qwen3.5-122B-A10B | 122B | BF16 | K100AI,BW1000 | 8 | [Hugging Face](https://huggingface.co/Qwen/Qwen3.5-122B-A10B) |
| Qwen3.5-35B-A3B | 35B | BF16 | K100AI,BW1000 | 2 | [Hugging Face](https://huggingface.co/Qwen/Qwen3.5-35B-A3B) |
| Qwen3.5-27B | 27B | BF16 | K100AI,BW1000 | 2 | [Hugging Face](https://huggingface.co/Qwen/Qwen3.5-27B) |
| Qwen3.5-9B | 9B | BF16 | K100AI,BW1000 | 1 | [Hugging Face](https://huggingface.co/Qwen/Qwen3.5-9B) |
| Qwen3.5-4B | 4B | BF16 | K100AI,BW1000 | 1 | [Hugging Face](https://huggingface.co/Qwen/Qwen3.5-4B) |
| Qwen3.5-2B | 2B | BF16 | K100AI,BW1000 | 1 | [Hugging Face](https://huggingface.co/Qwen/Qwen3.5-2B) |
| Qwen3.5-0.8B | 0.8B | BF16 | K100AI,BW1000 | 1 | [Hugging Face](https://huggingface.co/Qwen/Qwen3.5-0.8B) |
## 数据集
暂无
## 训练
暂无
## 推理
> 如果出现`ImportError: librocm_smi64.so.2: cannot open shaned object file: No such file or directory`报错,系机器hyhal版本较低所致,请进行升级。
### vLLM
#### 单机推理
##### BF16
**mtp**功能需添加以下参数:
```
--speculative-config.method mtp \
--speculative-config.num_speculative_tokens 2
```
```bash
# serve启动
vllm serve Qwen/Qwen3.5-35B-A3B \
--port 8001 \
--trust-remote-code \
--dtype bfloat16 \
--tensor-parallel-size 2 \
--gpu-memory-utilization 0.925 \
--default-chat-template-kwargs '{"enable_thinking": false}' \
--reasoning-parser qwen3 \
--enable-auto-tool-choice \
--tool-call-parser qwen3_coder
# client访问
curl http://localhost:8001/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3.5-35B-A3B",
"messages": [
{"role": "user", "content": "Type \"I love Qwen3.5\" backwards"}
],
"temperature": 0.6
}'
```
#### 多机推理
1. 加入环境变量
> 请注意:
> 每个节点上的环境变量都写到.sh文件中,保存后各个计算节点分别source`.sh`文件
>
> VLLM_HOST_IP:节点本地通信口ip,尽量选择IB网卡的IP,**避免出现rccl超时问题**
>
> NCCL_SOCKET_IFNAME和 GLOO_SOCKET_IFNAME:节点本地通信网口ip对应的名称
>
> 通信口和ip查询方法:ifconfig
>
> IB口状态查询:ibstat !!!一定要active激活状态才可用,各个节点要保持统一
```bash
export ALLREDUCE_STREAM_WITH_COMPUTE=1
export VLLM_HOST_IP=x.x.x.x # 对应计算节点的IP,选择IB口SOCKET_IFNAME对应IP地址
export NCCL_SOCKET_IFNAME=ibxxxx
export GLOO_SOCKET_IFNAME=ibxxxx
export NCCL_IB_HCA=mlx5_x:1 # 环境中的IB网卡名字
unset NCCL_ALGO
export NCCL_MIN_NCHANNELS=16
export NCCL_MAX_NCHANNELS=16
export NCCL_NET_GDR_READ=1
export HIP_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
export VLLM_RPC_TIMEOUT=1800000
# 海光CPU绑定核
export VLLM_NUMA_BIND=1
export VLLM_RANK0_NUMA=0
export VLLM_RANK1_NUMA=1
export VLLM_RANK2_NUMA=2
export VLLM_RANK3_NUMA=3
export VLLM_RANK4_NUMA=4
export VLLM_RANK5_NUMA=5
export VLLM_RANK6_NUMA=6
export VLLM_RANK7_NUMA=7
```
2. 启动RAY集群
> x.x.x.x 对应第一步 VLLM_HOST_IP
```bash
# head节点执行
ray start --head --node-ip-address=x.x.x.x --port=6379 --num-gpus=8 --num-cpus=32
# worker节点执行
ray start --address='x.x.x.x:6379' --num-gpus=8 --num-cpus=32
```
3. 启动vllm server
```bash
# serve启动
vllm serve Qwen/Qwen3.5-397B-A17B \
--port 8001 \
--tensor-parallel-size 16 \
--distributed-executor-backend ray \
--trust-remote-code \
--dtype bfloat16 \
--gpu-memory-utilization 0.925 \
--default-chat-template-kwargs '{"enable_thinking": false}' \
--reasoning-parser qwen3 \
--enable-auto-tool-choice \
--tool-call-parser qwen3_coder
# client访问
curl http://localhost:8001/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3.5-397B-A17B",
"messages": [
{"role": "user", "content": "Type \"I love Qwen3.5\" backwards"}
],
"temperature": 0.6
}'
```
### SGLang
#### 单机推理
##### BF16
1. serve启动,以`Qwen3.5-35B-A3B`为例(此命令适用于非K100AI芯片)
```bash
export SGLANG_ENABLE_SPEC_V2=1
export SGLANG_USE_FUSED_TOPK_SOFTMAX=1
export SGLANG_USE_LIGHTOP=1
export SGLANG_USE_CAUSAL_CONV1D=1
export SGLANG_USE_AITER_LINEAR_ATTN=1
export SGLANG_USE_CUDA_IPC_TRANSPORT=1
sglang serve --model-path Qwen/Qwen3.5-35B-A3B \
--attention-backend fa3 \
--mm-attention-backend fa3 \
--enable-piecewise-cuda-graph \
--tp-size 1 --pp-size 1 \
--page-size 64 \
--mem-fraction-static 0.95 \
--mamba-scheduler-strategy extra_buffer \
--kv-cache-dtype fp8_e5m2 \
--trust-remote-code \
--chunked-prefill-size -1 --context-length 8192
```
2. serve启动,以`Qwen3.5-35B-A3B`为例(此命令适用于K100AI芯片)
```bash
export SGLANG_ENABLE_SPEC_V2=1
export SGLANG_USE_FUSED_TOPK_SOFTMAX=1
export SGLANG_USE_LIGHTOP=1
export SGLANG_USE_CAUSAL_CONV1D=1
export SGLANG_USE_AITER_LINEAR_ATTN=1
export SGLANG_USE_CUDA_IPC_TRANSPORT=1
export HIP_VISIBLE_DEVICES=4,5,6,7
export SGLANG_KV_LAYOUT_DCU_FA=0
sglang serve --model-path Qwen/Qwen3.5-35B-A3B \
--attention-backend fa3 \
--mm-attention-backend fa3 \
--disable-cuda-graph \
--tp-size 2 --pp-size 1 \
--page-size 64 \
--mem-fraction-static 0.9 \
--kv-cache-dtype bf16 \
--trust-remote-code \
--chunked-prefill-size -1 \
--disable-radix-cache \
```
2. client访问
```bash
curl http://localhost:8001/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3.5-35B-A3B",
"messages": [
{"role": "user", "content": "Type \"I love Qwen3.5\" backwards"}
],
"temperature": 0.8,
"chat_template_kwargs": {
"enable_thinking": true
}
}'
```
## 效果展示
### 精度
- 推理框架: SGLang
- 测试数据: humaneval、gsm8k
- 使用的加速卡: BW1000
| model name| humaneval | gsm8k |
| :------: | :------: | :------: |
| Qwen3.5-27B | 0.92 | 0.98 |
| Qwen3.5-35B-A3B | 0.92 | 0.98 |
| Qwen3.5-122B-A10B | 0.93 | 0.98 |
## 源码仓库及问题反馈
- https://developer.sourcefind.cn/codes/modelzoo/qwen3.5
## 参考资料
- https://github.com/QwenLM/Qwen3.5