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

How to optimize two models in a class? #6943

Open
KasenYoung opened this issue Jan 11, 2025 · 1 comment
Open

How to optimize two models in a class? #6943

KasenYoung opened this issue Jan 11, 2025 · 1 comment
Assignees

Comments

@KasenYoung
Copy link

Thanks a lot for your great work. Now I have a class Model which has two little models.

class Model(nn.Module):
       def __init__(self):
             super().__init__()
             self.model1 = xxx
             self.model2 = xxx

When using accelerate package and deepspeed, it only supports one optimizer. So I have to place the parameters of the two models into one optimizer:

optimizer = optimizer(
      params_to_optimize=[model1.parameters(), model2.parameters()],
      ...,
)

My question is : when I optimize just one model, what should I do? For example, I want to optimize model1, what should I do to prevent model2 to be optimized? Thank you very much for your help.

@hwchen2017
Copy link
Contributor

Hi @KasenYoung , you can only pass the parameters of model1 to the optimizer like

optimizer = optimizer(
      params_to_optimize=[Model.model1.parameters()],
      ...,
)

@hwchen2017 hwchen2017 self-assigned this Jan 13, 2025
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

No branches or pull requests

2 participants