Skip to content

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

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_957035527
Open

fix(nnx): scope PartitionSpec default strictly to LoRA parameters in sharding analysis#4689
copybara-service[bot] wants to merge 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 0% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/maxtext/utils/sharding.py 0.00% 5 Missing ⚠️

📢 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 10 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 5 times, most recently from 44b6f1a to 8219228 Compare August 4, 2026 03:23
…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: 957035527
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