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

Improve error message for when nnx.Modules use jax or numpy arrays as leaf values #4492

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
10 changes: 8 additions & 2 deletions flax/nnx/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,10 +588,16 @@ def _graph_flatten(
if path is not None:
path_str = '/'.join(map(str, path))
raise ValueError(
f'Arrays leaves are not supported, at {path_str!r}: {value}'
f'The variable at the path {path_str!r} with value = {value} is of type:' \
f'{type(value)}. Leaf values of this type are not supported for nnx.Modules'\
f' or nnx.Object in general.'
)
else:
raise ValueError(f'Arrays leaves are not supported, found {value}')
raise ValueError(
f'The variable with path "None" and with value = {value} is of type:' \
f'{type(value)}. Leaf values of this type are not supported for nnx.Modules'\
f' or nnx.Object in general.'
)
# static_fields.append((key, value))
attributes.append((key, Static(value)))

Expand Down
Loading