
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 模型在各方面均表現出色:生成更清晰的內容、解決更棘手的問題、編寫更優秀的程式碼,並且在研究和自主任務中適應速度更快。它唯一的缺點是資源密集度,這使得本地部署成為一項挑戰。但如果你擁有基礎設施,那就無可匹敵。這不僅僅是一次升級!而是能力的全新提升。

評論留言