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

Add flax.nnx.value_and_grad docstring #4372

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

8bitmp3
Copy link
Collaborator

@8bitmp3 8bitmp3 commented Nov 11, 2024

@8bitmp3 8bitmp3 force-pushed the add-nnx-value_and_grad-docstring branch from 60abeb4 to c4264ee Compare November 13, 2024 22:42
@cgarciae
Copy link
Collaborator

@8bitmp3 some tests are failing.

@8bitmp3
Copy link
Collaborator Author

8bitmp3 commented Nov 15, 2024

@8bitmp3 some tests are failing.

Found it. ... was missing:

>>> value_and_grad_fn = nnx.value_and_grad(loss_fn)
...
>>> values, grads = value_and_grad_fn(m, x, y)

@8bitmp3 8bitmp3 force-pushed the add-nnx-value_and_grad-docstring branch from c4264ee to 26499a7 Compare November 15, 2024 16:09
@cgarciae
Copy link
Collaborator

@8bitmp3 CI is still failing

@8bitmp3
Copy link
Collaborator Author

8bitmp3 commented Nov 15, 2024

The error:

367     >>> values, grads = value_and_grad_fn(m, x, y)
368     >>> print(jax.tree.map(jnp.shape, grads))
Expected nothing
Got:
    State({
      'bias': VariableState(
        type=Param,
        value=(3,)
      ),
      'kernel': VariableState(
        type=Param,
        value=(2, 3)
      )
    })

I could try without print() @cgarciae

@cgarciae
Copy link
Collaborator

@8bitmp3 copy the output you see there and paste it on the example e.g:

>>> print(jax.tree.map(jnp.shape, grads))
State({
  'bias': VariableState(
    type=Param,
    value=(3,)
  ),
  'kernel': VariableState(
    type=Param,
    value=(2, 3)
  )
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants