Skip to content

Conversation

@divyashreepathihalli
Copy link
Collaborator

fixes this error in the guide : TypeError: got an unexpected keyword argument 'wrt'

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @divyashreepathihalli, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a TypeError in the nnx guide by updating the nnx.grad function calls to align with the latest API. The change involves replacing the wrt keyword argument with argnums and utilizing nnx.DiffState for specifying differentiable arguments, ensuring the guide's code examples are accurate and executable.

Highlights

  • nnx.grad API Update: The nnx.grad function call in the Keras NNX guide has been updated to use argnums=nnx.DiffState(...) instead of the deprecated wrt keyword argument, resolving a TypeError.
  • Guide Code Correction: The code examples in the keras_nnx_guide.ipynb, keras_nnx_guide.py, and keras_nnx_guide.md files have been corrected to reflect the current nnx API for gradient computation.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a TypeError in the Keras NNX guide caused by a deprecated wrt argument in nnx.grad. The fix correctly updates the API usage to argnums with nnx.DiffState across the notebook, Python script, and markdown files. The changes are correct and resolve the issue. I've added a few suggestions to inline the nnx.DiffState creation for better code conciseness in the guide examples.

Comment on lines +345 to +346
" diff_state = nnx.DiffState(0, trainable_var)\n",
" grads = nnx.grad(loss_fn, argnums=diff_state)(model)\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For conciseness, you can inline the creation of nnx.DiffState directly into the nnx.grad call. This removes the need for a temporary variable and makes the code a single, expressive line.

Suggested change
" diff_state = nnx.DiffState(0, trainable_var)\n",
" grads = nnx.grad(loss_fn, argnums=diff_state)(model)\n",
" grads = nnx.grad(loss_fn, argnums=nnx.DiffState(0, trainable_var))(model)\n",

Comment on lines +211 to +212
diff_state = nnx.DiffState(0, trainable_var)
grads = nnx.grad(loss_fn, argnums=diff_state)(model)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For conciseness, you can inline the creation of nnx.DiffState directly into the nnx.grad call. This removes the need for a temporary variable and makes the code a single, expressive line.

Suggested change
diff_state = nnx.DiffState(0, trainable_var)
grads = nnx.grad(loss_fn, argnums=diff_state)(model)
grads = nnx.grad(loss_fn, argnums=nnx.DiffState(0, trainable_var))(model)

Comment on lines +226 to +227
diff_state = nnx.DiffState(0, trainable_var)
grads = nnx.grad(loss_fn, argnums=diff_state)(model)
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For conciseness, you can inline the creation of nnx.DiffState directly into the nnx.grad call. This removes the need for a temporary variable and makes the code a single, expressive line. This can help keep code examples in the guide clean and focused.

Suggested change
diff_state = nnx.DiffState(0, trainable_var)
grads = nnx.grad(loss_fn, argnums=diff_state)(model)
grads = nnx.grad(loss_fn, argnums=nnx.DiffState(0, trainable_var))(model)

@divyashreepathihalli divyashreepathihalli merged commit d3b2abd into keras-team:master Sep 29, 2025
4 checks passed
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