Skip to content

Commit df1788c

Browse files
committed
Let FlaxTimestepEmbedding handle the conditioning dtype
nn.Dense promotes its inputs to its own dtype, so casting the already-projected timestep and guidance to the pooled projection's dtype first only rounds them early: a no-op when activations are bfloat16, and a needless loss of precision when they are float32. CombinedTimestepTextProjEmbeddings already passes its projected timestep through untouched.
1 parent 0c4f9e0 commit df1788c

1 file changed

Lines changed: 2 additions & 3 deletions

File tree

‎src/maxdiffusion/models/embeddings_flax.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -552,16 +552,15 @@ def __call__(self, timestep, guidance, pooled_projection=None):
552552
# (batch, frequency_embedding_size, embedding_dim) and break the sum with the
553553
# pooled projection below. The NNX variant owns its projection instead.
554554
timesteps_proj = timestep
555-
dtype = pooled_projection.dtype if pooled_projection is not None else jnp.float32
556555
timestep_emb = FlaxTimestepEmbedding(
557556
time_embed_dim=self.embedding_dim, dtype=self.dtype, weights_dtype=self.weights_dtype
558-
)(timesteps_proj.astype(dtype))
557+
)(timesteps_proj)
559558

560559
if self.guidance_embeds and guidance is not None:
561560
guidance_proj = guidance
562561
guidance_emb = FlaxTimestepEmbedding(
563562
time_embed_dim=self.embedding_dim, dtype=self.dtype, weights_dtype=self.weights_dtype
564-
)(guidance_proj.astype(dtype))
563+
)(guidance_proj)
565564
time_guidance_emb = timestep_emb + guidance_emb
566565
else:
567566
time_guidance_emb = timestep_emb

0 commit comments

Comments
 (0)