Repository navigation
Add a vLLM backend to unsloth eval - #14228
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
[skip ci]
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4db526c2e3
ℹ️ 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".
| else: | ||
| eval_kwargs.update(model = "hf", model_args = model_args, batch_size = bs, device = device) | ||
| elif backend == "vllm": | ||
| model_args = {"pretrained": model, "max_model_len": max_seq_length} |
There was a problem hiding this comment.
Clamp the default context length to the model limit
When the model advertises a context window below the CLI's default of 2048—for example, GPT-2's 1024-token window—this always forwards max_model_len=2048. vLLM rejects a user-specified maximum above the model-derived limit during engine initialization, so a normal --backend vllm invocation fails before evaluation unless the user manually supplies the correct smaller value. Clamp this value to the model limit or omit it when the option was not explicitly provided.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. Only sub-2048 context models hit it (the GPT-2 family); every model people fine-tune here is 2048 or more. It fails loudly at engine start with 'User-specified max_model_len (2048) is greater than the derived max_model_len (max_position_embeddings=1024...)', before anything is scored, and --max-seq-length 1024 runs it.
|
|
||
|
|
||
| # vLLM's accepted max_lora_rank values (vllm/config/lora.py MaxLoRARanks) | ||
| _VLLM_LORA_RANKS = (16, 32, 64, 128, 256, 320, 512) |
There was a problem hiding this comment.
Account for the installed vLLM rank set
When an existing installation uses a vLLM release whose accepted LoRA ranks stop at 64, evaluating a rank-128-or-higher adapter selects 128/256/etc. from this unconditional modern list and vLLM aborts while validating max_lora_rank. This is reachable because the new backend accepts any installed vLLM version and the project does not impose a vLLM minimum; either gate these values on the installed version or reject unsupported combinations with an actionable error.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. On a vLLM build whose rank set stops below the adapter's rank the adapter cannot be served at all (leaving max_lora_rank at the default 16 fails too), and vLLM already says which ranks it accepts.
| if _has_tokenizer_files(model): | ||
| model_args["tokenizer"] = model_args["lora_local_path"] |
There was a problem hiding this comment.
Detect adapter tokenizers from the downloaded snapshot
For a Hub adapter evaluated from an already cached snapshot while offline, _local_adapter() successfully returns the local directory, but this check queries the original Hub ID again via list_repo_files; the caught network failure is interpreted as no tokenizer files. Adapters with added or changed tokens then silently use the base tokenizer and can produce invalid scores even though the downloaded snapshot contains the correct tokenizer. Check model_args["lora_local_path"] instead, as is already done when loading the adapter configuration.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this here. It needs offline mode, a cached Hub adapter and a tokenizer that differs from the base, and the hf and unsloth backends use the same Hub lookup today. Fine as a follow up across all three backends.
| stripped = _BNB_SUFFIX_RE.sub("", model) | ||
| if stripped != model and model.lower().startswith("unsloth/"): | ||
| typer.echo(f"Note: vLLM cannot load '{model}', using its 16-bit repo '{stripped}'.") | ||
| return stripped |
There was a problem hiding this comment.
Avoid rewriting local paths as Hub repository names
When a local model path is relative and has the conventional form unsloth/<name>-bnb-4bit, this branch treats it as an Unsloth Hub ID and strips the suffix even though the directory exists. Direct local evaluations and adapters whose base_model_name_or_path points to such a directory then pass a different, usually nonexistent path to vLLM. Restrict the rewrite to actual Hub IDs, using the existing _is_hub_id() distinction.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this. It needs a relative folder literally named unsloth/-bnb-4bit, and vLLM cannot load a bnb checkpoint anyway (current vLLM rejects quantization bitsandbytes), so the 16-bit repo is the model that can actually be scored.
|
Codex Review: Didn't find any major issues. You're on a roll. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Review + reproduction evidencePinned review: I ran
The zero adapters score exactly like the base and the random ones move the score, so the LoRA path is really applied. gsm8k
Tests: the 6 new vllm tests fail on the merge base and pass on head; each of the 4 fixes adds a test that fails without it; the file passes (90 tests). The hf backend gives identical scores on the merge base and head (GPU and CPU). This is CLI only: the output above is the whole user-facing surface, and no Studio page or route reads it. Conclusion: the feature is real and works on head: vLLM scores match the PR description (0.42 / 0.46), adapters apply, the hf and unsloth paths are unchanged, and the four problems found in review are fixed with tests. |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5e16e1f00b
ℹ️ 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".
| if installed and installed < (0, 4, 12): | ||
| return ( | ||
| f"--backend vllm needs lm-eval 0.4.12 or newer, but {lm_eval_version} is installed. " | ||
| "Upgrade it with `pip install -U lm-eval`." |
There was a problem hiding this comment.
Avoid requiring an impossible upgrade on Python 3.9
On supported Python 3.9 installations, this condition always rejects --backend vllm and recommends an upgrade that pip cannot perform: this repository declares Python 3.9 support and installs lm_eval>=0.4.4, while lm-eval 0.4.12 requires Python 3.10 or newer. Python 3.9 therefore resolves at most 0.4.9, even though compatible vLLM releases exist for it; either retain a compatible path for that lm-eval version or explicitly direct these users to upgrade Python instead.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
On Python 3.9 no supported vLLM installs, so the 'needs vllm' message fires before this one: vLLM 0.32 declares Requires-Python >=3.11, and even the 0.11.2 floor this repo tracks declares >=3.10. Reaching this message needs a vLLM below that floor (0.6.x), which is not a configuration we support.
| if gpu_memory_utilization is not None and not 0 < gpu_memory_utilization <= 1: | ||
| _fail("--gpu-memory-utilization must be between 0 and 1.") |
There was a problem hiding this comment.
Reject
--gpu-memory-utilization outside vLLM
When this option is supplied with the default unsloth backend or --backend hf, the value passes validation but is silently discarded because it is forwarded only in the vLLM branch. A user attempting to cap GPU allocation can therefore get an unexpected OOM with no indication that the limit had no effect; reject the incompatible combination or emit an explicit ignored-option notice, as is already done for other backend-specific flags.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5cc4b5a58: it is forwarded only in the vllm branch, so the other backends now say so rather than dropping the cap silently, matching how --device and --load-in-4bit are reported. Test covers both unsloth and hf.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
) ## Problem `Frontend build + bundle sanity` is red for every PR based on current main. Main itself builds over the startup budget: ``` eager startup JS: 6684.2 KB raw, 2012.7 KB transfer, 96 chunks over the startup budget: raw 6684.2 KB > 6683.8 KB ``` ## Measurement Exact totals, one machine and build, Node 24, 96 chunks throughout: | Commit | Raw (B) | Transfer (B) | |---|---|---| | 22a0bea (last in-budget main) | 6,844,101 | 2,060,889 | | 6a19cb2 (before #14312) | 6,844,101 | 2,060,887 | | b32d544 (#14312, FLUX.3 workflows, controls and LoRAs) | 6,844,527 | 2,061,025 | | d3a8257 (main, after #14228) | 6,844,622 | 2,061,040 | #14312 adds 426 B raw / 138 B transfer, and #14228 adds 95 B raw / 15 B transfer. Both are ordinary feature growth on chunks the startup set already loads; the chunk count is unchanged. ## Change `BUDGET` in `studio/frontend/scripts/check-bundle-budget.ts` is raised to the main build plus the same 160 B raw / 189 B transfer margin as earlier raises: `rawBytes` 6,844,782 and `transferBytes` 2,061,229. A comment entry records the numbers above. ## Testing - `npm ci && npm run build && npx tsx scripts/check-bundle-budget.ts` on this branch: `within budget (0.2 KB transfer, 0.2 KB raw to spare)`. On main, the over-budget output above. - #14316 (catalog `fetchedFrom`) builds to the identical byte count on top of main, so it fits under this budget as well.
Problem
unsloth evalruns lm-evaluation-harness through transformers (--backend unslothor--backend hf). That is fine for log-likelihood tasks, but generation-heavy tasks such as GSM8K are slow, and there was no way to score with vLLM even when it is installed.Part of #7703.
What changed
--backend vllm, which hands lm-eval its built-invllmmodel type withpretrained,max_model_len(from--max-seq-length) andbatch_size(autoor an integer).--gpu-memory-utilization(vllm backend only, between 0 and 1). Unset means vLLM's own default.adapter_config.jsonor--base-modelas for the other backends, the adapter is passed aslora_local_path(a Hub adapter is downloaded first), andmax_lora_rankis raised to the next value vLLM accepts when the adapter's rank is above 16. Adapter tokenizer files are used when present.pyproject.toml, builds the LoRA request but never passesenable_lora, so vLLM refuses its own request. Both that version and current lm-eval forward the flag unchanged.--load-in-4bitprints a note that it has no effect, and anunsloth/...-bnb-4bitname (including an adapter's base) is swapped for its 16-bit repo with a note.--backend hf), when vllm is not installed (use--backend unsloth), and when no GPU is visible (use--backend hf).What does not change
unsloth, and theunslothandhfpaths are untouched.Tests
unsloth_cli/tests/test_eval.py: new vllm cases (plain model, adapter, rank bump, bnb swap, refusals, memory fraction validation). The 6 vllm behaviour tests fail on main and pass here; the whole file passes (85 tests).On one T4, hellaswag with
--limit 50, 16-bitQwen/Qwen2.5-0.5B-Instruct:--backend vllmand--backend unslothboth score acc 0.42 and acc_norm 0.46, and a rank-64 LoRA whose B matrices are zero scores the same through the adapter path.