
OpenAI 发布了两个开源语言模型:gpt-oss-120b 和 gpt-oss-20b。这是 OpenAI 自 GPT-2 以来首次公开授权的 LLM。其目标是创建最先进的推理和工具使用模型。这些模型一经推出便在 AI 社区引起了广泛关注。
OpenAI 开源 gpt-oss,允许人们在 Apache 2.0 的框架内自由使用和调整。这两个模型无疑为专业个性化和定制技术以适应本地上下文任务提供了一种民主的方法。在本指南中,我们将介绍如何访问 gpt-oss-120b 和 gpt-oss-20b,以及何时使用哪个模型。
gpt-oss有何特别之处?
OpenAI 的全新开放权重模型是自 GPT-2 以来最强大的公开模型。它采用最先进系统的最新方法,旨在真正发挥作用,易于使用和调整。
- 开放的 Apache 2.0 许可证:gpt-oss 模型都是完全开放权重的模型,并根据宽松的 Apache 2.0 许可证进行许可。这意味着不存在版权限制,开发者可以将它们用于研究或商业产品,无需支付许可费用或承担源代码义务。
- 可配置的推理级别:一个独特的功能是可以轻松配置模型的推理强度:低、中或高。这是速度与深度之间的权衡。一个简单的系统消息,例如“使用低推理”或“使用高推理”,将使模型在回答之前进行更少或更深的思考。
- 完整的思维链访问:与许多封闭模型不同,gpt-oss 展示了其内部推理。它有一个默认的分析输出,即推理步骤通道,然后是最终答案通道。用户和开发者可以检查或过滤该部分,以调试或信任模型的推理。
- 原生代理功能:这些模型基于代理工作流构建。它们以遵循指令为目标,并原生支持在思维中使用工具。
模型概述和架构
两个 gpt-oss 模型都是基于 Transformer 的网络,采用混合专家 (MoE) 设计。在 MoE 中,每个输入 token 仅激活完整参数的子集(“专家”),从而减少了计算量。就数量而言:
- gpt-oss-120b 共有 1170 亿个参数(36 层)。它使用 128 个专家子网络,每个 token 激活 4 个专家。这意味着每个 token 仅激活约 51 亿个参数。
- gpt-oss-20b 共有 210 亿个参数(24 层),包含 32 位专家(其中 4 位活跃),每个 token 产生约 36 亿个活跃参数。
该架构还包含多项高级功能:所有注意力层均使用旋转位置嵌入 (RoPE) 来处理超长上下文(最多 128,000 个 token)。注意力机制本身在全全局和 128 个 token 的滑动窗口之间交替,类似于 GPT-3 的设计。
这些模型使用分组多查询注意力机制,组大小为 8,以节省内存并保持快速推理。激活函数采用 SwiGLU。重要的是,所有专家权重均量化为 4 位 MXFP4 格式,使得大型模型可以装入一块 80GB 的 GPU,小型模型可以装入 16GB 的 GPU,且准确率不会大幅下降。
下表总结了核心规格:
| 模型 | 层数 | 参数总量 | 每个 Token 活跃参数 | Experts(总量 / 活跃) | 上下文长度 |
|---|---|---|---|---|---|
| gpt-oss-120b | 36 | 117B | 5.1B | 128 / 4 | 128K |
| gpt-oss-20b | 24 | 21B | 3.6B | 32 / 4 | 128K |
技术规格与许可
- 硬件要求:gpt-oss-120b 需要高端 GPU(约 80-100GB 显存),并可在单个 80GB A100/H100 级 GPU 或多 GPU 配置上运行。gpt-oss-20b 更轻量,即使在笔记本电脑或 Apple Silicon 芯片上,也仅需约 16GB 显存即可运行。两种型号均支持 128K 令牌上下文,非常适合长文档,但计算密集型应用。
- 量化与性能:两种型号均默认使用 4 位 MXFP4,这有助于减少内存使用并加快推理速度。但是,如果没有兼容的硬件,它们会回退到 16 位,并且 gpt-oss-20b 大约需要约 48GB 的内存。使用可选的高级内核(例如 FlashAttention)可以进一步提升速度。
- 许可与使用:两种模型均基于 Apache 2.0 发布,可自由使用、修改和分发,甚至可用于商业用途,无需支付版税或代码共享要求。无需支付 API 费用或许可限制。
| 规格项 | gpt-oss-120b | gpt-oss-20b |
|---|---|---|
| 参数总量 | 1 170 亿 | 210 亿 |
| 每个 Token 活跃参数 | 51 亿 | 36 亿 |
| 架构 | Mixture-of-Experts,128 个专家(每个 Token 4 个活跃) | Mixture-of-Experts,32 个专家(每个 Token 4 个活跃) |
| Transformer 层数 | 36 层 | 24 层 |
| 上下文窗口 | 128 000 Token | 128 000 Token |
| 显存需求 | 80 GB(单张 H100 即可运行) | 16 GB |
安装和设置过程
以下是开始使用 gpt-oss 的方法:
1. Hugging Face Transformers:安装最新的库并直接加载模型。以下命令安装必要的先决条件:
pip install --upgrade accelerate transformers
下面的代码从 Hugging Face 中心下载所需的模型。
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("openai/gpt-oss-20b")
model = AutoModelForCausalLM.from_pretrained(
"openai/gpt-oss-20b", device_map="auto", torch_dtype="auto")
下载模型后,您可以使用以下方式进行测试:
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain why the sky is blue."}
]
inputs = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt"
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=200)
print(tokenizer.decode(outputs[0]))
此设置已记录在 OpenAI 指南中,可在任何 GPU 上运行。(为了在 NVIDIA A100/H100 卡上获得最佳速度,请安装 triton 内核以使用 MXFP4;否则模型将在内部使用 16 位)。
2. vLLM:对于高吞吐量或多 GPU 服务,您可以使用 vLLM 库。OpenAI 指出,在 2 个 H100 上也是如此。您可以使用以下方式安装 vLLM:
pip install vllm
可以使用以下命令启动服务器:
vllm serve openai/gpt-oss-120b --tensor-parallel-size 2
或者用 Python 来写:
from vllm import LLM
llm = LLM("openai/gpt-oss-120b", tensor_parallel_size=2)
output = llm.generate("San Francisco is a")
print(output)
这在 Hopper GPU 上使用优化的注意力内核。
3. Ollama(Mac/Windows 本地):Ollama 是一个交钥匙本地聊天服务器。安装 Ollama 后,只需运行:
ollama pull gpt-oss:20b ollama run gpt-oss:20b
这将下载模型(量化)并启动聊天 UI。Ollama 默认自动应用聊天模板(“harmony” 格式)。您也可以通过 API 调用它。例如,使用 Python 和指向 Ollama 端点的 OpenAI SDK:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
response = client.chat.completions.create(
model="gpt-oss:20b",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain what MXFP4 quantization is."}
]
)
print(response.choices[0].message.content)
这会将提示发送到本地 gpt-oss 模型,就像官方 API 一样。
4. Llama.cpp (CPU/ARM):提供预构建的 GGUF 版本模型(例如 Hugging Face 上的 ggml-org/GPT-Oss-120b-GGUF)。安装 llama.cpp 后,您可以在本地使用该模型:
# macOS: brew install llama.cpp # Start a local HTTP server for inference: llama-server -hf ggml-org/gpt-oss-120b-GGUF -c 0 -fa --jinja --reasoning-format none
然后以相同的格式将聊天消息发送至 http://localhost:8080 。此选项即使在支持 JIT 或 Vulkan 的 CPU 或 GPU 无关环境中也能运行。
总体而言,gpt-oss 模型可与大多数常见框架配合使用。上述方法(Transformers、vLLM、Ollama、llama.cpp)涵盖桌面和服务器设置。您可以混合搭配使用 – 例如,运行一个设置进行快速推理(GPU 上的 vLLM),运行另一个设置进行设备测试(Ollama 或 llama.cpp)。
动手演示部分
任务 1:推理任务
提示词:“”” Select the option that is related to the third term in the same way as the second term is related to the first term.
IVORY : ZWSPJ :: CREAM : ?
A. NFDQB
B. SNFDB
C. DSFCN
D. BQDZL
”””
import os
os.environ['HF_TOKEN'] = 'HF_TOKEN'
from openai import OpenAI
client = OpenAI(
base_url="https://router.huggingface.co/v1",
api_key=os.environ["HF_TOKEN"],
)
completion = client.chat.completions.create(
model="openai/GPT-Oss-20b", # openai/GPT-Oss-120b Change to use 120b model
messages=[
{
"role": "user",
"content": """Select the option that is related to the third term in the same way as the second term is related to the first term.
IVORY : ZWSPJ :: CREAM : ?
A. NFDQB
B. SNFDB
C. DSFCN
D. BQDZL
"""
}
],
)
# Check if there's content in the main content field
if completion.choices[0].message.content:
print("Content:", completion.choices[0].message.content)
else:
# If content is None, check reasoning_content
print("Reasoning Content:", completion.choices[0].message.reasoning_content)
# For Markdown display in Jupyter
from IPython.display import display, Markdown
# Display the actual content that exists
content_to_display = (completion.choices[0].message.content or
completion.choices[0].message.reasoning_content or
"No content available")
gpt-oss-120b 响应:

切中要点的回应
gpt-oss-20b 响应:

精细化响应
比较分析
gpt-oss-120B 正确识别了类比中的相关模式,并通过深思熟虑的推理选择了选项 C。因为它系统地解释了词对之间的字符转换,从而获得了正确的映射。另一方面,gpt-oss-20B 未能在此任务中得出任何结果,这可能是由于输出 token 的限制。
这可能表明输出长度存在问题,以及计算效率低下。总体而言,gpt-oss-120B 能够更好地管理符号推理,控制力更强,准确性更高;因此,对于这项涉及言语类比的推理任务,它比 gpt-oss-20B 更可靠。
任务 2:代码生成
提示词:“”” Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)) in C++.
Example 1:
Input: nums1 = [1,3], nums2 = [2]
Output: 2.00000
Explanation: merged array = [1,2,3] and median is 2.
Example 2:
Input: nums1 = [1,2], nums2 = [3,4]
Output: 2.50000
Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
Constraints:
nums1.length == m
nums2.length == n
0 <= m <= 1000
0 <= n <= 1000
1 <= m + n <= 2000
-106 <= nums1[i], nums2[i] <= 106
”””
import os
from openai import OpenAI
client = OpenAI(
base_url="https://router.huggingface.co/v1",
api_key=os.environ["HF_TOKEN"],
)
completion = client.chat.completions.create(
model="openai/GPT-Oss-120b", # openai/GPT-Oss-20b change to use 20b model
messages=[
{
"role": "user",
"content": """Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays.
The overall run time complexity should be O(log (m+n)) in C++.
Example 1:
Input: nums1 = [1,3], nums2 = [2]
Output: 2.00000
Explanation: merged array = [1,2,3] and median is 2.
Example 2:
Input: nums1 = [1,2], nums2 = [3,4]
Output: 2.50000
Explanation: merged array = [1,2,3,4] and median is (2 + 3) / 2 = 2.5.
Constraints:
nums1.length == m
nums2.length == n
0 <= m <= 1000
0 <= n <= 1000
1 <= m + n <= 2000
-106 <= nums1[i], nums2[i] <= 106
"""
}
],
)
# Check if there's content in the main content field
if completion.choices[0].message.content:
print("Content:", completion.choices[0].message.content)
else:
# If content is None, check reasoning_content
print("Reasoning Content:", completion.choices[0].message.reasoning_content)
# For Markdown display in Jupyter
from IPython.display import display, Markdown
# Display the actual content that exists
content_to_display = (completion.choices[0].message.content or
completion.choices[0].message.reasoning_content or
"No content available")
gpt-oss-120b 响应
include <bits/stdc++.h>
using namespace std;
class Solution {
public:
double findMedianSortedArrays(const vector<int>& nums1,
const vector<int>& nums2) {
// Let A be the shorter array.
const vector<int>* A = &nums1;
const vector<int>* B = &nums2;
if (A->size() > B->size()) swap(A, B); // now |A| ≤ |B|
int m = A->size();
int n = B->size();
int total = m + n;
int half = (total + 1) / 2; // size of left part
int low = 0, high = m; // we search over number of elements taken from A
while (low <= high) {
int i = (low + high) / 2; // elements from A on the left side
int j = half - i; // must come from B
// Edge handling: use infinities for out‑of‑range indices
int a_left = (i == 0 ? INT_MIN : (*A)[i - 1]);
int a_right = (i == m ? INT_MAX : (*A)[i]);
int b_left = (j == 0 ? INT_MIN : (*B)[j - 1]);
int b_right = (j == n ? INT_MAX : (*B)[j]);
if (a_left > b_right) { // i too large
high = i - 1;
} else if (b_left > a_right) { // i too small
low = i + 1;
} else { // correct split
int max_left = max(a_left, b_left);
if (total % 2 == 1) // odd
return static_cast<double>(max_left);
int min_right = min(a_right, b_right);
return (max_left + min_right) / 2.0;
}
}
// The code never reaches here because the constraints guarantee at least one element.
return 0.0;
}
};
/* Example usage
int main() {
Solution s;
vector<int> a = {1, 3};
vector<int> b = {2};
cout << fixed << setprecision(5) << s.findMedianSortedArrays(a, b) << endl; // 2.00000
a = {1,2};
b = {3,4};
cout << fixed << setprecision(5) << s.findMedianSortedArrays(a, b) << endl; // 2.50000
}
gpt-oss-20b 响应
# Reference Implementation (C++17)
include <bits/stdc++.h>
using namespace std;
class Solution {
public:
double findMedianSortedArrays(vector<int>& nums1,
vector<int>& nums2) {
// Ensure nums1 is the shorter array
if (nums1.size() > nums2.size())
return findMedianSortedArrays(nums2, nums1);
int m = nums1.size();
int n = nums2.size();
int low = 0, high = m;
int halfLen = (m + n + 1) / 2; // size of left part
while (low <= high) {
int i = (low + high) / 2; // partition in nums1
int j = halfLen - i; // partition in nums2
// i too small - must move right
if (i < m && nums2[j-1] > nums1[i])
low = i + 1;
// i too big - must move left
else if (i > 0 && nums1[i-1] > nums2[j])
high = i - 1;
else {
// correct partition found
int maxLeft;
if (i == 0)
maxLeft = nums2[j-1];
else if (j == 0)
maxLeft = nums1[i-1];
else
maxLeft = max(nums1[i-1], nums2[j-1]);
// odd total, median is maxLeft
if ((m + n) % 2 == 1)
return static_cast<double>(maxLeft);
// even total, need minRight as well
int minRight;
if (i == m)
minRight = nums2[j];
else if (j == n)
minRight = nums1[i];
else
minRight = min(nums1[i], nums2[j]);
return (maxLeft + minRight) / 2.0;
}
}
// Should never reach here for valid input
return 0.0;
}
};
/* Example usage:
int main() {
Solution s;
vector<int> a = {1, 3};
vector<int> b = {2};
cout << fixed << setprecision(5) << s.findMedianSortedArrays(a, b) << endl; // 2.00000
}
比较分析
gpt-oss-120B 准确地完成了类比推理,选择了选项 C,并通过成功识别字母替换模式展现了强大的推理能力。该模型在处理字母振荡变化和跟踪事物之间关系方面表现出良好的推理能力。另一方面,gpt-oss-20B 甚至无法完成任务!该模型超出了输出 token 的限制,没有返回答案。这表明 gpt-oss-20B 在资源使用和处理提示方面效率低下。总体而言,gpt-oss-120B 在结构化推理任务中表现出色,因此在符号类比相关任务中,它是比 gpt-oss-20B 更好的选择。
模型选择指南
在 120B 和 20B 模型之间进行选择取决于项目需求或我们正在进行的任务:
- gpt-oss-120b:这是高性能模型。使用它来完成最难的推理任务、复杂的代码生成、数学问题解决或特定领域的问答。它的性能接近 OpenAI 的 o4-mini 模型。因此,它需要一个大约 80GB+ VRAM 的大型 GPU 来运行它,并且在逐步推理至关重要的基准测试和长篇任务上表现出色。
- gpt-oss-20b:这是一款针对效率进行了优化的“主力”模型。它在许多基准测试中与 OpenAI 的 o3-mini 的质量相匹配,但可以在单个 16GB VRAM 上运行。当您需要快速的设备助手、低延迟聊天机器人或使用网络搜索/Python 调用的工具时,请选择 20B。它是概念验证、移动/边缘应用程序或硬件受限时的理想选择。在许多情况下,20B 模型的答案足够好。例如,它在一项困难的数学竞赛任务中得分约为 96%,几乎与 120B 相当。
性能基准测试与比较
在标准基准测试中,OpenAI 的 gpt-oss 取得了不错的成绩。120B 模型的得分一路攀升,在高难度推理和知识任务上的得分高于 20B 模型,且两者依然保持着优异的表现。
| 基准测试 | gpt-oss-120b | gpt-oss-20b | OpenAI o3 | OpenAI o4-mini |
|---|---|---|---|---|
| MMLU(多学科大语言模型理解) | 90.0 | 85.3 | 93.4 | 93.0 |
| GPQA Diamond(图灵推理问答) | 80.1 | 71.5 | 83.3 | 81.4 |
| Humanity’s Last Exam(人类最后的考试) | 19.0 | 17.3 | 24.9 | 17.7 |
| AIME 2024(美国数学邀请赛 2024) | 96.6 | 96.0 | 95.2 | 98.7 |
| AIME 2025(美国数学邀请赛 2025) | 97.9 | 98.7 | 98.4 | 99.5 |

Source: ChatGPT

Source: ChatGPT
用例和应用
以下是 gpt-oss 的一些应用:
- 内容生成和重写:生成或重写文章、故事或营销文案。这些模型可以描述写作前的思维过程,并帮助作家和记者创作更优质的内容。
- 辅导和教育:可以演示描述概念的不同方式,逐步解决问题,并为教育应用程序、辅导工具和医学领域提供反馈。
- 代码生成:可以生成代码、调试代码或出色地解释代码。模型还可以内部执行工具,使其能够帮助完成相关的开发任务或作为编码助手。
- 研究协助:可以汇总文档、回答特定领域的问题并分析数据。更大的模型还可以针对特定研究领域进行微调,例如法律、医学或科学。
- 自主代理:支持使用工具构建具有自主代理的机器人的操作,这些代理可以浏览网页、调用 API 或运行代码。可轻松与代理框架集成,以构建更复杂的基于步骤的工作流程。
小结
120B 模型在各方面均表现出色:生成更清晰的内容、解决更棘手的问题、编写更优秀的代码,并且在研究和自主任务中适应速度更快。它唯一的缺点是资源密集度,这使得本地部署成为一项挑战。但如果你拥有基础设施,那就无可匹敌。这不仅仅是一次升级!而是能力的全新提升。


评论留言