VaeImageProcessor.denormalize() raises AttributeError for NumPy inputs
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 78/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
阅读 src/diffusers/image_processor.py 中的 VaeImageProcessor.denormalize(),并检查文档中说明的输入类型。使用 issue 中的 NumPy 示例复现该故障,然后检查附近的图像处理器测试,确认是否覆盖 NumPy 和 PyTorch 输入。完成标准是:NumPy 输入返回裁剪到 [0, 1] 范围内的值,并保留其类型,同时现有的 PyTorch 行为仍能正常工作。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Python
- 星标
- 34.7k
- 派生
- 7.4k
- 平均合并
- 2 天 16 小时
- 30 天内合并 PR
- 55
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
huggingface/diffusers 的其他 Issue
-
`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`)可能已有人在做 @Subodh-17 于 12 天前认领。 未关闭bug models
难度 2/5 1-3 小时 新手友好度 70/100
huggingface/diffusers#14952 · 1 条评论 ·
维护者通常 1 天内回复
-
UniPCMultistepScheduler fails in torch.linalg.solve under a float64 default dtype: the unit entry of rks takes the default dtype可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
huggingface/diffusers#14888 ·
维护者通常 1 天内回复
-
WanAnimatePipeline.get_i2v_mask() defaults device to "cuda", which raises on non-CUDA accelerators (NPU/XPU/MPS)可能已有人在做 @li-lizhe 于 21 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
huggingface/diffusers#14881 ·
维护者通常 1 天内回复
-
IndexError when preprocessing an empty image or video list可能已有人在做 @MohammadHijjawi97 于 26 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
huggingface/diffusers#14864 ·
维护者通常 1 天内回复
-
Windows: check_ai.py fails decoding UTF-8 guides with the default locale可能已有人在做 @tanvir-ux 于 26 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 84/100
huggingface/diffusers#14837 ·
维护者通常 1 天内回复
查看 huggingface/diffusers 的全部 Issue
相似的 Issue
-
comp/cli P3 type/security
难度 2/5 1-3 小时 新手友好度 68/100
NousResearch/hermes-agent#141420 · 1 条评论 ·
维护者通常 1 天内回复
-
vendor-pitch
难度 2/5 1-3 小时 新手友好度 87/100
维护者通常 1 天内回复
-
bug llm p2
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
New tool: ZIPZAX Python Notebook Studio可能已有人在做 @github-actions 今天认领。 未关闭submission triage
难度 1/5 1 小时以内 新手友好度 68/100
kausalflow/tools#226 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100