Qwen3.8-27B-FP8
Qwen3.8-27B-FP8
Qwen团队发布Qwen3.8-27B-FP8,为27B参数视觉语言模型,原生支持图像和视频理解,上下文长度262,144 tokens,可扩展至1M。模型采用块大小128的细粒度FP8量化,兼容Hugging Face Transformers、vLLM、SGLang和TokenSpeed。在SWE-bench Pro、DeepSWE 1.1、OSWorld-Verified等benchmark上超越Qwen3.6-27B和Qwen3.7-Plus,支持思考模式控制、reasoning_effort调节及preserve_thinking功能。
Qwen3.8-27B-FP8
[!Note] 本仓库包含后训练模型在 Hugging Face Transformers 格式下的 FP8 量化模型权重和配置文件。
这些产物与 Hugging Face Transformers、vLLM、SGLang、TokenSpeed 等兼容。
量化方法为块大小为 128 的细粒度 FP8 量化,其性能指标与原模型几乎一致。
[!Tip] 对于需要托管式、可扩展推理且无需维护基础设施的用户,官方 Qwen API 服务由 Qwen Cloud 提供。
特别是,Qwen3.8-27B 将作为托管版本提供,并具备更多生产级特性,例如默认 1M 上下文长度、官方内置工具。更多信息请参阅 Qwen3.8-27B 概览。该服务即将推出,敬请关注更新。
继 Qwen3.5 和 Qwen3.6 系列获得社区广泛采用之后,我们很高兴推出 Qwen3.8,这是迄今为止 Qwen 开源模型家族中能力最强的一代。
基于 Qwen3.5 的架构基础,Qwen3.8 在编程、专业工作、研究以及长周期 agentic 任务方面均实现了显著提升。Qwen3.8-27B 将这些进步带入了紧凑、易于部署的密集模型中:一个原生支持图像和视频理解的视觉语言模型,具备灵活的思考控制,旨在以更高的可靠性完成复杂、多步骤的任务。
Qwen3.8 亮点
Qwen3.8-27B 具备以下增强功能:
- 核心能力:在编程、专业工作、研究以及长周期 agentic 任务方面全面改进。
- Agent 执行:更强的自主规划能力和对环境反馈的更好处理,从而实现更可靠的端到端任务完成。
- 下游兼容性:更广泛地支持流行的 harness 和开发工具,使其更容易集成到您现有的技术栈中。
- 灵活的思考控制:思考模式默认开启,可根据请求单独禁用;推理深度可通过
reasoning_effort调整,历史消息中的推理上下文可通过preserve_thinking保留。 - 视觉语言理解:原生支持图像和视频理解,涵盖从 STEM 图表、文档到小时级视频。
模型概览
- 类型:带视觉编码器的因果语言模型
- 训练阶段:预训练与后训练
- 语言模型
- 参数量:27B
- 隐藏维度:5120
- Token 嵌入:248,320(已填充)
- 层数:64
- 隐藏层布局:16 × (3 × (Gated DeltaNet → FFN) → 1 × (Gated Attention → FFN))
- Gated DeltaNet:
- 线性注意力头数:V 为 48,QK 为 16
- 头维度:128
- Gated Attention:
- 注意力头数:Q 为 24,KV 为 4
- 头维度:256
- 旋转位置嵌入维度:64
- 前馈网络:
- 中间维度:17,408
- LM 输出:248,320(已填充)
- MTP(多 Token 预测):经过多步训练
- 上下文长度:原生 262,144,可扩展至 1,000,000 tokens。
Benchmark 结果
文本性能
VL 性能
快速开始
为简化集成,我们建议通过 API 使用 Qwen3.8。
部署 Qwen3.8
[!Important] 不同框架的推理效率和吞吐量差异显著。 我们建议使用最新版本的框架,以确保最佳性能和兼容性。 对于生产工作负载或高吞吐量场景,建议使用专用 serving 引擎,如 SGLang、vLLM 或 TokenSpeed。
Qwen3.8 可以使用流行的推理框架部署,例如:
API 使用
[!Important] Qwen3.8 模型默认以思考模式运行,在生成最终回复之前会生成以
<think>\n...</think>\n\n标记的思考内容。 要禁用思考内容并直接获取回复,请参阅此处的示例。
[!Tip] 我们建议使用以下采样参数集进行生成:
- 思考模式:
temperature=1.0、top_p=0.95、top_k=20、min_p=0.0、presence_penalty=0.0、repetition_penalty=1.0- Instruct(或非思考)模式:
temperature=0.7、top_p=0.80、top_k=20、min_p=0.0、presence_penalty=1.5、repetition_penalty=1.0请注意,采样参数的支持情况因推理框架而异。
Qwen3.8 官方支持 reasoning_effort,可用于调整推理深度并控制成本:
xhigh(默认):适用于需要深入分析的复杂任务medium:在准确性和速度之间取得平衡low:针对速度和成本优化的高效推理
此外,preserve_thinking 默认对所有工作负载启用,以提供最佳的开箱即用体验。要禁用保留思考,请参阅此处的示例。
[!Tip] 在多轮 agentic 任务中,较低的推理 effort 并不总能减少整体任务完成时间。虽然它可能产生更快的单轮响应,但也可能导致分析不足、更多失败和重复重试,从而可能增加总延迟和 token 消耗。
Chat Completions API
Chat Completions API 可与大多数推理框架以及 Qwen Cloud 一起使用。 开始之前,请确保已安装 OpenAI Python SDK,并配置好 API 密钥和 API 基础 URL,例如:
pip install -U openai
# 根据实际情况设置以下内容
export OPENAI_BASE_URL='your-base-url'
export OPENAI_API_KEY='your-api-key'
纯文本输入
from openai import OpenAI
# 通过环境变量配置
client = OpenAI()
messages = [{"role": "user", "content": "Write a Python function to merge two sorted linked lists."}]
completion = client.chat.completions.create(
model="Qwen/Qwen3.8-27B-FP8",
messages=messages,
extra_body={
"chat_template_kwargs": {
"enable_thinking": True, # 默认开启
"preserve_thinking": True, # 默认开启
},
},
reasoning_effort="xhigh", # 默认为 xhigh;支持级别为 xhigh、medium 和 low
stream=True,
stream_options={"include_usage": True},
)
reasoning_content = ""
answer_content = ""
is_answering = False
print("\n" + "=" * 20 + "Reasoning" + "=" * 20 + "\n")
for chunk in completion:
if not chunk.choices:
print("\nUsage:")
print(chunk.usage)
continue
delta = chunk.choices[0].delta
if hasattr(delta, "reasoning_content") and delta.reasoning_content is not None:
if not is_answering:
print(delta.reasoning_content, end="", flush=True)
reasoning_content += delta.reasoning_content
elif hasattr(delta, "reasoning") and delta.reasoning is not None:
if not is_answering:
print(delta.reasoning, end="", flush=True)
reasoning_content += delta.reasoning
if hasattr(delta, "content") and delta.content:
if not is_answering:
print("\n" + "=" * 20 + "Answer" + "=" * 20 + "\n")
is_answering = True
print(delta.content, end="", flush=True)
answer_content += delta.content
messages.append({
"role": "assistant",
"content": answer_content,
"reasoning_content": reasoning_content,
"reasoning": reasoning_content,
})
图像输入
from openai import OpenAI
# 通过环境变量配置
client = OpenAI()
messages = [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3.5/demo/CI_Demo/mathv-1327.jpg"
}
},
{
"type": "text",
"text": "The centres of the four illustrated circles are in the corners of the square. The two big circles touch each other and also the two little circles. With which factor do you have to multiply the radii of the little circles to obtain the radius of the big circles?\nChoices:\n(A) $\\frac{2}{9}$\n(B) $\\sqrt{5}$\n(C) $0.8 \\cdot \\pi$\n(D) 2.5\n(E) $1+\\sqrt{2}$"
}
]
}
]
chat_response = client.chat.completions.create(
model="Qwen/Qwen3.8-27B-FP8",
messages=messages,
)
print("Chat response:", chat_response)
视频输入
from openai import OpenAI
# 通过环境变量配置
client = OpenAI()
messages = [
{
"role": "user",
"content": [
{
"type": "video_url",
"video_url": {
"url": "https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3.5/demo/video/N1cdUjctpG8.mp4"
}
},
{
"type": "text",
"text": "How many porcelain jars were discovered in the niches located in the primary chamber of the tomb?"
}
]
}
]
chat_response = client.chat.completions.create(
model="Qwen/Qwen3.8-27B",
messages=messages,
)
# 当 vLLM 以 `--media-io-kwargs '{"video": {"num_frames": -1}}'` 启动时,
# 视频帧采样可通过 `extra_body` 配置(例如,通过设置 `fps`)。
# 此功能目前仅在 vLLM 中支持。
#
# 默认情况下,`fps=2` 且 `do_sample_frames=True`。
# 当 `do_sample_frames=True` 时,您可以自定义 `fps` 值来设置所需的视频采样率。
# chat_response = client.chat.completions.create(
# model="Qwen/Qwen3.8-27B-FP8",
# messages=messages,
# extra_body={
# "mm_processor_kwargs": {"fps": 2, "do_sample_frames": True},
# },
# )
print("Chat response:", chat_response)
Instruct(或非思考)模式
Qwen3.8-27B 在响应前默认会进行思考。 您可以通过配置 API 参数来获取模型的直接响应,而无需思考。 例如,
from openai import OpenAI
# 通过环境变量配置
client = OpenAI()
messages = [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://qianwen-res.oss-accelerate.aliyuncs.com/Qwen3.5/demo/RealWorld/RealWorld-04.png"
}
},
{
"type": "text",
"text": "Where is this?"
}
]
}
]
chat_response = client.chat.completions.create(
model="Qwen/Qwen3.8-27B-FP8",
messages=messages,
temperature=0.7,
top_p=0.8,
presence_penalty=1.5,
extra_body={
"top_k": 20,
"chat_template_kwargs": {"enable_thinking": False},
},
)
print("Chat response:", chat_response)
[!Note] 如果您使用的是 Qwen Cloud 的 API,除了更改
model之外,请直接使用"enable_thinking": False,而不是"chat_template_kwargs": {"enable_thinking": False}。
禁用保留思考
默认情况下,Qwen3.8 会保留所有历史消息中的思考块,从而在对话中维持完整的推理轨迹。这种行为称为保留思考,可确保完整的上下文连续性,对于决策一致性和减少冗余推理至关重要的 agent 场景尤其有益。它还能改善 KV cache 利用率,在思考和非思考模式下均优化推理效率。
如果您希望仅保留最新用户消息中的思考块,可以通过将 preserve_thinking 设置为 False 来禁用此行为:
from openai import OpenAI
# 通过环境变量配置
client = OpenAI()
messages = [...]
chat_response = client.chat.completions.create(
model="Qwen/Qwen3.8-27B-FP8",
messages=messages,
extra_body={
"chat_template_kwargs": {"preserve_thinking": False},
},
)
print("Chat response:", chat_response)
[!Note] 如果您使用的是 Qwen Cloud 的 API,除了更改
model之外,请直接使用"preserve_thinking": False,而不是将其包装在chat_template_kwargs中。
最佳实践
为获得最佳性能,我们建议以下设置:
采样参数:我们建议使用以下采样参数集:
- 思考模式:
temperature=1.0、top_p=0.95、top_k=20、min_p=0.0、presence_penalty=0.0、repetition_penalty=1.0 - Instruct(或非思考)模式:
temperature=0.7、top_p=0.80、top_k=20、min_p=0.0、presence_penalty=1.5、repetition_penalty=1.0
对于支持的框架,您可以将
presence_penalty参数调整到 0 到 2 之间,以减少无休止的重复。然而,使用较高的值偶尔可能导致语言混合和模型性能轻微下降。- 思考模式:
充足的输出长度:为优化 agentic 任务的性能,我们建议分配足够的输出长度,使模型能够生成详细且全面的响应。对于支持为内部推理和最终输出分别设置 token 限制的框架,我们建议在 1M 上下文长度内进行以下配置:
- 推理内容:将最大输出长度设置为 262,144 tokens。
- 最终响应:将最大输出长度设置为 131,072 tokens。
这些设置为复杂推理提供了必要的能力,同时为高质量最终交付物确保了充足的空间。
处理超长文本:Qwen3.8-27B 原生支持最长 262,144 tokens 的上下文长度。对于总长度(包括输入和输出)超过此限制的长周期任务,我们建议使用 RoPE 缩放技术来有效处理长文本,例如 YaRN。
YaRN 目前受多种推理框架支持,例如 vLLM、SGLang 和 TokenSpeed。 通常,对于支持的框架,启用 YaRN 有两种方法:
修改模型配置文件:
在
config.json文件中,将text_config中的rope_parameters字段更改为:{ "mrope_interleaved": true, "mrope_section": [ 11, 11, 10 ], "rope_type": "yarn", "rope_theta": 10000000, "partial_rotary_factor": 0.25, "factor": 4.0, "original_max_position_embeddings": 262144, }传递命令行参数:
对于 vLLM,您可以使用
VLLM_ALLOW_LONG_MAX_MODEL_LEN=1 vllm serve ... --hf-overrides '{"text_config": {"rope_parameters": {"mrope_interleaved": true, "mrope_section": [11, 11, 10], "rope_type": "yarn", "rope_theta": 10000000, "partial_rotary_factor": 0.25, "factor": 4.0, "original_max_position_embeddings": 262144}}}' --max-model-len 1000000对于 SGLang,您可以使用
SGLANG_ALLOW_OVERWRITE_LONGER_CONTEXT_LEN=1 python -m sglang.launch_server ... --json-model-override-args '{"text_config": {"rope_parameters": {"mrope_interleaved": true, "mrope_section": [11, 11, 10], "rope_type": "yarn", "rope_theta": 10000000, "partial_rotary_factor": 0.25, "factor": 4.0, "original_max_position_embeddings": 262144}}}' --context-length 1000000对于 TokenSpeed,您可以使用
TOKENSPEED_ALLOW_OVERWRITE_LONGER_CONTEXT_LEN=1 tokenspeed serve ... --hf-overrides '{"text_config": {"rope_parameters": {"mrope_interleaved": true, "mrope_section": [11, 11, 10], "rope_type": "yarn", "rope_theta": 10000000, "partial_rotary_factor": 0.25, "factor": 4.0, "original_max_position_embeddings": 262144}}}' --max-model-len 1000000
[!NOTE] 所有知名的开源框架都实现了静态 YaRN,这意味着缩放因子不随输入长度变化,可能影响较短文本上的性能。 我们建议仅在需要处理长上下文时才修改
rope_parameters配置。 还建议根据需要修改factor。例如,如果您的应用典型上下文长度为 524,288 tokens,最好将factor设置为 2.0。长视频理解:为优化纯文本和图像的推理效率,发布的
video_preprocessor_config.json中的size参数配置较为保守。建议将 video_preprocessor_config 文件中的longest_edge参数设置为 469,762,048(对应 224k 视频 tokens),以便对小时级视频启用更高帧率采样,从而获得更优性能。例如,{"longest_edge": 469762048, "shortest_edge": 4096}
引用
如果您觉得我们的工作有帮助,欢迎引用我们。
@misc{qwen38,
title = {{Qwen3.8-Max}: A New Bar for Coding and Cowork},
url = {https://qwen.ai/blog?id=qwen3.8},
author = {{Qwen Team}},
month = {August},
year = {2026}
}