huggingface / huggingface/diffusers
StableDiffusion3Pipeline crashes with AttributeError: 'NoneType' object has no attribute 'ndim' when using num_images_per_prompt with batched prompts
- Lenguaje dominante
- Python
- Estrellas
- 34.5k
- Forks
- 7.3k
- Merge medio
- 3 d 3 h
- PR fusionados (30 d)
- 91
Descripción
### 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
Guía de contribución
Línea de trabajo
Comienza en diffusers/pipelines/stable_diffusion_3/pipeline_stable_diffusion_3.py, alrededor de __call__ y la llamada al transformer en la línea 1064, y luego sigue las entradas a través de models/transformers/transformer_sd3.py y attention_processor.py. Reproduce el problema con prompts agrupados en un batch y num_images_per_prompt=1; se considera terminado cuando la llamada deja de pasar encoder_hidden_states=None o informa de un error de validación claro para la combinación no compatible.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python, pytorch
- Área
- machine-learning
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 48/100