Skip to content

[Stacked PR 1/5] Fix upstream pyink formatting and GMM v2 compatibility for Qwen3.5 - #5151

Open
Rohan-Bierneni wants to merge 1 commit into
mainfrom
rbierneni-gdn-1-ci-hygiene
Open

[Stacked PR 1/5] Fix upstream pyink formatting and GMM v2 compatibility for Qwen3.5#5151
Rohan-Bierneni wants to merge 1 commit into
mainfrom
rbierneni-gdn-1-ci-hygiene

Conversation

@Rohan-Bierneni

@Rohan-Bierneni Rohan-Bierneni commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

Stacked PR Chain

Stack Status Branch Base PR
PR 1 🚀 This PR rbierneni-gdn-1-ci-hygiene main #5151 - [Stacked PR 1/5] Fix upstream pyink formatting and GMM v2 compatibility for Qwen3.5
PR 2 ⏳ Stacked on PR 1 rbierneni-gdn-2-fwd-kernel rbierneni-gdn-1-ci-hygiene #5152 - [Stacked PR 2/5] Import local Tokamax GDN forward kernel with custom remat for backward pass support
PR 3 ⏳ Stacked on PR 2 rbierneni-gdn-3-bwd-kernel rbierneni-gdn-2-fwd-kernel #5153 - [Stacked PR 3/5] Add decoupled GDN Pallas backward pass kernel and parity tests
PR 4 ⏳ Stacked on PR 3 rbierneni-gdn-4-model-integration rbierneni-gdn-3-bwd-kernel #5154 - [Stacked PR 4/5] Enable GDN backward pass kernel and hybrid precision in Qwen3 model
PR 5 ⏳ Stacked on PR 4 rbierneni-gdnv3-bwd rbierneni-gdn-4-model-integration #5098 - [Stacked PR 5/5] Add GDN backward pass 8k and 64k latency and memory benchmark suite

Description

This is PR 1 of 5 in the stacked series enabling the Pallas Gated Delta Net (GDN) backward pass kernel in MaxText.

This PR addresses upstream CI hygiene and kernel compatibility prerequisites:

  1. Pyink Formatting Alignment: Re-formats src/maxtext/models/qwen3_5.py, tests/integration/train_tests.py, and tests/unit/train_compile_test.py with pyink following recent main merges to conform with repository formatting requirements.
  2. GMM v2 Fix for Qwen3.5 Compatibility: Updates sublane tiling heuristics in src/maxtext/kernels/megablox/pallas_mosaic_tpu_v2_gmm_kernel.py and src/maxtext/kernels/megablox/pallas_mosaic_tpu_v2_tgmm_kernel.py to ensure proper tile dimension boundaries on TPU sublanes (enforcing minimum sublane size of 16 and matching LHS/RHS sublanes in TGMM) to enable compatibility with the Qwen3.5 MoE model.

Files Changed

  • src/maxtext/models/qwen3_5.py: Pyink formatting conformance.
  • tests/integration/train_tests.py: Pyink formatting conformance.
  • tests/unit/train_compile_test.py: Pyink formatting conformance.
  • src/maxtext/kernels/megablox/pallas_mosaic_tpu_v2_gmm_kernel.py: Sublane tiling calculation fix for Qwen3.5 compatibility.
  • src/maxtext/kernels/megablox/pallas_mosaic_tpu_v2_tgmm_kernel.py: Sublane tiling calculation fix for Qwen3.5 compatibility.

Tests

  • Verified with pre-commit run --files ... (all hooks: codespell, pylint, pyink, yamllint passed).
  • Verified compilation tests in train_compile_test.py.

Checklist

  • I have performed a self-review of my code.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests and verified pre-commit linters pass.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request adjusts sublane tiling logic in Megablox TPU kernels and applies formatting cleanups to the Qwen3.5 model definition and tests. In the TGMM kernel, a change was made to compute a common sublane size using min(). Feedback indicates that using min can violate hardware tiling constraints for operands with larger requirements, and suggests using max() instead to ensure compatibility.

Comment on lines +224 to +226
common_sublane = min(size_lhs_sublane, size_rhs_sublane)
size_lhs_sublane = common_sublane
size_rhs_sublane = common_sublane

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using min to find the common_sublane can violate the hardware sublane tiling constraints of the operand with the larger sublane tiling requirement. For example, if size_lhs_sublane is 128 (e.g., for bf16) and size_rhs_sublane is 8, taking the minimum results in a common_sublane of 8. Setting size_lhs_sublane to 8 violates the 128-alignment requirement for bf16 on TPU, leading to compilation or runtime failures.

Since TPU sublane tilings are always powers of two, their least common multiple is simply their maximum. Using max instead of min ensures that the common sublane size is a multiple of both requirements, satisfying all hardware constraints.

Suggested change
common_sublane = min(size_lhs_sublane, size_rhs_sublane)
size_lhs_sublane = common_sublane
size_rhs_sublane = common_sublane
common_sublane = max(size_lhs_sublane, size_rhs_sublane)
size_lhs_sublane = common_sublane
size_rhs_sublane = common_sublane

@Rohan-Bierneni Rohan-Bierneni changed the title [Stacked PR 1/5] Fix upstream pyink formatting and megablox sublane tiling [Stacked PR 1/5] Fix upstream pyink formatting and GMM v2 compatibility for Qwen3.5 Sep 6, 2026
…iling

- Reformat qwen3.py, qwen3_5.py, pyconfig_test.py, train_tests.py, and train_compile_test.py with pyink to conform with upstream CI style requirements.
- Fix Megablox TPU v2 sublane tiling in pallas_mosaic_tpu_v2_gmm_kernel.py and pallas_mosaic_tpu_v2_tgmm_kernel.py to ensure correct tile dimension handling on TPU sublanes.
@Rohan-Bierneni
Rohan-Bierneni force-pushed the rbierneni-gdn-1-ci-hygiene branch from ee278f5 to a8aafbd Compare September 6, 2026 07:00
@codecov

codecov Bot commented Sep 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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