Skip to content

Multi-LoRA packing: load the num_proc policy without importing unsloth - #18324

Merged
danielhanchen merged 1 commit into
mainfrom
ci/multi-lora-pack-num-proc-shared-policy
Nov 18, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/multi-lora-pack-num-proc-shared-policy

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Multi-LoRA packing: load the num_proc policy without importing unsloth

studio/backend/tests/test_dataset_map_num_proc.py::test_the_batched_packing_pool_asks_the_same_veto fails in (Python 3.13, a-f) on every PR since #17701, for example #18015, #18108, #18142 and #18303:

core/training/multi_lora_trainer.py:686: in _pack_num_proc
    from unsloth_zoo.dataset_num_proc import get_dataset_num_proc
E   ModuleNotFoundError: No module named 'unsloth_zoo'
core/training/multi_lora_trainer.py:688: in _pack_num_proc
    from unsloth.dataset_num_proc import get_dataset_num_proc
unsloth/_gpu_init.py:241: in <module>
E   ImportError: Unsloth: Please install unsloth_zoo via `pip install unsloth_zoo` then retry!

Cause

_pack_num_proc, the multi-LoRA packing pool's worker count from #15733, looks up the shared dataset_num_proc policy in two steps:

  1. it imports unsloth_zoo;
  2. if that fails, it falls back to from unsloth.dataset_num_proc import ....

That fallback runs the whole unsloth package __init__, which needs unsloth_zoo anyway and patches torch on the way.

The rest of the backend already avoids this. utils.hardware.hardware._shared_policy() tries unsloth_zoo first and otherwise loads the stdlib-only dataset_num_proc.py straight off disk, precisely so that no caller runs import unsloth.

#17701 added the first test that reaches _pack_num_proc, and the backend shard runs without unsloth_zoo, so the fallback fails there.

Fix

_pack_num_proc now gets the policy from _shared_policy(), the same loader the single-job tokenize pool uses.

  • With a policy, which is every real install: the call is unchanged, get_dataset_num_proc(count) on the same module.
  • With no policy at all: it keeps that function's contract, so a serial count of 1 still means None.

Verification

  • Faithful repro of the CI state: core.training.trainer already imported, then unsloth_zoo made unimportable, then _pack_num_proc called with a tight host-memory snapshot.
    • main: ModuleNotFoundError: No module named 'unsloth_zoo'.
    • This PR: returns None, as the test expects.
  • With unsloth_zoo installed: tests/test_dataset_map_num_proc.py and the multi-LoRA tests pass (88 passed).
  • ruff is clean.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

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

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T13:03:16.390941Z 551e3c9 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.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 551e3c99b0

ℹ️ 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 7ebe2f2 into main Nov 18, 2026
@danielhanchen
danielhanchen deleted the ci/multi-lora-pack-num-proc-shared-policy branch November 18, 2026 13:03
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