EADST

Qwen3.6-27B 深度技术解读

基于 HuggingFace 模型卡、官方博客材料的技术拆解

资料来源标注:

  • [1] HuggingFace 模型卡

  • [2] 官方博客

  • [3] config.json

  • [4] model.safetensors.index.json


1. TL;DR

  • 定位 [2]:Qwen3.6 家族第 3 款开源模型(继 Qwen3.6-Plus、Qwen3.6-35B-A3B 之后),Dense 27B 多模态,支持 thinking / non-thinking 双模式。
  • 性能突破 [2]:在所有主流 Agentic Coding Benchmark 上反超上一代旗舰 Qwen3.5-397B-A17B(激活 17B 的 MoE)——SWE-bench Verified 77.2 vs 76.2、SWE-bench Pro 53.5 vs 50.9、Terminal-Bench 2.0 59.3 vs 52.5。
  • 架构惊喜 [3]:不是传统 Transformer。layer_types 显式交替排布 linear_attention × 3 + full_attention × 1,64 层共 48 层线性注意力 + 16 层全注意力,属于 Hybrid Linear/Full Attention 架构(Mamba-2 + Transformer 混合)。
  • 上下文 [3]:原生 max_position_embeddings = 262144(256K),rope_theta = 10_000_000
  • 权重体积 [4]total_size = 55.56 GB bf16,分 15 个 safetensors 分片,反推参数量约 27.78 B。

2. 模型概览

| 项           | 值                                                                  | 来源    |
|--------------|---------------------------------------------------------------------|---------|
| 发布方       | Qwen Team / Alibaba Cloud                                           | [2]     |
| 模型定位     | Dense 多模态(文本 + 视觉 + 视频)                                   | [2][3]  |
| 架构类名     | Qwen3_5ForConditionalGeneration                                     | [3]     |
| 模型类型     | qwen3_5(config 的 model_type 仍为 3_5,说明 3.6 与 3.5 共享实现)  | [3]     |
| 权重精度     | bfloat16                                                            | [3]     |
| Thinking     | 支持 preserve_thinking                                              | [2]     |
| 开源渠道     | HuggingFace / ModelScope / 阿里云 Model Studio / Qwen Studio       | [2]     |
| 官方卖点     | "Dense 27B 首次在 Agentic Coding 全面超越 397B-A17B MoE"           | [2]     |

3. 架构与参数(核心)

3.1 关键超参(来自 config.json text_config [3]

| 超参                      | 值              | 说明                                                     |
|---------------------------|-----------------|----------------------------------------------------------|
| hidden_size               | 5120            | 主干隐层宽度                                             |
| num_hidden_layers         | 64              | 语言塔总层数                                             |
| intermediate_size         | 17408           | FFN 中间维                                               |
| num_attention_heads       | 24              | 查询头数(仅用于 full_attention 层)                     |
| num_key_value_heads       | 4               | KV 头数 → GQA 比 6:1                                     |
| head_dim                  | 256             | 单头维度(24×256 = 6144 ≠ hidden,走独立 QKV proj)      |
| vocab_size                | 248320          | 包含视觉/视频特殊 token                                  |
| tie_word_embeddings       | false           | Embed 与 LM Head 独立权重                                |
| max_position_embeddings   | 262144          | 原生 256K 上下文                                         |
| rope_theta                | 10_000_000      | 超大基频支撑长上下文                                     |
| partial_rotary_factor     | 0.25            | 仅 25% 维度走 RoPE                                       |
| rms_norm_eps              | 1e-6            | RMSNorm                                                  |
| hidden_act                | silu            | SwiGLU FFN                                               |
| attn_output_gate          | true            | 注意力输出门控(非标准 Transformer)                     |
| mtp_num_hidden_layers     | 1               | Multi-Token Prediction 头,提升推理吞吐                  |

3.2 混合注意力模式(最关键差异点)

layer_types 字段显式给出 64 层排布 [3]

[linear × 3, full × 1] × 16 = 64 层
= 48 层 Linear Attention (Mamba/SSM 风格) + 16 层 Full Attention
  • full_attention_interval = 4:每 4 层插入 1 层 Full Attention
  • Linear Attention 子模块(来自 safetensors weight map [4]):
  • conv1d.weightlinear_conv_kernel_dim = 4
  • A_logdt_biasin_proj_ain_proj_b → 典型 Mamba-2 / Gated Linear Attention 实现
  • linear_num_key_heads = 16linear_num_value_heads = 48linear_key_head_dim = linear_value_head_dim = 128
  • Full Attention 子模块:标准 GQA,Q 24 头 / KV 4 头,head_dim 256,配 partial RoPE + MRoPE(mrope_interleaved = truemrope_section = [11, 11, 10] 用于多模态位置编码)

3.3 视觉塔(vision_config [3]

| 项                  | 值                                             |
|---------------------|------------------------------------------------|
| depth               | 27 层 ViT                                      |
| hidden_size         | 1152                                           |
| intermediate_size   | 4304                                           |
| num_heads           | 16                                             |
| patch_size          | 16                                             |
| temporal_patch_size | 2                                              |
| spatial_merge_size  | 2                                              |
| out_hidden_size     | 5120(与语言塔对齐)                           |
| 支持 token          | image_token_id=248056, video_token_id=248057   |

3.4 架构结构图

Qwen3.6-27B  (Qwen3_5ForConditionalGeneration, bf16)
│  # 总参数 ≈27.78B, 总权重 55.56GB, 15 shards
│
├─ Vision Tower (ViT, depth=27, hidden=1152)  ──▶ [B, N_patch, 5120]
│   └─ patch=16, temporal_patch=2, spatial_merge=2
│
├─ Tokenizer (BPE, vocab=248320, 含 image/video 特殊 token)
│
├─ Embedding                                  ──▶ [B, S, 5120]
│
├─ LanguageModel × 64 layers   (Hybrid: 48 Linear + 16 Full)
│   │   # 模式: [L,L,L,F] × 16, full_attention_interval=4
│   │
│   ├─ [Linear Attention Layer] × 48
│   │   ├─ RMSNorm                            [B, S, 5120]
│   │   ├─ in_proj_a / in_proj_b
│   │   ├─ Conv1d (kernel=4)
│   │   ├─ SSM Kernel (A_log, dt_bias)        # Mamba-2 风格
│   │   │    key_heads=16, value_heads=48, head_dim=128
│   │   ├─ Output Gate (swish)                # attn_output_gate=true
│   │   ├─ Residual (+)
│   │   ├─ RMSNorm
│   │   └─ SwiGLU FFN (inter=17408)
│   │       └─ Residual (+)
│   │
│   └─ [Full Attention Layer] × 16  (每 4 层 1 个)
│       ├─ RMSNorm
│       ├─ GQA Self-Attention
│       │   ├─ Q proj   ──▶ [B,S, 24, 256]
│       │   ├─ K proj   ──▶ [B,S,  4, 256]
│       │   ├─ V proj   ──▶ [B,S,  4, 256]
│       │   ├─ MRoPE (partial=0.25, θ=1e7, sections=[11,11,10])
│       │   └─ O proj + output gate           ──▶ [B,S, 5120]
│       ├─ Residual (+)
│       ├─ RMSNorm
│       └─ SwiGLU FFN (inter=17408)
│           └─ Residual (+)
│
├─ Final RMSNorm
├─ MTP Head (mtp_num_hidden_layers=1)         # 推理加速
└─ LM Head (tie=false)                        ──▶ [B, S, 248320]

3.5 与 Qwen2.5 / Qwen3 的关键差异

  1. Qwen2.5 / Qwen3 是纯 Transformer;Qwen3.6-27B 引入 Mamba 系线性注意力,是 Qwen 系列首次大规模混合架构开源落地。
  2. 上下文从 Qwen2.5 的 32K / Qwen3 的 128K 跃升到 256K 原生,依赖混合架构降低长序列显存压力。
  3. 引入 MTP(Multi-Token Prediction),类似 DeepSeek-V3,用于推测解码。
  4. 注意力输出门控 attn_output_gate=true,非标准 Transformer 设计。
  5. MRoPE(多模态旋转位置编码)配合 partial_rotary_factor=0.25,只对 25% 维度做旋转。

4. 权重与显存

4.1 实测数据(来自 model.safetensors.index.json [4]

  • total_size:55,562,855,904 bytes ≈ 55.56 GB(bf16)
  • 分片数:15 个 .safetensors
  • 反推参数量:55.56 GB / 2 byte ≈ 27.78 B
  • LM Head 位于 model-00008-of-00015.safetensors(不与 embed 共享)

4.2 推理显存估算

| 精度             | 权重      | 256K KV Cache*          | 单卡最低要求                     |
|------------------|-----------|-------------------------|----------------------------------|
| bf16             | ~55.6 GB  | ~16 GB(混合架构降低)  | 2×H100 80G / 2×H20 96G           |
| int8 (GPTQ/AWQ)  | ~28 GB    | ~8 GB                   | 1×H100 80G                       |
| int4 (GPTQ/AWQ)  | ~14 GB    | ~4 GB                   | 1×A100 40G / 1×RTX 4090×2        |

* KV cache 估算基于 16 层 full attention × 4 KV head × 256 head_dim × 2(K+V)× 2 byte × seq_len;线性注意力层只需常数状态,显存节省显著。

4.3 官方推理配置 [1]

  • SGLang:支持 --context-length 262144 --reasoning-parser qwen3 --speculative-algo NEXTN(即用 MTP 做 Speculative Decoding),推荐 --tp-size 8
  • vLLMvllm >= 0.19.0

5. 训练与对齐

  • 上下文长度:原生 256K,无需 YaRN [1][3]
  • 双模式采样参数 [1]
  • Thinking:temperature=0.6, top_p=0.95, top_k=20
  • Non-Thinking:temperature=0.7, top_p=0.80, top_k=20, presence_penalty=1.5
  • 推荐输出长度:常规 32K,竞赛级 81,920 tokens [1]
  • Agent 能力:官方支持 preserve_thinking,可保留多轮 thinking 内容 [2]
  • 后训练细节:博客未披露具体 SFT / RL 配方,待官方 Technical Report

6. 官方性能([2] 摘录)

| Benchmark              | Qwen3.6-27B | Qwen3.5-397B-A17B | Gemma4-31B | Claude 4.5 Opus |
|------------------------|-------------|-------------------|------------|-----------------|
| SWE-bench Verified     | 77.2        | 76.2              | 52.0       | 80.9            |
| SWE-bench Pro          | 53.5        | 50.9              | 35.7       | 57.1            |
| SWE-bench Multilingual | 71.3        | 69.3              | 51.7       | 77.5            |
| Terminal-Bench 2.0     | 59.3        | 52.5              | 42.9       | 59.3            |
| SkillsBench Avg5       | 48.2        | 30.0              | 23.6       | 45.3            |
| QwenWebBench           | 1487        | 1186              | 1197       | 1536            |
| GPQA Diamond           | 87.8        | --                | --         | --              |
| VideoMME (w sub.)      | 87.7        | 87.5              | 77.7       | 86.6            |
| CountBench             | 97.8        | 97.2              | 96.1       | 90.6            |

关键观察:27B Dense 在 Agentic Coding 维度上全面超越自家 397B MoE,且与 Claude 4.5 Opus 仅差 3-4 分。视觉与视频理解方面同样保持第一梯队。


7. 值得深挖的 5 个技术点

7.1 Hybrid Linear/Full Attention 为什么成立

Mamba 类线性注意力的弱点是全局信息检索能力差(无法像 softmax attention 那样在任意 token 间建立强关联)。Qwen3.6-27B 的方案是每 4 层保留 1 层 Full Attention 做全局路由,其余 3 层用 Linear Attention 做廉价序列建模。这种 3:1 混合比是社区近期的经验最优解(见 Jamba、Zamba-2、Samba 等工作),Qwen 首次在 27B 量级 + 256K 上下文规模上开源验证。

7.2 attn_output_gate = true 的隐含设计

传统 Transformer 的注意力输出直接经 o_proj 残差相加。Qwen3.6 在输出端额外加了一个 sigmoid/swish 门控,类似 Gated Attention Unit(GAU) 思路。这一改动对训练稳定性和长序列外推性能有显著贡献,是 Qwen 技术报告值得追读的点。

7.3 MTP(Multi-Token Prediction)如何省成本

mtp_num_hidden_layers = 1 意味着有一个额外的 Decoder 层专门预测"下一个 token 的下一个 token",训练时做 auxiliary loss,推理时作为 draft model 做 Speculative Decoding(SGLang 的 --speculative-algo NEXTN 即对应此机制)。实测可把 throughput 提升 1.5-2×,这是 DeepSeek-V3 率先验证、Qwen3.6 跟进的主流方案。

7.4 256K 上下文的显存奇迹

如果用纯 Transformer,256K × 64 层 × 4 KV head × 256 head_dim × bf16 ≈ 17 GB KV cache 起步。Qwen3.6-27B 只有 16 层 full attention,其余 48 层是常数状态的 Linear Attention,KV cache 实际占用降到纯 Transformer 的 ~25%。这是长上下文商业化的关键工程突破。

7.5 model_type = qwen3_5 的陷阱

配置里 model_type 仍然标成 qwen3_5,而不是 qwen3_6。这说明 3.6 没有新增模型类,仍复用 3.5 的实现。旧版 transformers 可能误识别为纯 Transformer,必须锁定 transformers >= 4.57.1,否则会丢失 Linear Attention / MTP / attn_output_gate 等关键分支。


8. 部署与生态

  • 官方推理框架:SGLang(推荐,原生 NEXTN Speculative Decoding)、vLLM ≥ 0.19.0
  • 量化:尚未看到官方 GPTQ/AWQ 发布,需等待社区;注意 Mamba SSM 对低比特量化敏感,int4 可能掉点明显
  • 微调工具链pefttrl 对 Linear Attention 层的 LoRA 注入配方尚不成熟,社区 target_modules 设定待验证
  • 第三方集成 [2]:OpenClaw、Claude Code、Qwen Code 等编码助手已原生支持
  • License:博客未明示,以 HuggingFace Repo 内 LICENSE 为准

9. 未解答的 Open Questions

  1. 开源 License 具体条款(Apache-2.0 / Qwen License / 其他)?
  2. 是否发布配套 Technical Report,披露 SFT/RL 数据配方与 Hybrid 层比例的消融实验?
  3. Linear Attention 层的官方 LoRA 推荐 target_modules 是什么?
  4. MTP 头在下游 SFT 时是否需要同步训练,还是可冻结?
  5. 256K 上下文下 Full Attention KV cache 的官方裁剪/滑窗策略?

10. 结语

Qwen3.6-27B 是 Qwen 开源路线的一次激进升级——把「Hybrid Attention + 长上下文 + MTP + 多模态」四张牌一次性打出来,同时在 Agentic Coding 上用 27B Dense 掀翻 397B MoE。对开源社区的意义不止于一个新 checkpoint,更在于把 Mamba 系混合架构的工业级验证从 7B/13B 推到了 27B/256K 量级

相关标签
About Me
XD
Goals determine what you are going to be.
Category
标签云
Google Docker AI Jetson torchinfo Tensor BeautifulSoup 净利润 Pytorch scipy Claude Password Color Linux Jupyter XML Qwen2.5 GoogLeNet Git API logger Website 关于博主 TSV Bipartite Template Qwen2 Quantization CAM SAM uwsgi Datetime Input Streamlit DeepSeek LaTeX git Food 云服务器 Heatmap CEIR CSV Plate DeepStream Cloudreve WAN Permission TensorFlow Ubuntu Augmentation Breakpoint 音频 PDF 域名 报税 LLAMA InvalidArgumentError Tracking SQLite Firewall NameSilo WebCrawler Review ChatGPT Translation HaggingFace Pillow Pandas GPTQ PIP Paddle v0.dev Hungarian QWEN Tiktoken tqdm Zip Animate CC Pickle FP64 证件照 printf Interview 飞书 Hilton Bitcoin PyTorch Github Plotly LLM XGBoost Hotel diffusers Card NLTK NLP MD5 Mixtral Logo 财报 Excel Search v2ray Proxy Numpy OpenAI Bin 论文速读 Domain YOLO OpenCV Base64 ResNet-50 Web RGB FlashAttention 阿里云 CTC 第一性原理 GPT4 FP32 TTS PDB ModelScope 论文 Diagram hf Django Conda 搞笑 Crawler mmap LoRA llama.cpp Magnet 递归学习法 Use 腾讯云 FastAPI Distillation Vim transformers Algorithm Rebuttal Sklearn Disk PyCharm Transformers 强化学习 Land IndexTTS2 COCO VSCode git-lfs Miniforge C++ Freesound icon Baidu News 图形思考法 ONNX JSON LeetCode Nginx BTC SPIE Knowledge RAR HuggingFace 算法题 Video UI Statistics CV Attention 多进程 Paper 版权 VGG-16 Quantize 继承 Michelin tar GGML UNIX SVR CUDA CLAP Windows Python 顶会 多线程 uWSGI FP16 Qwen Data Gemma GIT BF16 Markdown 公式 Dataset Anaconda Bert Agent Clash OCR 签证 Math Vmess 图标 TensorRT Shortcut EXCEL Safetensors Ptyhon Llama VPN Random SQL FP8 Image2Text
站点统计

本站现有博文327篇,共被浏览830694

本站已经建立2535天!

热门文章
文章归档
回到顶部