[docs]: Improve docs for NNX API Reference
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.unflattenin the graph section has a kwargouter_index_outer_ref=None, but its docstring refers toindex_ref_cache(which doesn’t exist).
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!
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!
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?
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.
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.rstonly lists__init__, updatein:members:, even thoughapply_to()is public and is used in EMA's own docstring examples.Accuracyrenders inconsistently with the other metrics:training/metrics.rstlists:members: updatefor it, whileMetric/Average/Welford/MultiMetricall list__init__, reset, update, compute. As a resultAccuracy's constructor doc (thethresholdarg) isn't shown.Statistics(returned byWelford.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?
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.