Skip to content

Tests: follow the NF4 dequant cache into the for_inference and fp8 backward harnesses - #18368

Merged
danielhanchen merged 1 commit into
mainfrom
ci/tests-follow-nf4-dequant-cache-routing
Nov 18, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
ci/tests-follow-nf4-dequant-cache-routing

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Sixteen tests in the CPU "rest" shard fail on main since #18285, in two groups:

tests/test_for_inference_resets_inference_runs.py      (6)  KeyError: "'__name__' not in globals"
tests/test_return_logits_survives_for_training.py      (8)  KeyError: "'__name__' not in globals"
tests/test_fp8_down_proj_bf16_backward.py              (2)  RuntimeError: 0 active drivers ([]). There should only be one.

Seen on the staging run for #17742, which does not touch these files.

Cause

#18285 keeps dequantized NF4 LoRA base weights in a cache. Both new call paths are correct; the CPU harnesses could not follow them.

  1. FastBaseModel.for_inference (unsloth/models/vision.py) now clears that cache with an inline from ..kernels.dequant_cache import clear_dequant_cache. _fast_base_model() in test_return_logits_survives_for_training.py lifts for_inference / for_training out of the source and execs them in a namespace with no package. A relative import there raises KeyError: '__name__' not in globals. The harness already stubbed whole helpers for this reason, but this import sits in the lifted method itself.
  2. The LoRA backward now dequantizes through dequant_cache.dequantize. That function reads fast_dequantize from kernels.utils when called. The fp8 fixture only patched fast_lora.fast_dequantize, so the real Triton path ran on a CPU runner. For an fp8 quant state, dequantize falls straight through to fast_dequantize, so production behaviour is unchanged.

Fix

Test-only:

  • _fast_base_model() rewrites each relative from ..x import a in the lifted bodies to a = _relative_import("x", "a"), resolved from an explicit stub table. The table starts with clear_dequant_cache as a no-op. Guarded imports the fakes never reach still need no stub. One that a fake does reach without a stub fails with stub the relative import ('kernels.dequant_cache', 'clear_dequant_cache') lifted from unsloth/models, so the next inline import says what to add instead of surfacing as a KeyError.
  • The fp8 fixture patches fast_dequantize in kernels.utils as well as in fast_lora.

Verification

Tree Result (the three files)
main 16 failed, 5 passed
this branch 21 passed
this branch, stub table emptied (sabotage) 14 failed, each naming the missing stub
this branch, kernels.utils patch removed (sabotage) 2 failed, 0 active drivers

ruff is clean.

The 17th failure in that shard, test_grpo_autocast_disabled.py::test_reading_it_tolerates_an_older_trainer, has a different cause (#18335) and is handled separately.

…ckward harnesses

#18285 added two call paths the CPU harnesses could not follow:

- for_inference now does from ..kernels.dequant_cache import
  clear_dequant_cache. _fast_base_model execs the lifted methods in a
  namespace with no package, so 14 tests fail with
  KeyError: '__name__' not in globals. Relative imports in the lifted
  bodies now resolve through an explicit stub table; one a fake reaches
  without a stub fails naming the import.
- The LoRA backward dequantizes through dequant_cache.dequantize, which
  reads fast_dequantize from kernels.utils at call time, so the fp8
  fixture's fast_lora patch no longer reached it and 2 tests hit the
  real Triton driver. Patch it in kernels.utils too.
@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-18T17:25:13.406603Z c262233 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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: c262233d7e

ℹ️ 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 c619f16 into main Nov 18, 2026
@danielhanchen
danielhanchen deleted the ci/tests-follow-nf4-dequant-cache-routing branch November 18, 2026 17:26
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