Skip to content

MoE grouped GEMM: skip kernel-info logging work unless debug logging is on - #14787

Merged
danielhanchen merged 2 commits into
mainfrom
ta-u-moelog
Oct 22, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
ta-u-moelog

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What was wrong

log_kernel_info in unsloth/kernels/moe/grouped_gemm/interface.py runs after every grouped GEMM launch (forward, dX and dW, so three times per MoE layer per training step). It read name, n_regs, n_spills and metadata from the compiled kernel and built two f-strings before calling logger.debug. The logger is at the default level (WARNING), so the messages were dropped, but the formatting of the KernelMetadata namedtuple still ran on every call.

Change

Return early unless logger.isEnabledFor(logging.DEBUG). With debug logging on, the output is unchanged.

Validation

B200, torch 2.14 + Triton 3.8, real CompiledKernel from an autotuned Triton kernel, 5 x 20000 calls:

call base (us/call, median [min, max]) this PR
log_kernel_info(ck) 6.85 [6.54, 8.20] 0.19 [0.12, 0.22]
log_kernel_info(ck, best_config) 7.66 [7.53, 9.29] 0.25 [0.25, 0.27]

That is about 20 us of host time per MoE layer per step on the unsloth_triton backend.

  • With logger.setLevel(logging.DEBUG) both arms print the same two lines (k: n_regs=... metadata=KernelMetadata(...) and k autotuned best_config: ...).
  • New tests/test_grouped_gemm_log_kernel_info.py: the no-debug test fails on base (it reads the compiled kernel's attributes) and passes here; the debug test passes on both.
  • Tests: the new test plus the grouped GEMM and MoE autotune test files: 53 passed on torch 2.10 + Triton 3.6 and on torch 2.14 + Triton 3.8.

Not covered

  • No end-to-end MoE training step timing; the saving is host-side and only shows when the step is launch bound.

…nless debug logging is on

log_kernel_info ran after every forward / dX / dW launch and built its debug
f-strings (the compiled kernel's full metadata) even with logging off: ~12 us
of host time per launch (57 -> 45 us for a small forward). It now returns early
unless the logger is enabled for DEBUG.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

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 🔄 Running since 2026-10-22T19:29:41.989501Z a7a7e98 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
danielhanchen merged commit 390b866 into main Oct 22, 2026
3 of 29 checks passed
@danielhanchen
danielhanchen deleted the ta-u-moelog branch October 22, 2026 21:33
danielhanchen added a commit that referenced this pull request Oct 22, 2026
pre-commit.ci fails `ruff-format-with-kwargs` on every open PR (#14806,
#14805, #14803, #14790, #14785, #14781, #14780, #14777, #14776, #14775,
#14774, #14773, #14772, #14770, #14769, #14768, and others): "files were
modified by this hook". pre-commit.ci runs the hooks on all files, and
20 files on main (26 by the time this lands) are not in the formatter's
output, so every PR is reformatted outside its own diff. Where
pre-commit.ci can push, its autofix commit drags those unrelated files
into the PR (for example #14790's touches `tests/test_block_compile.py`,
`tests/test_bnb_integration_compile.py` and `unsloth/models/_utils.py`).

The drift came in with PRs merged today, among them #14702, #14751,
#14759, #14784, #14786, #14787, #14788, #14791 and the FP8 block decode,
GRPO routing replay, 4-bit decode, compiled blocks and MoE LoRA target
changes.

### Change

`python scripts/run_ruff_format.py` (the hook's own entry point,
`ruff==0.6.9` as pinned in `.pre-commit-config.yaml`) applied to those
20 files, plus 6 more from #14739, #14779 and #14806, which merged while
this was open. Formatting only.

### Verification

- Every changed file parses to an identical AST before and after.
- A second run of the hook over the same files changes nothing (fixed
point), and over all tracked Python files on this branch it changes
nothing.
- `ruff check` passes on the changed files;
`tests/test_formatter_fixed_point.py` passes (16).

Open PRs pick this up on their next pre-commit.ci run after merging
main.
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