Skip to content

Fix broken from_local usage examples in backend module docstrings.#20

Merged
copybara-service[bot] merged 2 commits into
google:mainfrom
vraj130:fix-from-local-docstrings
Jul 20, 2026
Merged

Fix broken from_local usage examples in backend module docstrings.#20
copybara-service[bot] merged 2 commits into
google:mainfrom
vraj130:fix-from-local-docstrings

Conversation

@vraj130

@vraj130 vraj130 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

The usage examples in the module docstrings of gnm_numpy.py, gnm_jax.py,
gnm_pytorch.py, and gnm_tensorflow.py are not runnable as written:

  • They call <module>.from_local(...), but no module-level from_local
    exists — it is a classmethod on the GNM class. Running the snippet raises
    AttributeError: module 'gnm.shape.gnm_numpy' has no attribute 'from_local'.
  • They pass version=GNMVersion.V3, but V3 is not a member of GNMVersion
    (that enum has V3_0), and GNM.from_local is annotated to take
    GNMMajorVersion.

This PR updates all four examples to
<module>.GNM.from_local(version=<module>.GNMMajorVersion.V3, variant=<module>.GNMVariant.HEAD)
so they are copy-paste runnable.

It also fixes the remaining errors in the gnm_jax.py example:
np.random.uniform takes size=, not shape=; np.Array does not exist and
jax.grad's argnums expects ints, so it now uses argnums=(0, 1, 2, 3).
Plus a stray space in the gnm_numpy.py docstring title.

Verification: ran the corrected gnm_numpy example verbatim against the
bundled V3 head model, it constructs the model and returns a (17821, 3)
vertex array, where the previous snippet raised AttributeError. Docstring-only
change; no behavior affected, all lines within 80 columns.

The usage examples in gnm_numpy.py, gnm_jax.py, gnm_pytorch.py and
gnm_tensorflow.py call <module>.from_local(...), which does not exist
(from_local is a classmethod on GNM), and reference GNMVersion.V3,
which is not a member of GNMVersion (from_local takes
GNMMajorVersion). Update all four examples to
<module>.GNM.from_local(version=<module>.GNMMajorVersion.V3, ...) so
they are copy-paste runnable.

Also fix the remaining errors in the gnm_jax.py example
(np.random.uniform takes size=, not shape=, and jax.grad argnums
expects a sequence of ints; np.Array does not exist) and a stray
space in the gnm_numpy.py docstring title.

Verified by running the corrected gnm_numpy example against the
bundled V3 head model: it now constructs the model and returns a
(17821, 3) vertex array, where it previously raised AttributeError.

@bednarikjan bednarikjan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the fixes!

@bednarikjan bednarikjan added the ready to pull A tag used to indicate that the PR is ready to be pulled for review into the internal codebase. label Jul 16, 2026
@vraj130

vraj130 commented Jul 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review! I have two more small fixes open whenever you get a chance-

No rush, and happy to adjust anything!

@copybara-service
copybara-service Bot merged commit fd9f19f into google:main Jul 20, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to pull A tag used to indicate that the PR is ready to be pulled for review into the internal codebase.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants