VaeImageProcessor.denormalize() raises AttributeError for NumPy inputs
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 78/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- machine-learning
Línea de trabajo
Lee src/diffusers/image_processor.py en VaeImageProcessor.denormalize() y comprueba los tipos de entrada documentados. Reproduce el fallo con el ejemplo de NumPy del issue y, después, revisa las pruebas cercanas del procesador de imágenes para comprobar la cobertura de entradas de NumPy y PyTorch. El trabajo estará terminado cuando una entrada de NumPy devuelva valores recortados en [0, 1] y conserve su tipo, mientras que el comportamiento existente de PyTorch siga funcionando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the bug
VaeImageProcessor.denormalize() is documented to accept both NumPy arrays (np.ndarray) and PyTorch tensors (torch.Tensor). However, passing a NumPy array raises an AttributeError because the implementation uses the PyTorch-specific .clamp() method.
Root cause
In src/diffusers/image_processor.py, line 234:
return (images * 0.5 + 0.5).clamp(0, 1)
NumPy arrays do not implement .clamp(), despite being included in the function's type annotations and documentation.
Expected behavior
The function should denormalize NumPy inputs to [0, 1], preserving the input type and existing PyTorch behavior.
Proposed direction
Use input-type-appropriate clipping, such as np.clip() for NumPy and .clamp() for PyTorch, or clarify the supported types if NumPy support is not intended.
I'd be happy to contribute a fix after discussing the preferred approach with maintainers.
Reproduction
import numpy as np
import torch
from diffusers.image_processor import VaeImageProcessor
values = [-2.0, -1.0, 0.0, 1.0, 2.0]
numpy_input = np.array(values, dtype=np.float32)
torch_input = torch.tensor(values, dtype=torch.float32)
# PyTorch succeeds
print("PyTorch:", VaeImageProcessor.denormalize(torch_input))
# NumPy raises AttributeError
print("NumPy:", VaeImageProcessor.denormalize(numpy_input))
The issue is reproducible on CPU without pretrained models or external downloads.
Logs
File "E:\diffusers\src\diffusers\image_processor.py", line 234, in denormalize
return (images * 0.5 + 0.5).clamp(0, 1)
AttributeError: 'numpy.ndarray' object has no attribute 'clamp'. Did you mean: 'clip'?
Additional validation:
PyTorch actual: [0.0, 0.0, 0.5, 1.0, 1.0]
NumPy expected: [0.0, 0.0, 0.5, 1.0, 1.0]
Outputs match: True
System Info
- 🤗 Diffusers version: 0.41.0.dev0
- Platform: Windows-10-10.0.22631-SP0
- Running on Google Colab?: No
- Python version: 3.11.16
- PyTorch version (GPU?): 2.14.1+cpu (False)
- NumPy version: 2.4.6
- Huggingface_hub version: 1.33.0
- Transformers version: 5.18.0
- Accelerate version: 1.15.0
- PEFT version: 0.21.2
- Safetensors version: 0.8.0
Source revision: 899c9f3fd0e64f3206781c00c71c28249eff9ca5
Reproduction environment: Windows, CPU only. No pretrained models or external downloads required.
Who can help?
@DN6 @sayakpaul
I'd appreciate your feedback on the expected NumPy support and the preferred approach to resolving this issue. I'm happy to contribute a fix once the implementation approach is agreed upon.
- Lenguaje dominante
- Python
- Estrellas
- 34.7k
- Forks
- 7.4k
- Merge medio
- 2 d 10 h
- PR fusionados (30 d)
- 55
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de huggingface/diffusers
-
`ModelMixin.from_pretrained` on a sharded checkpoint fails under `HF_HUB_OFFLINE=1` even when fully cached (`_get_checkpoint_shard_files` still calls `model_info`)Posiblemente ocupada @Subodh-17 la tomó hace 13 días. Abiertobug models
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
huggingface/diffusers#14952 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
UniPCMultistepScheduler fails in torch.linalg.solve under a float64 default dtype: the unit entry of rks takes the default dtypePosiblemente ocupada @deep1blue la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
huggingface/diffusers#14888 ·
Los mantenedores suelen responder en 1 día
-
WanAnimatePipeline.get_i2v_mask() defaults device to "cuda", which raises on non-CUDA accelerators (NPU/XPU/MPS)Posiblemente ocupada @li-lizhe la tomó hace 22 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
huggingface/diffusers#14881 ·
Los mantenedores suelen responder en 1 día
-
IndexError when preprocessing an empty image or video listPosiblemente ocupada @MohammadHijjawi97 la tomó hace 27 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
huggingface/diffusers#14864 ·
Los mantenedores suelen responder en 1 día
-
Windows: check_ai.py fails decoding UTF-8 guides with the default localePosiblemente ocupada @tanvir-ux la tomó hace 26 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
huggingface/diffusers#14837 ·
Los mantenedores suelen responder en 1 día
Todos los issues de huggingface/diffusers
Issues similares
-
`image_generation`: `max_retries` is ignored for OpenAI-compatible providers (always 2 retries)Posiblemente ocupada @ericz7900 la tomó hoy. Abiertollm translation
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
rheeloaded/paperpull#117 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
agenda-tech-brasil/agenda-tech-brasil#1619 · 1 comentario ·
-
process
Dificultad 1/5 1-3 horas Aptitud para principiantes 76/100
pyrite-wiki/pyrite#1036 ·
Los mantenedores suelen responder en 1 día