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

[nnx] Add Sphinx Docs #3678

Merged
merged 1 commit into from
Feb 15, 2024
Merged

[nnx] Add Sphinx Docs #3678

merged 1 commit into from
Feb 15, 2024

Conversation

cgarciae
Copy link
Collaborator

@cgarciae cgarciae commented Feb 4, 2024

What does this PR do?

Preview: https://flax--3678.org.readthedocs.build/en/3678/experimental/nnx/index.html

  • Adds a landing page (ported from Flax).
  • Adds NNX Basics guide (proposed primary guide).
  • Adds MNIST Tutorial (ported Linen's Quick Start).

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@codecov-commenter
Copy link

codecov-commenter commented Feb 4, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (d9585e0) 56.14% compared to head (ab2a30d) 57.71%.
Report is 16 commits behind head on main.

Files Patch % Lines
flax/experimental/nnx/nnx/module.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3678      +/-   ##
==========================================
+ Coverage   56.14%   57.71%   +1.56%     
==========================================
  Files         102      103       +1     
  Lines       12186    12289     +103     
==========================================
+ Hits         6842     7092     +250     
+ Misses       5344     5197     -147     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cgarciae cgarciae force-pushed the nnx-quickstart2 branch 16 times, most recently from ecd9dcd to ab2a30d Compare February 12, 2024 20:05
@cgarciae cgarciae changed the title [nnx] add Quick Start [nnx] Add Sphinx Docs Feb 12, 2024

## 5. Create the `TrainState`

In Flax, a common practice is to use a dataclass to encapsulate the training state, including the step number, parameters, and optimizer state. The [`flax.training.train_state.TrainState`](https://flax.readthedocs.io/en/latest/flax.training.html#train-state) class is ideal for basic use cases, simplifying the process by allowing you to pass a single argument to functions like `train_step`.
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, the fusion of Flax and NNX!

Do we have to use TrainState in this example? Does it make sense to make it more self-contained and free of abstractions from non-NNX parts of Flax?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The Functional API works 🙂. However, I've been thinking of creating a Module-based TrainState that would be even more convenient that the current Pytree API.


y, state = forward(static, state, x=jnp.ones((1, 2)))
# 5. Update the state of the original Module
model.update(state)
Copy link
Member

Choose a reason for hiding this comment

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

How is model.update(state) different from static.merge(state)?

Copy link
Collaborator Author

@cgarciae cgarciae Feb 13, 2024

Choose a reason for hiding this comment

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

update mutates the original references with the new state, merge creates new references with the given state.

@copybara-service copybara-service bot merged commit efbe705 into main Feb 15, 2024
21 checks passed
@copybara-service copybara-service bot deleted the nnx-quickstart2 branch February 15, 2024 13:39
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.

3 participants