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

[Feature Request] Make torchopt.optim.Optimizer compatible with pytorch lightning #203

Open
2 tasks done
SamDuffield opened this issue Jan 11, 2024 · 0 comments
Open
2 tasks done
Assignees
Labels
enhancement New feature or request

Comments

@SamDuffield
Copy link

SamDuffield commented Jan 11, 2024

Required prerequisites

Motivation

Currently torchopt.optim classes aren't compatible with lightning's configure_optimizers.

This is because lightning doesn't think they are Optimizable

import torchopt
from lightning.fabric.utilities.types import Optimizable
optimizer = torchopt.Adam(model.parameters(), lr=1e-3)

isinstance(optimizer, Optimizable)
# False

For it to be Optimizable it requires defaults and state attributes.

If simply you do

from collections import defaultdict
optimizer.defaults = {}
optimizer.state = defaultdict()

then isinstance(optimizer, Optimizable) passes and torchopt <> lightning works a charm 😍

Solution

Can we add defaults and state attributes to the torchopt.optim.Optimizer class?

Alternatives

No response

Additional context

No response

@SamDuffield SamDuffield added the enhancement New feature or request label Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants