Allow individual models to scale the loss after it is calculated.
This commit is contained in:
parent
f743ccf7ef
commit
d14f6e567a
|
|
@ -827,6 +827,9 @@ class SDTrainer(BaseSDTrainProcess):
|
|||
loss = torch.nn.functional.mse_loss(pred.float(), target.float(), reduction="none")
|
||||
|
||||
loss = loss * local_loss_scale
|
||||
|
||||
# apply model specific loss scaling
|
||||
loss = self.sd.scale_loss(loss)
|
||||
|
||||
do_weighted_timesteps = False
|
||||
if self.sd.is_flow_matching:
|
||||
|
|
|
|||
|
|
@ -1602,3 +1602,7 @@ class BaseModel:
|
|||
def get_model_to_train(self):
|
||||
# called to get model to attach LoRAs to. Can be overridden in child classes
|
||||
return self.unet
|
||||
|
||||
def scale_loss(self, loss):
|
||||
# called to get the loss scaler for the model. Can be overridden in child classes
|
||||
return loss
|
||||
|
|
|
|||
|
|
@ -3161,3 +3161,7 @@ class StableDiffusion:
|
|||
|
||||
def get_model_to_train(self):
|
||||
return self.unet
|
||||
|
||||
def scale_loss(self, loss):
|
||||
# called to get the loss scaler for the model. Can be overridden in child classes
|
||||
return loss
|
||||
|
|
|
|||
Loading…
Reference in New Issue