VaeImageProcessor.denormalize() raises AttributeError for NumPy inputs
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 78/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
Đọc src/diffusers/image_processor.py tại VaeImageProcessor.denormalize() và kiểm tra các kiểu đầu vào được ghi trong tài liệu. Tái hiện lỗi bằng ví dụ NumPy trong issue, sau đó xem các bài kiểm thử gần đó của bộ xử lý ảnh để kiểm tra phạm vi bao phủ cho đầu vào NumPy và PyTorch. Công việc hoàn tất khi đầu vào NumPy trả về các giá trị được giới hạn trong [0, 1] và giữ nguyên kiểu của nó, đồng thời hành vi PyTorch hiện có vẫn hoạt động.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 34.7k
- Fork
- 7.4k
- Merge trung bình
- 2 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 55
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của 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`)Có thể đã có người làm @Subodh-17 đã nhận 11 ngày trước. Đang mởbug models
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
huggingface/diffusers#14952 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
UniPCMultistepScheduler fails in torch.linalg.solve under a float64 default dtype: the unit entry of rks takes the default dtypeCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
huggingface/diffusers#14888 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
WanAnimatePipeline.get_i2v_mask() defaults device to "cuda", which raises on non-CUDA accelerators (NPU/XPU/MPS)Có thể đã có người làm @li-lizhe đã nhận 20 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
huggingface/diffusers#14881 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
IndexError when preprocessing an empty image or video listCó thể đã có người làm @MohammadHijjawi97 đã nhận 25 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
huggingface/diffusers#14864 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Windows: check_ai.py fails decoding UTF-8 guides with the default localeCó thể đã có người làm @tanvir-ux đã nhận 25 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
huggingface/diffusers#14837 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của huggingface/diffusers
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
[Bug] to_ical lexicographical/default sorting moves URL property between two X-WR- propertiesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
collective/icalendar#1968 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Deferred from #1869: Complete the companion pytest guardrail update noted in the PR description...Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Custom provider API keys collide on one host: env slot keyed on host:port only, not URL pathĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
NousResearch/hermes-agent#140958 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bug triage/confirmed
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 85/100
agentscope-ai/agentscope#3355 ·
Maintainer thường phản hồi trong vòng 2 ngày