Skip to content

Add a vLLM backend to unsloth eval - #14228

Merged
danielhanchen merged 12 commits into
mainfrom
studio-eval-vllm-backend
Oct 20, 2026
Merged

danielhanchen merged 12 commits into
mainfrom
studio-eval-vllm-backend

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Problem

unsloth eval runs lm-evaluation-harness through transformers (--backend unsloth or --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

  • New --backend vllm, which hands lm-eval its built-in vllm model type with pretrained, max_model_len (from --max-seq-length) and batch_size (auto or an integer).
  • New --gpu-memory-utilization (vllm backend only, between 0 and 1). Unset means vLLM's own default.
  • LoRA adapters: the base comes from adapter_config.json or --base-model as for the other backends, the adapter is passed as lora_local_path (a Hub adapter is downloaded first), and max_lora_rank is raised to the next value vLLM accepts when the adapter's rank is above 16. Adapter tokenizer files are used when present.
  • LoRA is enabled on the engine explicitly: lm-eval 0.4.4, the floor in pyproject.toml, builds the LoRA request but never passes enable_lora, so vLLM refuses its own request. Both that version and current lm-eval forward the flag unchanged.
  • vLLM has no bitsandbytes loader, so this backend loads 16-bit weights. --load-in-4bit prints a note that it has no effect, and an unsloth/...-bnb-4bit name (including an adapter's base) is swapped for its 16-bit repo with a note.
  • Clear refusals before anything loads: on macOS (use --backend hf), when vllm is not installed (use --backend unsloth), and when no GPU is visible (use --backend hf).

What does not change

  • The default backend is still unsloth, and the unsloth and hf paths 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).

python -m pytest -q unsloth_cli/tests/test_eval.py

On one T4, hellaswag with --limit 50, 16-bit Qwen/Qwen2.5-0.5B-Instruct: --backend vllm and --backend unsloth both 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-10-20T07:17:46.997074Z 81be761 Manual request
🔒 Security Review ⚠️ Failed 2026-10-19T09:04:27.509223Z eb96d38 PR opened
ℹ️ 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 danielhanchen self-assigned this Oct 19, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: e9936adb33

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

@NilayYadav NilayYadav self-assigned this Oct 19, 2026
[skip ci]
@NilayYadav

Copy link
Copy Markdown
Collaborator

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator

@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: 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}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment on lines +643 to +644
if _has_tokenizer_files(model):
model_args["tokenizer"] = model_args["lora_local_path"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment on lines +213 to +216
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: a837386193

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

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 19, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 19, 2026
@unslothai unslothai deleted a comment from danielhanchen Oct 19, 2026
@NilayYadav

NilayYadav commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Review + reproduction evidence

Pinned review: 418e16efc (head a707596f2 is an empty commit on the same tree so CI runs). 4 findings, fixed in a6ffcef30, a83738619, 5bba73eac and 418e16efc.

I ran unsloth eval Qwen/Qwen2.5-0.5B-Instruct -t hellaswag --limit 50 on the merge base a33463fb1 and on the PR (Linux, 1x NVIDIA L4, vllm 0.32.0, lm-eval 0.4.13, torch 2.13.0+cu130):

  • Before (merge base): --backend vllm exits 2 with Error: --backend must be 'unsloth' or 'hf', got 'vllm'.
  • PR head as submitted (99611b98a): every --backend vllm run failed with RuntimeError: Engine core initialization failed. See root cause above. and nothing above it. The cause was Cannot re-initialize CUDA in forked subprocess: the new GPU check calls torch.cuda.is_available() in the parent, which initialises CUDA before vLLM forks its engine. The same run passes with PYTORCH_NVML_BASED_CUDA_CHECK=1 (which vLLM itself sets on import) or with VLLM_WORKER_MULTIPROC_METHOD=spawn. Fixed in a6ffcef30 by setting that variable before the probe, with a test.
  • PR head after the fix:
run acc acc_norm
--backend vllm, plain model 0.42 0.46
--backend vllm, rank 64 adapter with zero B 0.42 0.46
--backend vllm, rank 64 zero adapter whose base is unsloth/Qwen2.5-0.5B-Instruct-bnb-4bit (swapped to the 16-bit repo, note printed) 0.42 0.46
--backend vllm, rank 8 adapter with random B 0.42 0.52
--backend vllm, rank 64 adapter with random B (max_lora_rank raised to 64) 0.36 0.52
--backend hf, plain model, merge base and head 0.38 0.50

The zero adapters score exactly like the base and the random ones move the score, so the LoRA path is really applied. gsm8k --limit 20 with --backend vllm: exact_match 0.25 in 83 s, against 212 s for --backend hf. --gpu-memory-utilization 0.5 -b 8 and --load-in-4bit (prints the 16-bit note) both run.

  • Multi-process: torchrun --nproc_per_node 2 -m unsloth_cli eval ... --backend vllm on 2x L4 started two engines and both failed at engine init, with no results. Fixed in a83738619: the existing refusal for --backend unsloth now covers vllm too, with a test.
  • lm-eval too old for vLLM: with vllm 0.32.0, lm-eval 0.4.11 dies inside its vllm wrapper (ModuleNotFoundError: No module named 'ray'; it also still passes swap_space, which vLLM 0.32 removed), and the pyproject floor 0.4.4 dies with NameError: name 'LLM' is not defined. lm-eval 0.4.12 runs (acc 0.35, acc_norm 0.25 on --limit 20, same as 0.4.13). Fixed in 5bba73eac: --backend vllm with lm-eval below 0.4.12 now exits 2 before loading anything with Error: --backend vllm needs lm-eval 0.4.12 or newer, but 0.4.11 is installed. Upgrade it with `pip install -U lm-eval`. The hf and unsloth backends keep the 0.4.4 floor. lm-eval 0.4.12 also runs with an older vLLM (0.11.0, transformers 4.57.6): plain model and adapter both score 0.35 / 0.25, so the check does not lock anyone out.
  • Engine start failures: with --gpu-memory-utilization 0.02 the run used to end with only RuntimeError: Engine core initialization failed. See root cause above. and nothing about memory anywhere in the output. Fixed in 418e16efc: for the vllm backend the silenced output goes to a temporary log instead of /dev/null, and its tail is printed when the evaluation fails, so the same run now shows ValueError: No available memory for the cache blocks. Try increasing gpu_memory_utilization ... above the traceback. A normal run is unchanged: 11 lines of output before and after, same scores (plain and adapter, --limit 20: 0.35 / 0.25).
  • No GPU: --backend vllm exits 2 with --backend vllm needs an NVIDIA or AMD GPU, but none is visible. Use --backend hf to evaluate on CPU. --gpu-memory-utilization 1.5 exits 2 with the range error.

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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 418e16efc2

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

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: a707596f22

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

@unslothai unslothai deleted a comment from NilayYadav Oct 20, 2026
@unslothai unslothai deleted a comment from NilayYadav Oct 20, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@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: 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".

Comment on lines +212 to +215
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`."

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment on lines +532 to +533
if gpu_memory_utilization is not None and not 0 < gpu_memory_utilization <= 1:
_fail("--gpu-memory-utilization must be between 0 and 1.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 81be761ace

ℹ️ 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 d3a8257 into main Oct 20, 2026
@danielhanchen
danielhanchen deleted the studio-eval-vllm-backend branch October 20, 2026 07:35
danielhanchen added a commit that referenced this pull request Oct 20, 2026
)

## 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.
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