Skip to content

Studio: default export load to offload_layers=auto - #13720

Merged
danielhanchen merged 4 commits into
unslothai:mainfrom
indrajeetapache:studio/export-offload-layers-13696
Oct 14, 2026
Merged

danielhanchen merged 4 commits into
unslothai:mainfrom
indrajeetapache:studio/export-offload-layers-13696

Conversation

@indrajeetapache

@indrajeetapache indrajeetapache commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Unable to generate output with Gemma4 e2b on Windows, despite successful execution and training #13696: on a low-VRAM card (for example 8 GB with about 6.8 GB free), the Output tab's export load of a 4-bit checkpoint such as Gemma 4 E2B failed with the bitsandbytes CPU-spill error, even though Training and a manual offload_layers="auto" load work.
  • Export now loads exactly as before. Only when a single-GPU 4-bit load spills to the CPU does it retry once with offload_layers="auto", keeping the layers the GPU cannot hold in host RAM. The retry plans a 1 GiB merge reserve instead of a training step's, since export trains nothing.
  • _is_cpu_spill_rejection now also matches Unsloth's rewritten "does not fit in GPU memory" error (it keeps the original as __cause__), so the existing multi-GPU fallback recognises it too. Both retries carry base_model and offload_layers through.
  • LoadCheckpointRequest.offload_layers (default "auto", 0 disables the retry, an integer is passed through as Training does) is plumbed route -> orchestrator -> worker -> ExportBackend.load_checkpoint, as a trailing keyword so existing positional callers are unaffected. No UI change.

Testing

  • Gemma 4 E2B LoRA checkpoint, Studio ExportBackend with the card limited to 6.84 GiB free:
    • before: Failed to load checkpoint: Unsloth: unsloth/gemma-4-E2B-it-unsloth-bnb-4bit does not fit in GPU memory (cuda:0 has 6.80 GB free) ...
    • after: retry plans the input embedding and 33 of 35 decoder layers in host RAM, loads at 5.73 GiB peak; merged 16-bit export is bit-identical (2011 of 2011 tensors) to an unrestricted export on a large card, and the Q8_0 GGUF plus mmproj GGUF are byte-identical (same sha256).
  • Loads that fit pass exactly the same kwargs as before (no offload_layers, no planner kwargs).
  • Planner check: Qwen3-8B with 3 to 4 GiB free is infeasible at the training reserve but fits with the 1 GiB export reserve; at 6.84 GiB it offloads 0 layers instead of 14.
  • pytest studio/backend/tests/test_export_*.py studio/backend/tests/multi_account; the new retry tests fail on main and pass here.
  • Studio regression switchboard (auth, settings, crawl, train + export + reload on GPU), main vs this branch: no functional regression.

Export checkpoint loading never passed Unsloth's offload_layers, so
low-VRAM Output exports hit bitsandbytes CPU-spill while Training already
supported Auto (unslothai#13696). Plumb the same kwarg through the export API and
default it to auto so models that fit with layer offload can export.
Retry a single-GPU 4-bit export load that bitsandbytes refuses with offload_layers='auto'
and a 1 GiB merge reserve instead of a training step's, so loads that fit stay unchanged.
Match Unsloth's rewritten CPU-spill error via __cause__, carry base_model and
offload_layers into the load retries, and keep offload_layers keyword-last.
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 14, 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 ⚠️ Failed 2026-10-14T15:15:03.878842Z 7245ea0 New commits
ℹ️ 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

Copy link
Copy Markdown

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

Reviewed commit: 8ce7746c33

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

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.

Unable to generate output with Gemma4 e2b on Windows, despite successful execution and training

2 participants