Qwen · HF · 通义

呵

Qwen3.8-27B-FP8

Qwen3.8-27B-FP8

二〇二六年九月八日 · 英文原文

Qwen 团队发布 Qwen3.8-27B-FP8,为 27B 参数视觉语言模型的 FP8 量化版本,采用块大小 128 的细粒度量化,兼容 Hugging Face Transformers、vLLM、SGLang 与 TokenSpeed。模型原生支持图像与视频理解,上下文长度 262,144 tokens,可扩展至 1M。在 Terminal Bench 2.1、SWE-bench Pro、OSWorld-Verified 等 benchmark 上得分分别为 73.0、61.7、84.3。

Qwen3.8-27B-FP8

[!Note] 本仓库包含后训练模型的 FP8 量化模型权重和配置文件,格式为 Hugging Face Transformers。

这些产物兼容 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.8 基于 Qwen3.5 的架构基础构建,在编码、专业工作、研究和长周期 agentic 任务方面均实现了显著提升。Qwen3.8-27B 将这些进步带入了紧凑、易于部署的密集模型中:一个原生支持图像和视频理解的视觉语言模型,具备灵活的思考控制,旨在以更高的可靠性完成复杂、多步骤的任务。

Qwen3.8 亮点

Qwen3.8-27B 具有以下增强功能:

模型概览

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,可用于调整推理深度并控制成本:

此外,preserve_thinking 默认对所有工作负载启用,以提供最佳的开箱即用体验。如需禁用保留思考,请参阅此处的示例。

[!Tip] 在多轮 agentic 任务中,较低的推理 effort 并不总能减少整体任务完成时间。虽然它可能产生更快的单轮响应,但也可能导致分析不足、更多失败和重复重试,从而增加总延迟和 token 消耗。

Chat Completions API

Chat Completions API 可与大多数推理框架以及 Qwen Cloud 一起使用。 开始前,请确保已安装 OpenAI Python SDK,并配置好 API key 和 API base 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 中。

最佳实践

为获得最佳性能,我们建议以下设置:

  1. 采样参数:我们建议使用以下采样参数组合:

    • 思考模式: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 之间以减少无休止的重复。但使用较高值偶尔可能导致语言混合和模型性能轻微下降。

  2. 充足的输出长度:为优化 agentic 任务的性能,我们建议分配足够的输出长度,使模型能够生成详细且全面的响应。对于支持为内部推理和最终输出分别设置 token 限制的框架,我们建议在 1M 上下文长度内进行以下配置:

    • 推理内容:将最大输出长度设置为 262,144 tokens。
    • 最终响应:将最大输出长度设置为 131,072 tokens。

    这些设置为复杂推理提供了必要的能力,同时为高质量最终交付物保留了充足空间。

  3. 处理超长文本: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。

  4. 长视频理解:为优化纯文本和图像的推理效率,发布的 video_preprocessor_config.json 中的 size 参数配置较为保守。建议将 video_preprocessor_config 文件中的 longest_edge 参数设置为 469,762,048(对应 224k 视频 tokens),以支持小时级视频的更高帧率采样,从而获得更优性能。例如,

    {"longest_edge": 469762048, "shortest_edge": 4096}
    

    或者,通过引擎启动参数覆盖默认值。实现细节请参阅:vLLM / SGLang。

引用

如果您觉得我们的工作有帮助,欢迎引用我们。

@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}
}
译自 Qwen · HF · 通义 · 录于 二〇二六年九月八日