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

Support linen.LogicallyPartitioned <-> nnx.Variable #4161

Merged
merged 1 commit into from
Sep 10, 2024

Conversation

IvyZX
Copy link
Collaborator

@IvyZX IvyZX commented Aug 31, 2024

  • nnx.spmd API will now recognize another nnx.Variable field: sharding_rules
    • This corresponds to the logical partitioning rules in Linen.
  • Bridge API will now correctly recognize linen.LogicallyPartitioned boxes and convert them to this format.

@IvyZX IvyZX changed the title Support linen.LogicallyPartitioned <-> nnx.Variable [WIP] Support linen.LogicallyPartitioned <-> nnx.Variable Aug 31, 2024
@IvyZX IvyZX changed the title [WIP] Support linen.LogicallyPartitioned <-> nnx.Variable Support linen.LogicallyPartitioned <-> nnx.Variable Sep 10, 2024
@IvyZX IvyZX marked this pull request as ready for review September 10, 2024 00:18
@IvyZX IvyZX force-pushed the bdg-logic branch 2 times, most recently from fdb4e73 to 821bc64 Compare September 10, 2024 00:34
@IvyZX IvyZX requested review from cgarciae and levskaya and removed request for cgarciae September 10, 2024 00:45
Comment on lines 294 to 295
metadata['sharding'] = metadata['names']
del metadata['names']
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
metadata['sharding'] = metadata['names']
del metadata['names']
metadata['sharding'] = metadata.pop('names')

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Great idea!

"""Given a dict of `nnx.Variable` format metadata, create a `nn.Partitioned`."""
metadata['names'] = metadata['sharding']
del metadata['sharding']
fields = [x.name for x in dataclasses.fields(cls)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

feels like fields should be set

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think dataclasses.fields should already return de-duplicated names, otherwise the class cannot be built... but yeah we can add it

Copy link
Collaborator

Choose a reason for hiding this comment

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

oh I mean because in the line below we just use it to check for membership

"""Given a dict of `nnx.Variable` format metadata, create a `nn.LogicallyPartitioned`."""
metadata['names'], metadata['rules'] = metadata['sharding'], metadata['sharding_rules']
del metadata['sharding'], metadata['sharding_rules']
fields = [x.name for x in dataclasses.fields(cls)]
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as before

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same here

@copybara-service copybara-service bot merged commit f948154 into google:main Sep 10, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants