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 Using Filters guide #4028

Merged
merged 1 commit into from
Jun 28, 2024
Merged

[nnx] add Using Filters guide #4028

merged 1 commit into from
Jun 28, 2024

Conversation

cgarciae
Copy link
Collaborator

@cgarciae cgarciae commented Jun 25, 2024

What does this PR do?

  • Adds filters_guide to the docs: preview
  • Improves current Filters by making them hashable and equatable.

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@cgarciae
Copy link
Collaborator Author

Hey @IvyZX, something weird happened with the other PR so I am continuing it here.

Thanks for reviewing the PR, sadly I hadn't pushed all my changes and the guide was half way through. Check out the new content. I focused the guide on making it clear how filters work and how state is filtered. Let me know if you still think I should add more examples.

@jlperla
Copy link
Contributor

jlperla commented Jun 26, 2024

@cgarciae this is beautiful! Makes a big difference in forming a mental model on NNX.

Is a new release planned anytime the next month or so which encapsulates this sort of stuff? I would love to prepare some of these notes fall teaching to show the NNX workflow

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.

Overall LGTM - just a few minor comments to clarify things. This looks much better!

| | `PathContains(key)` | Matches values that have an associated `path` that contains the given `key` |
| `'{filter}'` | `WithTag('{filter}')` | Matches values that have string `tag` attribute equal to `'{filter}'` |
| `(*filters)` | `Any(*filters)` | Matches values that match any of the inner `filters` |
| `[*filters]` | `Any(*filters)` | Matches values that match all of the inner `filters` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is some part of this grid duplicated? Not sure I understood it fully but the tuple is "any" while the list is "all"? This feels a bit confusing...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Merged them into 1 row to clarify that both tuples and lists are converted to Any

Reversing the order will make sure that the `SpecialParam` are captured first

```{code-cell}
graphdef, special_params, params = split(bar, SpecialParam, nnx.Param) # correct!
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we introduced the filter DSL above, it would be cool to showcase it here in this example!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added an example using the DSL in nnx.vmap

@cgarciae
Copy link
Collaborator Author

@jlperla coincidentally I just created a new release (needed it for a bug fix), I can create another one soon. However, all the features shown here are stable so it should not impact the information in the guide a lot (except for some types being exposed at the top-level).

@jlperla
Copy link
Contributor

jlperla commented Jun 26, 2024

Thanks @cgarciae If the interfaces are stable then that is good for me to experiment. I will try some of this out in the next month and then update my lecture notes august (at which point I can point to new docs) so no time pressure on my side.

Looking forward to trying out the library. Also keen to see in august how the "training loop" pattern with metrics, optax, etc. that I can teach as a boilerplate - which I noticed you were working on. Lots of movement!

@cgarciae cgarciae force-pushed the nnx-filters-guide2 branch 2 times, most recently from 36f2b32 to 2ae48a7 Compare June 27, 2024 13:49
@copybara-service copybara-service bot merged commit 15e0e8d into main Jun 28, 2024
18 checks passed
@copybara-service copybara-service bot deleted the nnx-filters-guide2 branch June 28, 2024 15:37
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