You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classModel(nn.Module):
def__init__(self):
self.model_1=Model_1() # need to be frozenself.model_2=Model_2() # need gradient checkpointingdefforward(batch):
x=self.model_1(batch)
x=self.model_2(x)
returnx
I want to train the model with DDP. But the tricky thing is that the model's first part needs to be frozen and has no gradient, so I should use DDP with find_unused_parameters=True. While the second part uses gradient checkpointing, so I need to use DDP with find_unused_parameters=False.
However, since the model is further wrapped in a pl.LightningModule, usually I can only set one strategy and pass it to the pl.Trainer. I wonder is there a way to adapt my code so that I could use different strategies for different parts of the model, and train them together?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a model with the following architecture.
I want to train the model with DDP. But the tricky thing is that the model's first part needs to be frozen and has no gradient, so I should use DDP with
find_unused_parameters=True
. While the second part uses gradient checkpointing, so I need to use DDP withfind_unused_parameters=False
.Luckily, as is discussed in this post (Finding the cause of RuntimeError: Expected to mark a variable ready only once), I could use different DDP strategy for these two parts of the model to let each part work as expected.
However, since the model is further wrapped in a
pl.LightningModule
, usually I can only set one strategy and pass it to thepl.Trainer
. I wonder is there a way to adapt my code so that I could use different strategies for different parts of the model, and train them together?Beta Was this translation helpful? Give feedback.
All reactions