Skip to content

Keep import unsloth working when vLLM needs transformers 5 - #12268

Merged
danielhanchen merged 1 commit into
mainfrom
fix/vllm-transformers-v4-import
Sep 29, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/vllm-transformers-v4-import

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Problem

vLLM 0.24 and later raise at import when transformers is older than 5.0 (vllm/transformers_utils/config.py):

ImportError: Support for Transformers v4 is deprecated and was removed in vLLM v0.24.0. Please upgrade to Transformers v5

At import, Unsloth's GuidedDecodingParams fix imports vllm.sampling_params. disable_broken_vllm only recognised ABI-broken builds, so this error escaped. With transformers 4.57.x (inside the supported range) and any recent vLLM installed, import unsloth failed outright, even for SFT, DPO or GRPO without fast_inference.

Fix

  • disable_broken_vllm now also recognises this refusal, including through a chained exception. It disables vLLM the same way it does for a broken build and logs one warning: vLLM needs transformers >= 5, fast_inference is unavailable, and everything else still works.
  • The warning text is kept in import_fixes.VLLM_DISABLED_REASON. With fast_inference = True, both loader call sites now report that reason instead of "Please install vLLM", which was wrong when vLLM is installed but disabled. The broken-build case gets the same improvement.
  • Nothing changes when vLLM imports: the new check only runs on an import error that is not already recognised.

Evidence

B200, vLLM 0.30.0. A tiny Qwen3 GRPO run, 2 steps:

transformers TRL main this PR
4.57.6 0.22.2 import unsloth raises ImportError trains, one warning
4.57.6 1.14.0 import unsloth raises ImportError trains, one warning
4.57.6 1.14.0, fast_inference=True import unsloth raises ImportError ImportError naming the transformers requirement
5.17.0 0.25.1, fast_inference=True trains trains, no warning
5.17.0 1.14.0, fast_inference=True trains trains, no warning

Unsloth main plus transformers 5.17 and vLLM 0.30 were also checked across TRL 0.22.2, 0.24.0, 0.25.1, 0.29.1, 1.13.0 and 1.14.0, each with HF and with vLLM generation. All 12 runs train.

Tests: tests/test_vllm_broken_detection.py gains a direct and a chained case, plus a negative case for an unrelated ImportError. The two new positive cases fail with the detection reverted. The file passes 9/9.

vLLM >= 0.24 raises ImportError at import under transformers < 5. The startup
GuidedDecodingParams fix imports vllm.sampling_params, so with transformers
4.57.x and a recent vLLM installed, import unsloth itself failed, even for SFT
or GRPO without fast_inference. disable_broken_vllm now also recognises that
refusal and disables vLLM with a warning, as it does for an ABI-broken build.
fast_inference = True then reports why vLLM is unavailable instead of asking
to install it.
@danielhanchen danielhanchen self-assigned this Sep 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-29T09:14:49.054651Z 44c5ee6 Manual request
🔒 Security Review ✅ Completed 2026-09-29T09:14:26.991040Z 44c5ee6 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 44c5ee690c

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 44c5ee690c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 62db978 into main Sep 29, 2026
32 of 34 checks passed
@danielhanchen
danielhanchen deleted the fix/vllm-transformers-v4-import branch September 29, 2026 11:42
@danielhanchen

Copy link
Copy Markdown
Member Author

The two "Core zoo" failures (test_cast_routers_compiled_and_decoder_layer_types_kept) are not from this PR. That zoo test, added in unslothai/unsloth-zoo#1495, inherits this job's UNSLOTH_COMPILE_DISABLE=1 and then asserts the default compiled decorator. unslothai/unsloth-zoo#1501 pins the mode, and a rerun after it merges will clear them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant