Skip to content

VaeImageProcessor.denormalize() raises AttributeError for NumPy inputs #15011

Open

Description

@SrijanRoy123-github

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.

Activity

  1. SrijanRoy123-github commented on Oct 12, 2026

    @SrijanRoy123-github
    Author

    Basically, VaeImageProcessor.denormalize() supports both NumPy arrays and PyTorch tensors according to its documentation, but internally uses .clamp(), which is only available for PyTorch tensors. As a result, NumPy inputs raise an AttributeError. I've reproduced this locally and verified the expected output against PyTorch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions