Add support for recursing Chains in ReactantCompatibleOptimisers#1622
Add support for recursing Chains in ReactantCompatibleOptimisers#1622ispielma wants to merge 3 commits intoLuxDL:mainfrom
Conversation
Summary of ChangesHello @ispielma, 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 an issue where Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request correctly addresses a bug where Optimisers.adjust would not recurse through an OptimiserChain wrapped in a ReactantOptimiser. The added methods for Optimisers.adjust now handle this case by iterating through the optimizers in the chain and applying the adjustment recursively. However, there is a small typo in one of the new function signatures that will cause a syntax error and needs to be fixed.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request correctly adds support for recursing through OptimiserChain for ReactantCompatibleOptimisers by implementing Optimisers.adjust, addressing the described bug. I've suggested a refactoring to combine the two new adjust methods into a single, more generic function to reduce code duplication and improve maintainability, which also offers a minor performance improvement.
| function Optimisers.adjust( | ||
| chain::ReactantOptimiser{<:Optimisers.OptimiserChain}, | ||
| eta::Real | ||
| ) | ||
| results = Optimisers.OptimiserChain([Optimisers.adjust(opt, eta) for opt in chain.opt.opts]...) | ||
| return ReactantOptimiser(results) | ||
| end | ||
| function Optimisers.adjust( | ||
| chain::ReactantOptimiser{<:Optimisers.OptimiserChain}; | ||
| kw... | ||
| ) |
There was a problem hiding this comment.
will overloading _adjust work instead?
There was a problem hiding this comment.
It could be done that way, but there would be more duplicated code since the implementation would end up replicating the recursion code already present in Optimisers.adjust.
The existing patches for Optimizers.jl directed ReactantOptimiser to Optimisers._adjust. This is a bug for Optimisers.OptimiserChain because Optimisers.adjust recurses through chains but Optimisers._adjust does not.
This pull request fixes this issue by adding ReactantOptimiser{<:Optimisers.OptimiserChain} methods to Optimisers.adjust.