Skip to content

[BUGFIX] Gate GGML LoRA exports to the main process like the GGUF paths - #19284

Open
DimitriChrysafis wants to merge 1 commit into
unslothai:mainfrom
DimitriChrysafis:fix-ggml-ddp-gating
Open

DimitriChrysafis wants to merge 1 commit into
unslothai:mainfrom
DimitriChrysafis:fix-ggml-ddp-gating

Conversation

@DimitriChrysafis

Copy link
Copy Markdown
Contributor

[BUGFIX] Gate GGML LoRA exports to the main process like the GGUF paths

model.push_to_hub_ggml(...) and model.save_pretrained_ggml(...) are the LoRA GGML twins of push_to_hub_gguf/save_pretrained_gguf, but #18686 added the plain-DDP gating only to the GGUF pair. Under plain data parallel every rank runs _unsloth_save_lora_gguf: every rank converts the adapter and uploads the same repo (push_to_hub_ggml), or writes the same save_directory and races N convert_lora_to_gguf.py subprocesses on one output file (save_pretrained_ggml). Neither signature accepts is_main_process, so a caller cannot opt a non-main rank out at all.

The fix mirrors #18686: @_ddp_push_on_rank0("push_to_hub") on push_to_hub_ggml so rank 0 alone converts and uploads, and an is_main_process = True parameter + _defer_to_main_process(is_main_process, self) on both, matching save_pretrained_gguf. FSDP2 gather writers and FSDP1 replicas are unaffected.

New tests in tests/test_peft_export_main_process.py fake a 2-rank group: on base the rank-1 push converts/uploads and is_main_process is rejected as an unexpected kwarg; with the fix rank 0 exports and rank 1 returns None.

danielhanchen added a commit that referenced this pull request Nov 24, 2026
#19296)

## Problem

`studio/backend/tests/test_managed_engine_readiness_poll.py` fails on
main (6 of 9 tests) and on every PR based on it, for example #19284 and
#19285, which do not touch Studio:

```
>   child_env["WSL_UTF8"] = "1"
E   TypeError: 'NoneType' object does not support item assignment
```

## Cause

Two PRs merged within an hour of each other, each green on its own base:

- #19167 added `vllm` to `MANAGED_ENGINE_LOG_FAMILIES`, so a vLLM start
now captures logs and, on the WSL path, sets `child_env["WSL_UTF8"] =
"1"` on the environment `_wsl_command` returns (the SGLang half of this
came in #19166).
- #19242 added this test file. Its `_wsl_command` stub returned
`(command, None)`, and its base predated #19167, so vLLM did not capture
logs there and the `None` was never touched.

The code is right: the real `_wsl_command` always returns
`wsl_host.guest_command(...)`, whose second element is the `wsl.exe`
environment dict, and `test_managed_engine_logs.py` already stubs it
with `dict(os.environ)`. The stub was the part that did not match the
contract.

## Fix

- The stub returns `dict(os.environ)`, the same shape the real launcher
hands back.
- The fixture sets `UNSLOTH_STUDIO_HOME` to `tmp_path`, since the vLLM
start now opens a per-attempt log under the Studio home and the tests
should not write into the real one.

No product code changes.

## Verification

- `tests/test_managed_engine_readiness_poll.py`: 9 passed (6 failed on
main before the change).
- Reverting only the stub's return value back to `None` brings back the
same 6 failures.
- `test_managed_engine_logs.py`, `test_engine_ports.py` and this file
together: 50 passed; this file under `-n 4`, 3 repeats: 27 passed.

This branch has not been deployed

No deployments
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