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

Tracking issue: inline docstrings #21461

Open
jakevdp opened this issue May 28, 2024 · 2 comments
Open

Tracking issue: inline docstrings #21461

jakevdp opened this issue May 28, 2024 · 2 comments
Assignees

Comments

@jakevdp
Copy link
Collaborator

jakevdp commented May 28, 2024

For many public APIs, JAX currently uses the jax._src.numpy.util.implements helper to define docstrings dynamically at runtime. This has several drawbacks:

  1. The docstrings extracted from NumPy do not always precisely match the semantics of the associated JAX function. This leads to confusion for people reading these docs.
  2. JAX-specific argument requirements should be documented: for example, some functions require particular parameters to be static, and we should document this.
  3. The dynamic docstrings do not include example usage: we've stripped all examples from these dynamically-generated docs, because often JAX-specific logic is necessary.
  4. Development environments like PyCharm are unable to show these dynamically-generated docs
  5. For some submodules, the current logic necessitates runtime dependency on upstream packages (e.g. jax.scipy imports scipy), and this adds to the import-time startup cost.
  6. Wrapped docstrings refer to symbols at import time, so if downstream libraries remove a symbol, JAX cannot be imported! This is currently causing problems for jax versions earlier than 0.4.27, because recent scipy removed symbols from its namespace.
  7. The implements decorator, despite being correctly annotated, can cause some type checkers to not recognize the input/output annotations of the wrapped function (this has been observed with pytype)

The implements decorator was originally added as a way to quickly bootstrap development of the jax.numpy API, but that is no longer necessary. For all these reasons, we'd like to migrate to static, JAX-specific inline docstrings.

A challenge here is that we cannot simply copy and modify the existing dynamic docstrings: they come from numpy, and for licensing reasons, we cannot replicate NumPy docstring verbiage within the JAX repository. For this reason, each docstring must be rewritten from scratch, without referencing the text of the NumPy version of the documentation.

@apghml
Copy link

apghml commented May 28, 2024

Looking forward to it!

they come from numpy, and for licensing reasons, we cannot replicate NumPy docstring verbiage within the JAX repository

IANAL, but isn't Numpy under a 3-clause BSD license, which is Apache-compatible? The Apache Software Foundation itself seems to allow 3-clause BSD code within Apache Software Foundation projects licensed under the Apache license: https://www.apache.org/legal/resolved.html

@jakevdp
Copy link
Collaborator Author

jakevdp commented May 28, 2024

IANAL either, which is why I do not specualate on such things 😁. But for reasons I won't get into, rewriting from scratch is the way we need to do it here.

copybara-service bot pushed a commit that referenced this issue Sep 20, 2024
…ng, jnp.kaiser

Part of #21461

PiperOrigin-RevId: 676565142
copybara-service bot pushed a commit that referenced this issue Sep 20, 2024
…ng, jnp.kaiser

Part of #21461

PiperOrigin-RevId: 676866721
rajasekharporeddy pushed a commit to rajasekharporeddy/jax that referenced this issue Sep 20, 2024
…ng, jnp.kaiser

Part of jax-ml#21461

PiperOrigin-RevId: 676866721
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants