flax icon indicating copy to clipboard operation
flax copied to clipboard

[docs]: Improve docs for NNX API Reference

Open ibbyml opened this issue 10 months ago • 5 comments

Hi,

I’d like to improve the NNX API reference docs (not Linen). While working on a smaller docs issue (#5107), I noticed a few recurring problems across the NNX API reference: incomplete indexing/toctrees, inconsistent Sphinx cross-references vs code formatting, and missing/unclear docstrings for user-facing symbols. Some pages also look copied from older docs and don’t match the current NNX surface.


Example:

  • flax.nnx.unflatten in the graph section has a kwarg outer_index_outer_ref=None, but its docstring refers to index_ref_cache (which doesn’t exist).
Image

To keep review manageable, I’ll do this as a series of small PRs, going section by section in the API Reference page. To keep the scope manageable I'll focus on docs + docstrings only (no behavioral changes).

Is it ok if I send small PRs starting with flax.nnx.graph?

Thanks!

ibbyml avatar Jan 03 '26 20:01 ibbyml

Hi @ibbyml, thanks for pointing that out. Yes, keeping the docs updated during the development can be a bit complex. If you can pointing out all these inconsistencies and send small fixes, it would be awesome.

The team is also working on how to improve the merging process on the approved PRs, but meanwhile having the fixes on GitHub would be very helpful!

vfdev-5 avatar Jan 05 '26 10:01 vfdev-5

Hi @ibbyml and @vfdev-5, this sounds like a great initiative! To help parallelize the effort, I can take ownership of auditing the flax.nnx.nn module (Linear, Conv, Attention, etc.).

I'll check for the same inconsistencies (missing args, broken cross-refs, and outdated Linen-style docstrings) and submit them as separate, small PRs. Does that sound good?

ayushkumrdev avatar Jan 06 '26 17:01 ayushkumrdev

I'd like to take the filterlib section. The filter classes (WithTag, PathContains, OfType, Any, All, Not, Everything, Nothing) are exported but currently render with no docstrings in the API reference, I'll add short docstrings for each based on the descriptions in the Filters guide.

santihdzs avatar May 29 '26 02:05 santihdzs

Hi @vfdev-5 , I'd like to take the flax.nnx.training section (Metrics, Optimizer, EMA) as part of this docs audit. A few concrete inconsistencies I've already spotted there:

  • EMA.apply_to() isn't rendered in the API reference — training/ema.rst only lists __init__, update in :members:, even though apply_to() is public and is used in EMA's own docstring examples.
  • Accuracy renders inconsistently with the other metrics: training/metrics.rst lists :members: update for it, while Metric/Average/Welford/MultiMetric all list __init__, reset, update, compute. As a result Accuracy's constructor doc (the threshold arg) isn't shown.
  • Statistics (returned by Welford.compute(), and shown in its rendered example) has no docstring or reference entry.

I'll keep it docs + docstrings only, no behavioral changes, and send it as a small PR (or a couple) scoped to this section. Sound good?

greekera1000 avatar Aug 04 '26 20:08 greekera1000

Hi @vfdev-5, following up on my training section PR (#5544) — I'd like to also take the variables, rnglib, and helpers sections. Concrete issues found:

with_metadata is listed in variables.rst via autofunction but has no docstring, so it renders as a bare signature. RngStream has no docstring of its own — the API reference shows the generic inherited Pytree docstring ("Base class for all NNX objects."), which is misleading. List and Dict (in helpers) both have a "contained a mixed set" → "containing a mixed set" typo.

Docs + docstrings only, no behavioral changes, small PR same as before.

greekera1000 avatar Aug 05 '26 06:08 greekera1000