Skip to content

[BUGFIX] Fail fast in vLLM eval when LoRA rank exceeds 512 - #18775

Merged
danielhanchen merged 7 commits into
unslothai:mainfrom
DimitriChrysafis:fix-vllm-eval-lora-rank-limit
Nov 23, 2026
Merged

danielhanchen merged 7 commits into
unslothai:mainfrom
DimitriChrysafis:fix-vllm-eval-lora-rank-limit

Conversation

@DimitriChrysafis

@DimitriChrysafis DimitriChrysafis commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fail fast via _fail() in unsloth_cli/commands/eval.py when evaluating a LoRA adapter with --backend vllm whose rank (including rank_pattern) exceeds _VLLM_LORA_RANKS[-1] (512), instead of silently clamping max_lora_rank to 512 and letting vLLM crash downstream.
  • Preserves existing max_lora_rank selection for all supported ranks (<= 16 omitted, 17..512 rounded up to _VLLM_LORA_RANKS).
  • Add regression tests in unsloth_cli/tests/test_eval.py covering valid rounding boundaries (<= 16, 24, 32, 257, 300, 512) and rejection (513, 1024, and rank_pattern=640).

Verification

  • pytest unsloth_cli/tests/test_eval.py tests/test_ci_repo_cpu_shards.py (138 passed, 4 skipped; all 3 rejection cases failed pre-fix)
  • ruff check, py_compile, and scripts/lint_duplicate_definitions.py clean

Takeover update

No rebase; one commit added on top of the original two.

  • Confirmed the original issue on a GPU:
    • before this PR, an r=1024 adapter was clamped to max_lora_rank=512;
    • vLLM then died on the first request, about 200 s into the run, with LoRA rank 1024 is greater than max_lora_rank 512, a value the user never set;
    • with this PR it exits in seconds with a clear message.
  • Checked that 512 is still the limit: MaxLoRARanks in vllm/config/lora.py is [1, 8, 16, 32, 64, 128, 256, 320, 512] in every release from v0.11.2 to v0.34.0 and on main, so the hard-coded cap is correct across the supported range.
  • Max rank selection for valid adapters is unchanged. An exhaustive check of ranks 1 to 512 gives the same max_lora_rank before and after.
  • Added: vLLM applies a single lora_alpha / r scale to every LoRA module and ignores rank_pattern / alpha_pattern. An adapter whose patterns change a module's scale was evaluated with the wrong weights and no error:
    • vLLM vs PEFT prompt log-prob difference was 0.12, against 0.0016 for a plain adapter;
    • such adapters are now refused before vLLM starts;
    • patterns that keep the scale unchanged are still accepted.
  • Both refusals now also suggest merging the adapter with unsloth export <adapter> <output_dir> --format merged-16bit and evaluating the merged model with --backend vllm.
  • Tests: the existing rank tests now check the new hint, and new cases cover allowed and refused rank_pattern / alpha_pattern / rsLoRA combinations. unsloth_cli/tests passes (2737 passed).

vLLM's PEFTHelper applies lora_alpha / r to every module and never reads
rank_pattern or alpha_pattern, so an adapter whose patterns change a
module's scale is scored with the wrong weights and no error. Refuse it
before the engine starts, like the rank > 512 case, and point both
refusals at the HF / Unsloth backends or a merged-16bit export.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

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

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-23T20:25:19.408783Z
We couldn’t complete this review. Comment @codex review to try again.
f5fb725 Draft marked ready
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a385e429a9

ℹ️ 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".

Comment thread unsloth_cli/commands/eval.py Resolved
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 851bcecb8c

ℹ️ 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".

Comment thread unsloth_cli/commands/eval.py Resolved
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 59b94f6ea6

ℹ️ 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".

Comment thread unsloth_cli/commands/eval.py Resolved
Comment thread unsloth_cli/commands/eval.py Resolved
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce0a85f24e

ℹ️ 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".

Comment thread unsloth_cli/commands/eval.py Resolved
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: f5fb7256b5

ℹ️ 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 added a commit that referenced this pull request Nov 23, 2026
…ness (#19121)

## Problem

Three Studio tests are red on `main` since #19040 (they fail on `Repo
tests (CPU, studio)` for every PR based on it, for example #18775 and
#19110):

-
`tests/studio/test_chat_autoload_failure_gate.py::test_a_chat_only_mac_without_mlx_skips_its_cached_mlx_repo`
-
`tests/studio/test_chat_autoload_failure_gate.py::test_a_chat_only_mac_auto_loads_an_omlx_folder_with_a_plain_name[false-False]`
-
`tests/studio/test_model_picker_contracts.py::test_cached_non_gguf_rows_get_the_chat_only_platform_gate`

Bisected: all three pass on `956e62778b^` and fail on `956e62778b`
(#19040).

## Cause

#19040 is correct. It routes every Chat only MLX gate in
`chat-adapter.ts` through the shared `isServedByMlx(isGguf, deviceType,
chatOnlyReason, mlxInference)`, which answers from `mlx_inference` when
the backend reports it.

The tests were behind it:

- The auto-load harness kept a hand-written `isServedByMlx` that took
three arguments and ignored `mlx_inference`. A Chat only Mac reporting
`mlx_inference: false` therefore looked like it served MLX, and the
scenarios loaded an MLX repo where the shipped code does not.
- The contract test pinned the old `platform.mlxInference === true`
literal, which #19040 replaced with `return
platformServesMlx(platform);`.

## Fix

- The harness now inlines `NO_MLX_REASONS` and `isServedByMlx` from
`per-model-config.ts` as shipped, the same way it already inlines
`isOtherCacheSnapshot`, `llamaServerLoadFields` and the server-model
wait gate. A missing definition fails with a clear message instead of a
silent stub.
- The contract test pins the new shape: the cached-row gate returns
`platformServesMlx(platform)`, and that helper calls
`isServedByMlx(...)` with `platform.mlxInference`.

## Verification

- Both files: 305 passed (were 3 failed on `main`).
- Sabotage 1: drop the `typeof mlxInference === "boolean"` branch from
`isServedByMlx` in `per-model-config.ts`; the two harness scenarios fail
again.
- Sabotage 2: pass `null` instead of `platform.mlxInference` in
`chat-adapter.ts`; the contract test and both scenarios fail.

Tests only; no product code changes.
@danielhanchen
danielhanchen marked this pull request as ready for review November 23, 2026 20:25
@danielhanchen
danielhanchen merged commit cea54c8 into unslothai:main Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants