Skip to content

Large head attention follow-ups: compiled kill switch, 4-bit shard self check, forced float32 skip - #14188

Merged
danielhanchen merged 10 commits into
mainfrom
dh/fu-misc-u
Oct 19, 2026
Merged

danielhanchen merged 10 commits into
mainfrom
dh/fu-misc-u

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Follow-ups for the head-dim 512 attention kernel (#13869) and one test gap from #13888. The default path is unchanged except where noted.

  1. Kill switch read under compile. _enabled() was an lru_cache. Dynamo warns when it traces through that wrapper, and it re-reads the environment there, so compiled code could disagree with eager after the variable changed at runtime. It now reads the value once into a module-level holder that both paths share. _enabled.cache_clear() still resets it.
  2. 4-bit-only GPU shards skipped the self check. At load, the kernel self-checks every (device, dtype) holding fp16 / bf16 weights. A GPU that holds only bitsandbytes 4-bit weights (uint8 storage, for example with CPU-offloaded embeddings or a device-mapped shard) produced no target, so the kernel stayed off there. It now uses the 4-bit weights' compute dtype from quant_state.
  3. No wasted fp16 self check under forced float32. Models stamped _unsloth_forced_float32 (zoo's Gemma-4 float32 path) run attention in float32 on plain SDPA and never reach this router, so the patch now returns before the fp16 self check and autotune at load.
  4. Test only: test_rms_layernorm_backward_leaves_shared_grad_alone now sets _SAVE_OUTPUT and asserts the backward-from-output path runs. Before, its save_output = True cases never exercised that path.

Tests (GPU)

  • tests/test_large_head_attention.py: 3 new tests (compiled vs eager kill switch, 4-bit-only shard self check, forced float32 skip). They fail on main and pass here.
  • With tests/test_norm_backward_grad_alias.py: 52 passed.

Not run here: a real Gemma-4 load for items 2 and 3, or any timing. The kernel itself is unchanged.

@danielhanchen danielhanchen self-assigned this Oct 19, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-19T16:52:59.674711Z 0f9b36e New commits
🔒 Security Review ⚠️ Failed 2026-10-19T04:19:51.079666Z 1179583 PR opened
ℹ️ 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 chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1179583ba0

ℹ️ 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".

Comment thread unsloth/kernels/large_head_attention.py Outdated
Comment on lines +953 to +955
dtype = p.dtype
if dtype not in (torch.float16, torch.bfloat16):
dtype = getattr(getattr(p, "quant_state", None), "dtype", None)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use quant-state dtype for float-packed 4-bit weights

When a 4-bit parameter uses floating bnb_4bit_quant_storage that differs from its compute dtype (for example, fp16 storage with bf16 compute), p.dtype is a supported half type, so this branch never reads quant_state.dtype and self-checks the storage dtype instead. Compiled bf16 attention then finds no (device, torch.bfloat16) verdict and permanently falls back to SDPA; detect quantized parameters first and use their logical compute dtype regardless of the packed storage dtype.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in feed2c1: the self check now takes the dtype from the quant state whenever a parameter has one, so float16 storage with bfloat16 compute checks bfloat16. Added test_patch_self_checks_the_compute_dtype_of_float_packed_4bit, which fails on the previous head.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: feed2c1dac

ℹ️ 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 73d2598 into main Oct 19, 2026
@danielhanchen
danielhanchen deleted the dh/fu-misc-u branch October 19, 2026 18:21
danielhanchen added a commit that referenced this pull request Oct 19, 2026
## Summary

The `Core zoo` cells in `consolidated-tests-ci.yml` keep hitting their
25 minute job cap after the tests have already passed. In one cancelled
cell:

- the zoo `pytest -n 4` step ran from 08:41 to 09:03 and passed (3015
passed, 620 skipped),
- the job was then cancelled at 25:17 during `test_apply_fused_lm_head`
and the pip cache save.

The comment above the cap assumed a ~7.6 min zoo suite. It now takes up
to about 23 minutes on a busy runner, so the cap cancels cells that have
already passed. Today that cancelled Core zoo cells on #14152, #14165,
#14188, #14192, #14199 and #14207, and on staging runs. Each one needs a
manual rerun before the PR can merge.

This raises the cap to 35 minutes, the same as `consolidated`. Hung
tests are still bounded: `PYTEST_TIMEOUT: 300` in the step still names
the culprit per test.

## Tests

The workflow-parsing tests (`git grep -l consolidated-tests-ci --
tests`): 158 passed, 3 skipped.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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