huggingface / huggingface/diffusers

StableDiffusion3Pipeline crashes with AttributeError: 'NoneType' object has no attribute 'ndim' when using num_images_per_prompt with batched prompts

オープン
#12,895 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
stale
主要言語
Python
スター
34.5k
フォーク
7.3k
平均マージ
3日 3時間
マージ済み PR(30日)
91

説明

### Describe the bug

When using **StableDiffusion3Pipeline** with **batched prompts** (`prompt` as a list) and passing the parameter `num_images_per_prompt` (even when set to `1`), the pipeline crashes with:

```
AttributeError: 'NoneType' object has no attribute 'ndim'
```

This error does **not** occur:

* when `num_images_per_prompt` is omitted
* when using other pipelines (SDXL, SD1.x, FLUX, etc.)
* when running single-prompt (non-batch) inference

This appears to be specific to **Stable Diffusion 3** and its internal prompt/embedding handling.

### Environment

* **diffusers**: 0.36.0
* **torch**: 2.8
* **python**: 3.12
* **device**: CUDA
* **OS**: Linux
* **Pipeline**: `StableDiffusion3Pipeline`
* **Not using**: `prompt_embeds`, custom embeddings, or LoRAs

### Steps to reproduce

Minimal reproduction pattern:

```python
from diffusers import StableDiffusion3Pipeline
import torch

pipe = StableDiffusion3Pipeline.from_pretrained(
"stabilityai/stable-diffusion-3-medium",
torch_dtype=torch.float16
).to("cuda")

prompts = [
"A photo of a cat",
"A photo of a dog",
]

images = pipe(
prompt=prompts, # batched prompts
height=1024,
width=1024,
num_inference_steps=30,
num_images_per_prompt=1, # <- causes crash
).images
```

Removing `num_images_per_prompt` makes the same code run successfully.

### Full traceback

```
0%| | 0/30 [00:00
ERROR: Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/aquilesimage/runtime/batch_inf.py", line 294, in batch_infer
return self.pipeline.generate_batch(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/aquilesimage/runtime/requestscopedpipeline.py", line 789, in generate_batch
result = local_pipe(
^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/torch/utils/_contextlib.py", line 120, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py", line 1064, in __call__
noise_pred = self.transformer(
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1773, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1784, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/diffusers/models/transformers/transformer_sd3.py", line 327, in forward
encoder_hidden_states, hidden_states = block(
^^^^^^
File "/usr/local/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1773, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1784, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/diffusers/models/attention.py", line 715, in forward
attn_output2 = self.attn2(hidden_states=norm_hidden_states2, **joint_attention_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1773, in _wrapped_call_impl
return self._call_impl(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1784, in _call_impl
return forward_call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/diffusers/models/attention_processor.py", line 605, in forward
return self.processor(
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/diffusers/models/attention_processor.py", line 1849, in __call__
context_input_ndim = encoder_hidden_states.ndim
^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'ndim'

ERROR: {'height': 1024, 'width': 1024, 'num_inference_steps': 30, 'device': 'cuda', 'num_images_per_prompt': 1}
```

### Expected behavior

* `num_images_per_prompt` should work with batched prompts, or
* the pipeline should raise a clear validation error if this combination is unsupported

At minimum, the pipeline should not pass `encoder_hidden_states=None` into the attention processor.

### Additional notes

* This issue only reproduces with **StableDiffusion3Pipeline**
* Other pipelines handle the same parameters correctly
* As a workaround, expanding prompts manually and **not passing `num_images_per_prompt`** avoids the crash

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py の __call__ 周辺と 1064 行目の transformer 呼び出しから始め、models/transformers/transformer_sd3.py と attention_processor.py を通じて入力を追跡します。バッチ化したプロンプトと num_images_per_prompt=1 で再現します。呼び出しで encoder_hidden_states=None が渡されなくなるか、サポートされていない組み合わせに対して明確な検証エラーが報告されれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python, pytorch
領域
machine-learning
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
明確に書かれている
初心者へのやさしさ
48/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。