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

Add why nnx #4240

Merged
merged 1 commit into from
Oct 8, 2024
Merged

Add why nnx #4240

merged 1 commit into from
Oct 8, 2024

Conversation

cgarciae
Copy link
Collaborator

@cgarciae cgarciae commented Oct 1, 2024

What does this PR do?

Preview

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@cgarciae cgarciae changed the title improve why nnx Add why nnx Oct 2, 2024
@cgarciae cgarciae force-pushed the why-nnx branch 5 times, most recently from 277c4ee to 2da1565 Compare October 3, 2024 15:59
Copy link
Collaborator

@IvyZX IvyZX left a comment

Choose a reason for hiding this comment

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

Very informative and cool! Just a few nits.

docs_nnx/why.rst Outdated
for SPMD annotations, optimizer metadata, etc.

One choice we made was to use functional (``compact``) semantics for NN programming via the lazy initialization of parameters,
this made for concise implementation code and aligned our API with Haiku. However, this also meant that the semantics of
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: "concise implementation"

docs_nnx/why.rst Outdated
Inspection
^^^^^^^^^^
The first improvement is that Flax NNX modules are regular Python objects, so you can easily
construct and inspect them. Because Flax Linen Modules are lazy some attributes are not available
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Because Flax Linen Modules are lazy some attributes are not available upon construction and are only accesible at runtime, this makes it hard to inspect and debug.

"Because Flax Linen Modules are lazy, some attributes are not available upon construction and are only accesible at runtime. This makes it hard to inspect and debug."

docs_nnx/why.rst Outdated
z = model.encode(x)
y = model.decoder(z)

Note that in Linen, calling submodules directly is might not be possible as they are not initialized
Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that in Linen, calling submodules directly is might not be possible as they are not initialized so you must construct a new instance, and also the proper parameter structure must be provided.

"Note that in Linen, calling submodules directly is not possible as they are not initialized. So you must construct a new instance and provide proper parameter structure."

docs_nnx/why.rst Outdated

State Handling
^^^^^^^^^^^^^^
One of the areas where Flax Linen is notoriuosly complex is in handling state. When you either use a
Copy link
Collaborator

Choose a reason for hiding this comment

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

notoriuosly -> notoriously

@copybara-service copybara-service bot merged commit 94f6440 into main Oct 8, 2024
20 checks passed
@copybara-service copybara-service bot deleted the why-nnx branch October 8, 2024 13:51
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