Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Fall back to Unsloth inference for gpt-oss with fast_inference=True (#13155)

Daniel Han09ce38697ff6
diff --git a/tests/fast_inference/test_gpt_oss_fallback.py b/tests/fast_inference/test_gpt_oss_fallback.py
new file mode 100644
index 00000000000..2c3792880b6
--- /dev/null
+++ b/tests/fast_inference/test_gpt_oss_fallback.py
@@ -0,0 +1,37 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved.
+
+"""gpt-oss with fast_inference = True loads on Unsloth inference instead of crashing in vLLM weight sharing (unslothai/unsloth#4541)."""
+
+import importlib.util
+
+import pytest
+from real_accelerator import (
+ has_real_accelerator,
+) # tests/_shared, on sys.path via tests/conftest.py
+
+pytestmark = pytest.mark.gpu
+
+MODEL_NAME = "trl-internal-testing/tiny-GptOssForCausalLM"
+
+
[email protected](not has_real_accelerator(), reason = "needs a GPU")
[email protected](importlib.util.find_spec("vllm") is None, reason = "needs vLLM installed")
+def test_gpt_oss_fast_inference_falls_back(capfd):
+ from unsloth import FastLanguageModel
+
+ model, tokenizer = FastLanguageModel.from_pretrained(
+ model_name = MODEL_NAME,
+ max_seq_length = 256,
+ load_in_4bit = False,
+ fast_inference = True,
+ gpu_memory_utilization = 0.1,
+ )
+ assert (
+ "does not support gpt_oss yet - will switch to Unsloth inference" in capfd.readouterr().out
+ )
+ assert getattr(model, "vllm_engine", None) is None
+
+ inputs = tokenizer(["Hello"], return_tensors = "pt").to(model.device)
+ out = model.fast_generate(**inputs, max_new_tokens = 4, min_new_tokens = 4, do_sample = False)
+ assert out.shape[1] == inputs["input_ids"].shape[1] + 4
diff --git a/unsloth/models/loader.py b/unsloth/models/loader.py
index fd3ef675b90..58a695c7ace 100644
--- a/unsloth/models/loader.py
+++ b/unsloth/models/loader.py
@@ -98,6 +98,8 @@ SUPPORTS_FALCON_H1 = transformers_version >= Version("4.53.0")
SUPPORTS_GEMMA3N = transformers_version >= Version("4.53.0")
SUPPORTS_GPTOSS = transformers_version >= Version("4.55.0")
SUPPORTS_GEMMA4 = transformers_version >= Version("5.5.0")
+# unsloth_zoo cannot share these models' vLLM weights with the training model.
+VLLM_UNSUPPORTED_MODEL_TYPES = ("gpt_oss",)
# Transformers v5 meta-device loading corrupts non-persistent buffers (inv_freq); see _fix_rope_inv_freq() below.
_NEEDS_ROPE_FIX = transformers_version >= Version("5.0.0")
if SUPPORTS_GEMMA:
@@ -2190,6 +2192,13 @@ class FastModel(FastBaseModel):
model_types_all = ",".join(model_types) + ","
_maybe_advise_fla_install(model_types)
_raise_if_modeling_ignores_config(model_config, model_types)
+ _vllm_unsupported = [t for t in model_types if t in VLLM_UNSUPPORTED_MODEL_TYPES]
+ if fast_inference and _vllm_unsupported:
+ # Without this, vLLM loads the whole model first and weight sharing then crashes (unslothai/unsloth#4541).
+ print(
+ f"Unsloth: fast_inference (vLLM) does not support {_vllm_unsupported[0]} yet - will switch to Unsloth inference!"
+ )
+ fast_inference = False
# Text-diffusion models (DiffusionGemma) take a transformers-only slow path: a custom block-diffusion generate over a novel backbone, so Unsloth's autoregressive kernel/compile patching is skipped and the unmodified HF model is loaded, keeping 4bit/8bit and PEFT LoRA.
if is_diffusion_model_type(model_types):