Repository navigation
Drop the git+ install cell and correct the distillation memory claim - #402
Conversation
Codex Review SummaryThis 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. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc532e0fd4
ℹ️ 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".
| @@ -101,16 +82,21 @@ | |||
| "source": [ | |||
| "### Pick a configuration\n", | |||
| "\n", | |||
| "GKD holds full `(batch, seq, vocab)` logits for **both** models, so peak memory\n", | |||
| "follows the vocabulary, not the weights.\n", | |||
| "Unsloth projects hidden states through each `lm_head` in chunks, so the full\n", | |||
There was a problem hiding this comment.
Require the patched Unsloth release before relying on GKD
When this notebook is rerun in a persistent or local environment containing pre-2026.10.5 unsloth/unsloth_zoo, the installation cell uses unversioned installs without --upgrade, so removing the forced-reinstall cell can leave those old packages active. As pip install --help states, --upgrade is what upgrades specified packages to the newest available version. The affected releases still downcast GKDConfig to SFT, so the advertised distillation and chunked-memory behavior can silently fail to run; pin a minimum patched version or explicitly upgrade both packages.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed and fixed in 56163fb. I reproduced it rather than reasoning about it: with unsloth==2026.9.7 installed, the notebook's exact pip install unsloth left 2026.9.7 in place, and that release has no chunked loss at all.
Both install variants now pass --upgrade with a minimum, Kaggle's included, since Kaggle images can already carry unsloth and that install did not use --upgrade either.
One thing your suggestion led me into that is worth recording. I first implemented exactly the version pin you described, parse(version("unsloth")) >= parse("2026.10.5"), and it shipped defanged: replace_common in update_all_notebooks.py rewrites every YYYY.M.D literal in a cell to 2026.2.1, and 2026.9.7 satisfies that, so the guard passed on the old release. I only caught it because I tested the guard against a downgraded environment instead of trusting it.
So the shipped check probes the capability instead, which no version-rewriting pass can touch:
from unsloth_zoo.rl_replacements import distillation_chunked_jsd
from unsloth.models.rl_replacements import RL_FUNCTIONS
_patches = [getattr(f, "__name__", "") for f in RL_FUNCTIONS.get("gkd_trainer", [])]
assert any("compute_loss" in n for n in _patches), ...Verified both directions: on 2026.10.5 it prints ['gkd_trainer_mask_prompt', 'gkd_trainer_compute_loss']; on 2026.9.7 it raises AssertionError naming an empty patch list.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 56163fb4e1
ℹ️ 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".
| " git+https://github.com/unslothai/unsloth-zoo git+https://github.com/unslothai/unsloth" | ||
| "# Probing the capability, not a version string: the notebook generator\n", | ||
| "# rewrites every version literal in a cell, which silently defangs a pin.\n", | ||
| "from unsloth_zoo.rl_replacements import distillation_chunked_jsd\n", |
There was a problem hiding this comment.
Import Unsloth before probing unsloth_zoo
On a fresh Colab or Kaggle kernel, the installation cell installs these packages but does not import them, so this first import initializes unsloth_zoo directly. Its package initializer requires the UNSLOTH_IS_PRESENT marker established by importing unsloth and otherwise raises ImportError: Please install Unsloth via pip install unsloth; consequently the new capability-check cell stops every clean run before the later FastLanguageModel import. Import unsloth (or unsloth.models.rl_replacements) before accessing unsloth_zoo.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Correct, and this one would have broken every clean run. Fixed in f979c12 by importing unsloth first.
Worth recording why I did not catch it myself: this workspace exports UNSLOTH_IS_PRESENT=1, so the standalone from unsloth_zoo.rl_replacements import ... succeeded locally and my end-to-end run passed. Re-running with env -u UNSLOTH_IS_PRESENT reproduces exactly what you described:
File ".../unsloth_zoo/__init__.py", line 556, in <module>
raise ImportError("Please install Unsloth via `pip install unsloth`!")
So the guard I added to stop a silent failure would itself have been a loud failure for every user on a fresh kernel. Both arms now behave with the variable unset: 2026.10.5 prints ['gkd_trainer_mask_prompt', 'gkd_trainer_compute_loss'], and 2026.9.7 raises the intended AssertionError rather than an ImportError.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f979c12115
ℹ️ 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".
| "# Probing the capability, not a version string: the notebook generator\n", | ||
| "# rewrites every version literal in a cell, which silently defangs a pin.\n", | ||
| "# unsloth first: unsloth_zoo refuses to import until it sets UNSLOTH_IS_PRESENT.\n", | ||
| "import unsloth\n", |
There was a problem hiding this comment.
Set compile-disable before importing Unsloth
When CONFIG is changed to gemma-4 on a T4-class runtime, this new early import initializes Unsloth while UNSLOTH_COMPILE_DISABLE is still unset. The configuration cell only sets that variable later (lines 186–188), after the compiler module has cached its import-time setting, so the notebook's documented workaround is ineffective and the gradient-checkpoint tensor-rank failure can return. Establish the selected configuration and environment flag before this capability import.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Right, and I nearly argued the opposite. Fixed in eb769f7: the config and UNSLOTH_COMPILE_DISABLE cells now run first, and the capability check follows them.
The reason this was easy to get wrong is worth writing down. Every occurrence of the name that looks like the import-time cache is inside a code-generation string template:
line 496: inside a string template
line 3374: inside a string template
line 3475: inside a string template
line 3598: inside a string template
An AST pass confirms it, and unsloth_zoo.compiler has no such attribute at runtime, so on that evidence the flag appeared to be read only at call time (compiler.py:5939-5940 genuinely are). The live constant is in a different module, unsloth_zoo/temporary_patches/common.py:43, consumed by module-level if UNSLOTH_COMPILE_DISABLE: branches at lines 318 and 333 that execute at import. I only found it by walking module-level assignments and excluding string spans, rather than grepping.
Measured both orders:
| frozen constant | gemma-4 workaround | |
|---|---|---|
import unsloth, then set the flag |
False |
lost |
set the flag, then import unsloth |
True |
honoured |
With CONFIG = "gemma-4" the notebook now reports gemma-4 frozen compile-disable: True.
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! 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". |
unsloth==2026.10.5 carries everything the forced-reinstall cell existed for (unslothai/unsloth#11440, unsloth-zoo#1310, the reentrant pin, and the chunked JSD wiring from unslothai/unsloth#12136), checked against the installed wheel rather than the tags, so the cell now only drags users off a release onto main. Removing it exposes a hole: the shared install says a bare `pip install unsloth`, which pip treats as satisfied by ANY installed version. Measured: with 2026.9.7 present, `pip install unsloth` left 2026.9.7 in place, and that release has no chunked loss. Both install variants now pass --upgrade with a minimum, Kaggle's included, and the notebook checks the capability before training. The check probes RL_FUNCTIONS["gkd_trainer"] rather than a version, because replace_common rewrites every YYYY.M.D literal in a cell to 2026.2.1, which 2026.9.7 satisfies; a version assert shipped defanged. It imports unsloth before unsloth_zoo, which refuses to import until UNSLOTH_IS_PRESENT is set. And it runs after the config and UNSLOTH_COMPILE_DISABLE cells, because unsloth_zoo/temporary_patches/common.py:43 freezes that flag at import, so an earlier unsloth import silently lost the gemma-4 workaround. The memory claim is also no longer true. Measured at the settings this notebook ships, with UNSLOTH_GKD_CHUNKED=0 as the dense control: dense 9.94 GiB peak, loss 0.375788, 49.3 s chunked 3.03 GiB peak, loss 0.375766, 63.5 s 3.3x off the peak for the same loss to 2.2e-05, at about 30% more time at batch 1; level at batch 2, and faster on gemma-4 at batch 2 (11.1 s vs 14.8 s) while dropping 51.34 GiB to 23.63 GiB. The qwen3 table row is re-measured on a free single Colab T4 (loss 0.367, 392/392 adapters, 3.36 GB, verified from the executed notebook) and the table says which rows predate the chunked loss. Rebased onto current main: the earlier branch was 25 commits behind and would have reverted four workflow files Dependabot had updated, which is also why only CodeQL ran on it. molab was removed from the repo meanwhile (#394), so that artefact is gone rather than regenerated. Verified: gemma-4 frozen compile-disable True, the guard raises AssertionError on 2026.9.7 with UNSLOTH_IS_PRESENT unset, and the notebook runs end to end at loss 0.370, 392/392 adapters, 3.28 GB. The suite's 18 failures are on the Qwen3 (4B) tool-use notebooks from #395 and reproduce unchanged on clean main.
eb769f7 to
e093871
Compare
Rebased, and that turned out to be why CI was not runningAcross five pushes this PR only ever ran The branch was 25 commits behind main and carried stale copies of four workflow files, so merging it would have reverted Dependabot's action pin updates from earlier today in Rebased onto Two things changed in the process:
Everything was re-verified on the new base rather than assumed to carry over: One pre-existing failure set to flag, so it is not mistaken for mine: the suite reports 18 failures on the |
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 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". |
|
Merging. Codex is clean on
That is pre-existing on Raising that separately, since a failing hard gate on |
Two things in this notebook became wrong when
unsloth==2026.10.5shipped.The git+ install cell. It force-reinstalled unsloth and unsloth-zoo from main, with a note saying to delete it once a release carried #11440 and unsloth-zoo#1310. The release carries both. I checked the installed wheel rather than the tags: the reentrant pin, the GKDConfig handling, the chunked JSD and its GradScaler support are all present. Leaving the cell in would now pull users off a release onto main.
The memory claim. It said GKD "holds full
(batch, seq, vocab)logits for both models, so peak memory follows the vocabulary". #12136 routed the generatedcompute_lossthrough the chunked generalized JSD, so those logits are never materialised.UNSLOTH_GKD_CHUNKED=0falls back to the dense loss, which makes a clean one-variable control. At the settings this notebook ships (batch 1, accumulation 4, 30 steps, seq 1024, Qwen3-0.6B from Qwen3-1.7B, both 4-bit):3.3x off the peak for the same loss to 2.2e-05, costing about 30% more time at batch 1. That cost is batch-dependent and I am not hiding it: at batch 2 the arms were level, and gemma-4 at batch 2 was faster chunked (11.1 s vs 14.8 s) while dropping 51.34 GiB to 23.63 GiB.
Table. The
qwen3row is re-measured on a free Colab single T4: loss 0.367, 392/392 adapters, 3.36 GB peak, against 10.9 GB on two T4s before. Verified from the executed notebook, not the exit code: 16/16 cells clean, 30 steps logged,Tesla T4,Num GPUs used = 1.The other three rows predate the chunked loss and the table now says so rather than passing them off as current.
gemma-4andmuse-glimmerneed two T4s for their weights alone (19 GB and 22 GB), so re-measuring them needs Kaggle, where all three tokens are currently out of GPU quota until 2026-10-17.muse-glimmerpreviously OOM'd by only 208 MiB, so it is a live candidate to start fitting; I will re-run it when the quota resets rather than guess.Prose held at 994 markdown words, just under where #375 left it.
18296 tests pass.