VaeImageProcessor.denormalize() raises AttributeError for NumPy inputs

Open Beginner friendly
#15,011 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@tonycoder-hub is already working on this.

Since Oct 12, 2026.

  • #15012 by @tonycoder-hub — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
numpy, python, pytorch

Research direction

Read src/diffusers/image_processor.py at VaeImageProcessor.denormalize() and check its documented input types. Reproduce the failure with the NumPy example in the issue, then inspect nearby image processor tests for coverage of NumPy and PyTorch inputs. Done means NumPy input returns clipped values in [0, 1] with its type preserved, while existing PyTorch behavior still works.

Written by the indexing model from the issue text.

Description

bug
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.

Dominant language
Python
Stars
34.8k
Forks
7.4k
Avg merge
2d 13h
Merged PRs (30d)
58

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from huggingface/diffusers

All issues in huggingface/diffusers

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.