Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JAX] Use default factory for not sharing mutable default values #1364

Merged
merged 2 commits into from
Dec 10, 2024

Conversation

zlsh80826
Copy link
Collaborator

Description

This PR addresses an issue caused by using mutable default values in dataclass fields, which can lead to unexpected behavior. More details are available in the official documentation.

Starting with Python 3.11, an explicit error is raised when mutable values are used as default values in dataclass fields. To resolve this, the default_factory parameter is now used as recommended in the documentation. This approach ensures that new instances of mutable types are created for each dataclass instance, avoiding shared state and related issues.

Fixes # (issue)

Type of change

  • Documentation change (change only to the documentation, either a fix or a new content)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Infra/Build change
  • Code refractor

Changes

Using default_factory to set an non-frozen dataclass as the default value

Checklist:

  • I have read and followed the contributing guidelines
  • The functionality is complete
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@zlsh80826 zlsh80826 force-pushed the rewang/fix-immutable-default branch 2 times, most recently from 09ca03e to f37d8b0 Compare December 10, 2024 06:56
@zlsh80826 zlsh80826 force-pushed the rewang/fix-immutable-default branch from f37d8b0 to 048ee59 Compare December 10, 2024 08:08
@zlsh80826
Copy link
Collaborator Author

/te-ci jax L1

@phu0ngng phu0ngng self-requested a review December 10, 2024 13:02
@phu0ngng
Copy link
Collaborator

The CI failed as follows:

  • on A100 node withtest_model_parallel_encoder.py::TestEncoder::test_te_bf16
  • L1 distributed test with test_distributed_layernorm.py

I think these failures are unrelated to the changes introduced in this PR.
Therefore, we can merge this PR to unblock the CI for now while looking into those failures.

@phu0ngng phu0ngng merged commit e4c99b0 into NVIDIA:main Dec 10, 2024
20 of 22 checks passed
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