Skip to content

fix(nnx): scope PartitionSpec default strictly to LoRA parameters in sharding analysis - #4689

Merged
copybara-service[bot] merged 1 commit into
mainfrom
test_957035527
Aug 4, 2026
Merged

fix(nnx): scope PartitionSpec default strictly to LoRA parameters in sharding analysis#4689
copybara-service[bot] merged 1 commit into
mainfrom
test_957035527

Conversation

@copybara-service

@copybara-service copybara-service Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

fix(nnx): scope PartitionSpec default strictly to LoRA parameters in sharding analysis

This CL is a follow-up fix for PR #4501 (src/maxtext/utils/sharding.py):

  • Scopes PartitionSpec P() defaulting strictly to LoRA parameters (isinstance(p_leaf, nnx.LoRAParam) or 'lora' in parameter name), allowing NNX LoRA models to execute safely without missing-spec errors.
  • Standard NNX parameters (nnx.Param) and standard Linen parameters remain None so unit tests (test_mixed_sharding_fails) throw an AssertionError on unannotated arrays as expected (tolerance=0.5 untouched).
  • Keeps element counts (p_leaf.size) for unsharded parameter totals to preserve mixed-precision sharding validation.

Tests

  • Verified tests/unit/maxtext_utils_test.py::TestAssertParamsSufficientlySharded (7/7 passed with tolerance=0.5 untouched).
  • Verified tests/integration/lora_e2e_nnx_test.py (sharding validation passed across all 10 tests).

Checklist

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests and provided workload details above.
  • I have made or will make corresponding changes to the doc if needed.

@codecov

codecov Bot commented Jul 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/utils/sharding.py 60.00% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@copybara-service
copybara-service Bot force-pushed the test_957035527 branch 4 times, most recently from 5229448 to 3e677e0 Compare July 31, 2026 14:21
@copybara-service
copybara-service Bot force-pushed the test_957035527 branch 7 times, most recently from f583668 to 2fa5fc3 Compare July 31, 2026 17:21
@copybara-service
copybara-service Bot force-pushed the test_957035527 branch 4 times, most recently from 07d738d to 9843e44 Compare August 3, 2026 10:48
@copybara-service copybara-service Bot changed the title fix(ci): resolve CI failures for PR #4501 sharding and Tunix adapter rollout regression fix(nnx): scope PartitionSpec default to NNX variables in sharding analysis Aug 3, 2026
@copybara-service copybara-service Bot changed the title fix(nnx): scope PartitionSpec default to NNX variables in sharding analysis fix(nnx): scope PartitionSpec default strictly to LoRA parameters in sharding analysis Aug 3, 2026
@copybara-service
copybara-service Bot force-pushed the test_957035527 branch 5 times, most recently from 51d8810 to dba84fb Compare August 3, 2026 15:21
@copybara-service
copybara-service Bot force-pushed the test_957035527 branch 7 times, most recently from 8b3ab75 to 6c9a2c1 Compare August 4, 2026 08:26
…sharding analysis

This CL is a follow-up fix for PR #4501 (`src/maxtext/utils/sharding.py`):
- Scopes `PartitionSpec P()` defaulting strictly to LoRA parameters (`isinstance(p_leaf, nnx.LoRAParam)` or `'lora'` in parameter name), allowing NNX LoRA models to execute safely without missing-spec errors.
- Standard NNX parameters (`nnx.Param`) and standard Linen parameters remain `None` so unit tests (`test_mixed_sharding_fails`) throw an `AssertionError` on unannotated arrays as expected (`tolerance=0.5` untouched).
- Keeps element counts (`p_leaf.size`) for unsharded parameter totals to preserve mixed-precision sharding validation.

# Tests
- Verified `tests/unit/maxtext_utils_test.py::TestAssertParamsSufficientlySharded` (7/7 passed with tolerance=0.5 untouched).
- Verified `tests/integration/lora_e2e_nnx_test.py` (sharding validation passed across all 10 tests).

# Checklist
- [x] I have performed a self-review of my code. For an optional AI review, add the `gemini-review` label.
- [x] I have necessary comments in my code, particularly in hard-to-understand areas.
- [x] I have run end-to-end tests and provided workload details above.
- [x] I have made or will make corresponding changes to the doc if needed.

PiperOrigin-RevId: 958869746
@copybara-service
copybara-service Bot merged commit 29a0ad6 into main Aug 4, 2026
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.

2 participants