Repository navigation
Forward the inputs DSUNet._forward accepts to the UNet - #8408
vineethsaivs wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5a030136ea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| encoder_hidden_states, | ||
| timestep_cond=timestep_cond, | ||
| cross_attention_kwargs=cross_attention_kwargs, | ||
| added_cond_kwargs=added_cond_kwargs, |
There was a problem hiding this comment.
Refresh nested added conditioning before graph replay
With enable_cuda_graph=True (the default), SDXL passes added_cond_kwargs as a dictionary containing tensors such as text_embeds and time_ids. _graph_replay only copies top-level tensor kwargs, so the captured dictionary from the first invocation is never refreshed; a later pipeline call with a different prompt replays using the first call's added conditioning and produces silently incorrect images. Flatten or explicitly copy the dictionary's tensor values into static buffers before replay; the new test disables CUDA graphs and therefore does not cover this path.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Real, and split out into #8488.
You are right that forwarding added_cond_kwargs is what makes the staleness reachable: before this PR it was dropped entirely, so there was nothing to go stale. _graph_replay matches on torch.is_tensor, so a dict of tensors is skipped and the capture-time conditioning is replayed for every later prompt.
It is not specific to this file. The same six lines sit in DSVAE (three times), DSClipEncoder and InferenceEngine, all with the same gap. #8488 adds one refresh_static_tensors() helper next to CUDAGraph and uses it at all six sites, with a CPU test that fails on master.
Keeping it out of this PR so this one stays about the argument list.
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
CUDA graph replay does not refresh tensors nested within added_cond_kwargs, causing stale conditioning on later calls.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Fixes DSUNet argument forwarding to the wrapped Diffusers UNet.
Changes:
- Forwards optional inputs by keyword.
- Adds a regression test for argument forwarding.
| File | Description |
|---|---|
deepspeed/model_implementations/diffusers/unet.py |
Corrects wrapped UNet invocation. |
tests/unit/inference/test_stable_diffusion.py |
Tests forwarded argument values. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| encoder_hidden_states, | ||
| timestep_cond=timestep_cond, | ||
| cross_attention_kwargs=cross_attention_kwargs, | ||
| added_cond_kwargs=added_cond_kwargs, |
There was a problem hiding this comment.
Handled in #8488, which refreshes tensors nested in containers at every replay site. It builds on this PR, so the two should land together.
|
Friendly bump: still relevant, and it merges cleanly with the base branch. Happy to adjust anything. |
|
Friendly ping: this is still relevant and merges cleanly with main. Happy to rebase or change anything. |
DSUNet._forward takes timestep_cond and added_cond_kwargs and passes neither on, and it hands return_dict to the UNet positionally, where UNet2DConditionModel.forward reads class_labels. So a caller asking for return_dict=False gets class_labels=True and the UNet's own default instead, SDXL's added_cond_kwargs never arrives, and a guidance-distilled model's timestep_cond is dropped. Pass everything after encoder_hidden_states by keyword. The cross_attention branch goes away with it: cross_attention_kwargs=None is what omitting it already meant. Signed-off-by: Vineeth Sai <vineethsai4444@gmail.com>
5a03013 to
5a0fb26
Compare

What is wrong
DSUNet._forwardacceptstimestep_condandadded_cond_kwargsand forwards neither, and it passesreturn_dictpositionally:UNet2DConditionModel.forward's fourth positional parameter isclass_labels, notreturn_dict:Driving the wrapper with a stub that mirrors that signature, with
enable_cuda_graph=Falseso no accelerator is needed:return_dict=Falseclass_labels=False,return_dict=Trueclass_labels=None,return_dict=Falsetimestep_cond=<tensor>Noneadded_cond_kwargs={...}NoneSDXL's UNet requires
added_cond_kwargs(addition_embed_type == "text_time"), andtimestep_condis what a guidance-distilled model reads, so both are dropped exactly where they matter.What changed
Pass everything after
encoder_hidden_statesby keyword. Theif cross_attention_kwargs:branch goes with it:cross_attention_kwargs=Noneis what omitting the argument already meant, and both of its arms carried the same positional mistake.Test
test_ds_unet_forwards_the_inputs_it_acceptsintests/unit/inference/test_stable_diffusion.py, a plain function alongside the existingTestStableDiffusionclass. It drivesDSUNetwith a recording stub, needs no accelerator and downloads no model.yapf --style .style.yapf --diffis clean on both files.