Skip to content

Route SanaTransformer2DModel.forward by time-embed type, not by guidance presence#13741

Open
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix-sana-guidance-embeds
Open

Route SanaTransformer2DModel.forward by time-embed type, not by guidance presence#13741
Ricardo-M-L wants to merge 1 commit into
huggingface:mainfrom
Ricardo-M-L:fix-sana-guidance-embeds

Conversation

@Ricardo-M-L
Copy link
Copy Markdown
Contributor

Why

Fixes #12540.

When `SanaTransformer2DModel` is built with `guidance_embeds=True`, the forward pass routed on `guidance is not None`. Pipelines that do not thread guidance through (`SanaPipeline`, `SanaPAGPipeline`) therefore fell into the `batch_size` branch and crashed with:

```
TypeError: SanaCombinedTimestepGuidanceEmbeddings.forward() got an
unexpected keyword argument 'batch_size'
```

Fix

Dispatch on `isinstance(self.time_embed, SanaCombinedTimestepGuidanceEmbeddings)` instead — the embedder type is what dictates the call signature. If the model was configured with guidance embeddings but the pipeline omits guidance, raise a clear `ValueError` naming the misconfiguration instead of surfacing a confusing kwargs error from the embedder.

13 LOC, 1 file (`sana_transformer.py`). Unblocks Sana checkpoints that were trained with the guidance-embedding variant when used through the non-guidance pipelines.

…nce presence

When SanaTransformer2DModel was built with guidance_embeds=True, the
forward pass routed on `guidance is not None`. Pipelines that do not
thread guidance through (SanaPipeline, SanaPAGPipeline) therefore fell
into the `batch_size` branch and crashed with
`TypeError: SanaCombinedTimestepGuidanceEmbeddings.forward() got an
unexpected keyword argument 'batch_size'` (see huggingface#12540).

Dispatch on `isinstance(self.time_embed, SanaCombinedTimestepGuidanceEmbeddings)`
instead: the embedder type is what dictates the call signature. If the
model was configured with guidance embeddings but the pipeline omits
guidance, raise a clear ValueError naming the misconfiguration instead
of surfacing a confusing kwargs error from the embedder.

Fixes huggingface#12540
@github-actions github-actions Bot added models size/S PR with diff < 50 LOC fixes-issue labels May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fixes-issue models size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SanaCombinedTimestepGuidanceEmbeddings do not work with SanaPipeline

1 participant