@@ -168,17 +168,7 @@ def __init__(self, model_dim, time_dim, max_period=10000.0):
168168 def forward (self , time ):
169169 args = torch .outer (time .to (torch .float32 ), self .freqs .to (device = time .device ))
170170 time_embed = torch .cat ([torch .cos (args ), torch .sin (args )], dim = - 1 )
171- time_embed = F .linear (
172- self .activation (
173- F .linear (
174- time_embed ,
175- self .in_layer .weight .to (torch .float32 ),
176- self .in_layer .bias .to (torch .float32 ),
177- )
178- ),
179- self .out_layer .weight .to (torch .float32 ),
180- self .out_layer .bias .to (torch .float32 ),
181- )
171+ time_embed = self .out_layer (self .activation (self .in_layer (time_embed )))
182172 return time_embed
183173
184174
@@ -279,11 +269,7 @@ def __init__(self, time_dim, model_dim, num_params):
279269 self .out_layer .bias .data .zero_ ()
280270
281271 def forward (self , x ):
282- return F .linear (
283- self .activation (x .to (torch .float32 )),
284- self .out_layer .weight .to (torch .float32 ),
285- self .out_layer .bias .to (torch .float32 ),
286- )
272+ return self .out_layer (self .activation (x ))
287273
288274
289275class Kandinsky5AttnProcessor :
@@ -537,6 +523,7 @@ class Kandinsky5Transformer3DModel(
537523 "Kandinsky5TransformerEncoderBlock" ,
538524 "Kandinsky5TransformerDecoderBlock" ,
539525 ]
526+ _keep_in_fp32_modules = ["time_embeddings" , "modulation" , "visual_modulation" , "text_modulation" ]
540527 _supports_gradient_checkpointing = True
541528
542529 @register_to_config
0 commit comments