Repository navigation
Inkling 2: merged 16-bit save and GGUF export - #19016
Conversation
The generic merge re-reads the released checkpoint, whose keys are Inkling's own (attn.wq_du, controllers.*) and whose experts are NVFP4 / MXFP8, so it placed none of the LoRA weights and the export was refused. save_inkling2_merged_16bit walks the original shards, maps each key to its transformers name with the model's own conversion mapping, dequantizes the experts with transformers' Inkling2LoopDequantizeExperts, adds the LoRA deltas in float32 (gate_up deltas re-interleaved to the checkpoint's layout) and writes the checkpoint back in its original layout with bfloat16 experts and no quantization config. transformers reloads it, and llama.cpp's Inkling 2 converter reads it, so save_pretrained_gguf works too. merged_4bit still refuses.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9c0a8fba00
ℹ️ 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".
Measure linear and embedding deltas against the original checkpoint for PiSSA / OLoRA style inits (same conversion as the generic merge), and subtract the initial snapshot from expert deltas. Collect embedding LoRA factors from lora_embedding_A / lora_embedding_B instead of skipping them. Write live biases trained through bias="all" / "lora_only" instead of copying the checkpoint's.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 068fed1775
ℹ️ 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".
LoRA trainable_token_indices keeps the trained embedding rows in PEFT's TrainableTokensLayer, so the Inkling 2 writer copied the original rows. Replace them from each active adapter's trainable_tokens_delta, as merge_and_unload does, and refuse LoRA plus trainable tokens on one weight. save_pretrained_merged now forwards dtype to the Inkling 2 writer: float32 writes every floating tensor (experts included) in float32 without rounding the merged deltas; None keeps the previous output; other dtypes are refused. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cb2f65817b
ℹ️ 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".
A merged Inkling 2 export always writes numbered shards plus an index. When the target directory already held model.safetensors from an earlier unsharded save, transformers loaded that file ahead of the index and silently reloaded the old weights. After the new shards and index are in place, drop model.safetensors, pytorch_model.bin, its index and numbered shards the new index does not list. Write the index through a temp file, and refuse to export into the source checkpoint directory since the writer reads from it. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 38490fb980
ℹ️ 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".
If the target directory previously held a LoRA save, adapter_config.json and adapter_model.safetensors (or adapter_model.bin) stayed next to the merged shards, and transformers auto-loaded that adapter onto the merged model, applying the LoRA twice. Drop those files in the same post-write cleanup that removes stale weights, after the new shards and index are in place.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fc62a59851
ℹ️ 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".
create_repo(private = True) leaves an existing public repo public, so the direct upload in save_inkling2_merged_16bit could publish the merged weights. Check visibility with _refuse_private_push_to_public_repo right after create_repo, before merging or uploading, as the staged Hub export does, and upload to the repo id create_repo resolved. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f104a5ec1
ℹ️ 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".
upload_folder only adds files, so an existing Hub repo kept an older model.safetensors, pytorch_model.bin or LoRA adapter that would shadow the merged shards on reload. List the repo and delete those files in the same commit, matching what the local save already does. [skip ci]
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e966ade4a5
ℹ️ 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".
|
@codex review |
|
Codex Review: Didn't find any major issues. Already looking forward to the next diff. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…le helper (#19133) ## Problem Two tests are broken on `main`. 1. **`tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding`** is red in `Repo tests (CPU, rest-2)` for every PR based on `main`, for example #19122: ``` Left contains one more item: 'tests/test_inkling2_support.py:633: read_text()' ``` #19016 added `(_ROOT / "unsloth" / "save.py").read_text()`. It reads a checked-in file with the platform default encoding, which breaks on Windows as soon as `save.py` gains a non-ASCII byte. The guard is right and the new line is wrong. 2. **`tests/test_inkling2_support.py::test_fastmodel_keeps_inkling2_eager_unless_told_otherwise`** fails wherever the file runs: ``` assert re.search('if os\\.environ\\.get\\("UNSLOTH_COMPILE_DISABLE", "0"\\) == "0": ...', body) AssertionError: None ``` It still pins the inline assignment that #19073 replaced with the shared `_set_partial_compile_disable()` helper. CI does not show it yet: the file skips below transformers 5.24, and the HF=latest legs are held below 5.24. It fails locally on 5.24.0, so it would turn red as soon as that cap lifts. ## Fix Tests only, in `tests/test_inkling2_support.py`: - Both reads of checked-in source pass `encoding = "utf-8"`: - the `save.py` read the guard flags; - the loader source read through `__file__`, which the guard does not see. - The eager-compile test now pins the current shape: - the Inkling 2 branch calls `_set_partial_compile_disable()`; - the helper sets `partial` from unset, `0` or `partial`; - the helper keeps a full disable (`1`, `true`) as `1`, so an explicit user choice is still left alone. ## Verification | Check | Result | | --- | --- | | `test_source_read_encoding.py`, `main` | 1 failed | | `test_source_read_encoding.py`, this branch | 16 passed | | `test_inkling2_support.py`, transformers 5.24.0, `main` | 1 failed, 41 passed | | `test_inkling2_support.py`, transformers 5.24.0, this branch | 42 passed | | `test_inkling2_support.py`, transformers 5.17 | module skipped as before | Sabotage, each with only the product line changed: - Drop the helper call from the Inkling 2 branch in `loader.py`: the test fails on the call check. - Make the helper always set `partial`: the test fails with `assert 'partial' == '1'` for a full disable.
…19135) ## Problem `tests/test_runtime_text_encoding.py::test_shipping_code_names_an_encoding` is red on `main` in `Repo tests (CPU, rest)`, for example on #19122 and #19127: ``` 4 text read/write call sites in shipping code let the operator's locale decide the encoding 'unsloth/models/inkling2.py:364: open()' 'unsloth/models/inkling2.py:532: open()' 'unsloth/models/inkling2.py:537: open()' 'unsloth/models/inkling2.py:545: open()' ``` ## Cause The guard is right; the new code is wrong. #19016 (Inkling 2 merged 16-bit save and GGUF export) added four text-mode `open()` calls with no encoding: - reading `model.safetensors.index.json` (`index_path`); - writing the merged index; - reading `config.json`; - writing `config.json`. On Windows, Python uses the locale code page there. A config or index with a non-ASCII byte then fails to load, or is written in a codec the next reader does not expect. The guard has been in the repo since October; the lines all come from `c69ffd79be`. ## Fix Pass `encoding = "utf-8"` on all four calls in `unsloth/models/inkling2.py`. Nothing else changes: the JSON written is the same on a UTF-8 host. ## Verification - `tests/test_runtime_text_encoding.py`: 9 passed (`main`: 1 failed, listing exactly these four sites). - `tests/test_inkling2_support.py` on transformers 5.24.0, including the merged-save tests: 42 passed.
Inkling 2 merged 16-bit save and GGUF export were refused with
NotImplementedError(added on purpose in #18812). This adds a dedicated merge so both work.Why the generic merge cannot work
The released checkpoint uses Inkling's own key names (
attn.wq_du,controllers.*) and stores the routed experts as NVFP4 / MXFP8. The generic merge re-reads the original shards, cannot place any LoRA weight on those keys, and would write the base model back unchanged.What this does
save_inkling2_merged_16bit(inunsloth/models/inkling2.py), used forsave_method="merged_16bit"and therefore bysave_pretrained_gguf:Inkling2LoopDequantizeExperts;merged_4bitstill refuses.Tests
tests/test_inkling2_support.py: updated plus a merge round-trip test; 21 pass on CPU.q8_0GGUF export loads in llama.cpp.thinkingmachines/Inkling-2-Mini(20.19 GB, needed because merge and GGUF output cannot be judged on random weights), Colab A100 40 GB, 10 training steps: merged save 1116 tensors / 52.78 GB with LoRA targets changed and norms unchanged;q4_k_mGGUF 17.48 GB plus a 0.64 GB image projector, export 1274 s; llama.cpp (CPU build) generates 6.2 tok/s and answers the fibonacci prompt correctly.Not covered