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
remove "commentary" from the valid channel list when the request contains no tools
The default jinja chat template includes "commentary" as a valid output channel even when no tools are present in the request. This one template mismatch breaks the model on nearly every non-tool-call task. Removing "commentary" from valid channels when no tools are defined fixes the problem. The accuracy gains are dramatic.
On the chat API with fc_model=0 (BFCL_v4 tool calling benchmark, AST parsing, no tools in request):
| Test | Default Jinja | Fixed Jinja | Change |
|---|---|---|---|
| live_relevance | 3.1% | 41.4% | +38.3% |
| live_simple | 3.1% | 36.7% | +33.7% |
| simple_java | 18.0% | 60.5% | +42.5% |
| simple_javascript | 13.0% | 56.5% | +43.5% |
| simple_python | 1.8% | 36.6% | +34.8% |
| multi_turn_base | 0.2% | 14.6% | +14.3% |
| irrelevance | 99.9% | 93.8% | -6.1% |
The one metric that drops is irrelevance (99.9% to 93.8%). With the fixed template, the model actually tries to answer questions instead of producing silent failures. The irrelevance test marks those attempts as wrong, so the score goes down even though the system is doing more.
Removing one channel from the chat template moves accuracy from 3% to 40% on live tests. This is not a minor tuning adjustment. The default template shipped with the inference stack was making the model non-functional for basic tasks. Mismatches between training structure and inference template produce silent failures that look like model incompetence.
There is a problem I can see here - cached prefix invalidation. Imagine if you had some messages that did not use tools, and then one uses it (or vice versa) - the very beginning of the prefix changes, invalidating the whole cache.
Edit:
Though, on the second thought, the same would have happened before when Calls to these tools must go to the commentary channel: 'functions'." is not rendered in the system message, so nothing new would happen after this has merged.