Skip to content

Lora: fail GGUF export when no .gguf is produced - #17627

Merged
danielhanchen merged 5 commits into
unslothai:mainfrom
DimitriChrysafis:fix/lora-gguf-empty-export
Nov 18, 2026
Merged

danielhanchen merged 5 commits into
unslothai:mainfrom
DimitriChrysafis:fix/lora-gguf-empty-export

Conversation

@DimitriChrysafis

Copy link
Copy Markdown
Contributor

LoRA GGUF export could write only adapter safetensors, log (none), and still report success. With push_to_hub=True, it would upload a folder with no GGUF. A leftover .gguf could also make a no-op conversion look successful.

The model-GGUF path already rejects missing output and calls out this failure in its #7897 comment. This adds the missing check to LoRA exports, including the second save used for Hub staging. Both converter wrappers also check that their output file exists.

For reused folders, _ReusedFolderWrites separates new files from leftovers. If it can't tell, a clean staged save has to produce a GGUF first. That save is reused for upload so there's no extra conversion.

Tests

The six failure cases reproduced the bug before the fix.

  • Adapter-format, GGUF Hub-upload, and Hub-push tests: 164 passed, 1 skipped (safetensors missing).
  • Saver/token tests: 20 passed with source-loaded helpers and a mocked converter, without importing the full ML stack.
  • Ruff, pinned formatting, syntax checks, and git diff --check pass.

No real GGUF conversion or Hub upload was run.

@danielhanchen

Copy link
Copy Markdown
Member

(Python 3.13, g-l) fails both cases of studio/backend/tests/test_hub_write_ambient_token.py::test_a_local_gguf_lora_conversion_carries_the_sentinel with the new check:

AssertionError: Adapter export failed: LoRA GGUF conversion reported success but wrote no .gguf file to .../test_a_local_gguf_lora_convers0.

That test's _FakeModel.save_pretrained_gguf only records the token it was given and writes nothing, so it now trips the "no .gguf produced" refusal before it can assert the token. The check itself looks right. Having the fake write a placeholder file, e.g. (Path(save_directory) / "adapter.gguf").write_bytes(b""), keeps the test about the token sentinel and lets it pass with the new guard.

@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-18T10:11:04.697182Z d404eab 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[bot]

This comment was marked as resolved.

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: d404eab2fb

ℹ️ 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 Nov 18, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Nov 18, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Nov 18, 2026
danielhanchen added a commit that referenced this pull request Nov 18, 2026
## Read the NPU compat fixtures as UTF-8


`tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding`
fails on `main` since #18050. It shows up on unrelated PRs as `Repo
tests (CPU, rest-2)`, for example #18104 and #17627:

```
E   AssertionError: 1 file reads in the test trees touch a checked-in file with the platform default encoding ...
E     Left contains one more item: 'studio/backend/tests/test_npu_compat.py:18: read_text()'
```

### Cause

#18050 added two reads of the checked-in fixture
`fixtures/npu_compat/hf_configs.json` that call `.read_text()` with no
encoding:

- `studio/backend/tests/test_npu_compat.py:18`
- `studio/backend/tests/test_export_npu_q4nx.py:677`

Without an encoding, Python decodes with the platform default, which is
the ANSI codepage on Windows. The lint fails that as soon as a fixture
gains a non-ASCII byte.

### Fix

Both reads now pass `encoding = "utf-8"`. The fixture is JSON, so it is
UTF-8 by definition. Nothing else changes.

The other bare `.read_text()` in `test_npu_compat.py`, at line 88, reads
a file the test itself wrote into `tmp_path`. The lint deliberately
leaves those alone, so it is unchanged.

### Verification

- `tests/test_source_read_encoding.py`: fails on `main` on both lines
and passes with this change (16 passed).
- `tests/test_npu_compat.py` and `tests/test_export_npu_q4nx.py`: 96
passed.
- ruff is clean.
@danielhanchen
danielhanchen merged commit f0cc813 into unslothai:main Nov 18, 2026
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