Instructions to use openai/gpt-oss-20b with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openai/gpt-oss-20b with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="openai/gpt-oss-20b") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("openai/gpt-oss-20b") model = AutoModelForCausalLM.from_pretrained("openai/gpt-oss-20b", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- AMD Developer Cloud
- Local Apps Settings
- vLLM
How to use openai/gpt-oss-20b with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "openai/gpt-oss-20b" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai/gpt-oss-20b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/openai/gpt-oss-20b
- SGLang
How to use openai/gpt-oss-20b with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "openai/gpt-oss-20b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai/gpt-oss-20b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "openai/gpt-oss-20b" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "openai/gpt-oss-20b", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use openai/gpt-oss-20b with Docker Model Runner:
docker model run hf.co/openai/gpt-oss-20b
triton_kernels and multiprocessing
Has anyone been able to share the quantized model across multiple processes in python (i.e. using multiprocessing or torch.multiprocessing)? I'm myself getting issues with pickling/unpickling related to triton_kernels:
ModuleNotFoundError: No module named 'triton_kernels_b8dc79e809df14c1'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/conda/lib/python3.12/multiprocessing/spawn.py", line 122, in spawn_main
exitcode = _main(fd, parent_sentinel)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/conda/lib/python3.12/multiprocessing/spawn.py", line 132, in _main
self = reduction.pickle.load(from_parent)
Note that I'm able to use the model fine from the main process and can share other models on CUDA with child processes (via spawn) but not this one. Anyone seen this? (and better yet, have a solution?)
We packaged the triton_kernels better, if you use the main, it should be a much better experience.
https://github.com/huggingface/transformers/pull/39926
Thank you for looking into it. I got the latest versions of transformers and kernels from github but am still seeing the issue. Here is a minimal example to test:
from transformers import AutoModelForCausalLM
from torch.multiprocessing import get_context
import torch
import os
MODEL_NAME = "openai/gpt-oss-20b"
DEVICE = "cuda"
spawn_context = get_context("spawn")
def use_model(model):
print(os.getpid(), model.device)
print(
model.generate(
input_ids=torch.tensor([[0, 1, 2]], device=model.device), max_new_tokens=1))
if __name__ == "__main__":
model = AutoModelForCausalLM.from_pretrained(MODEL_NAME,
torch_dtype="auto",
device_map=DEVICE)
use_model(model)
spawn_context.Process(target=use_model, args=(model, )).start()
Here are my versions (I removed triton_kernels just in case it was interfering in some way):
kernels 0.9.0.dev0
transformers 4.56.0.dev0
triton 3.4.0
# at these commits (main branch head as of Sat Aug 16):
- Installing transformers (4.56.0.dev0 cd22550)
- Installing kernels (0.9.0.dev0 1caa4c1)
Are you able to reproduce?