huggingface / huggingface/diffusers

Public `embeddings.py` helpers raise `ValueError` with default arguments

Open
#14,366 3 comments 0 reactions 0 assignees View on GitHub
bug models
Dominant language
Python
Stars
34.5k
Forks
7.3k
Avg merge
3d 3h
Merged PRs (30d)
91

Description

### Describe the bug

Four public helpers in `src/diffusers/models/embeddings.py` raise `ValueError` when called with their default arguments, on `main` (0.40.0.dev0).

All four default to `output_type="np"`, and that branch calls `deprecate(..., "0.33.0"/"0.34.0", ...)`. Since `deprecate()` raises once `__version__` is at or past the target (`utils/deprecation_utils.py`), and the current version is 0.40, the default path raises before doing anything.

### Reproduction

```python
import numpy as np
from diffusers.models import embeddings as E

E.get_2d_sincos_pos_embed(embed_dim=8, grid_size=2)
E.get_2d_sincos_pos_embed_from_grid(8, np.zeros((2, 4)))
E.get_1d_sincos_pos_embed_from_grid(8, np.arange(4))
E.get_2d_rotary_pos_embed(8, (2, 2), (0, 0, 2, 2))
```

Each raises:

```
ValueError: The deprecation tuple ("output_type=='np'", '0.33.0', ...) should be removed
since diffusers' version 0.40.0.dev0 is >= 0.33.0
```

### Expected behavior

Three things look off rather than one:

1. The **default** value routes into the raising branch, so no-argument calls fail.
2. The error text is an internal maintenance message addressed to maintainers, not to the caller.
3. The intended guidance is never reached — `deprecate()` raises before it warns, so `"Pass output_type='pt' to use the new version now."` is never shown, and the `return get_*_np(...)` fallback immediately after each call is unreachable.

`get_1d_sincos_pos_embed_from_grid` documents the default explicitly: `output_type ("str", *optional*, defaults to "np")`. The other three accept `output_type` but do not document it at all.

### Scope

**Library internals are not affected.** All eight in-tree call sites pass `output_type="pt"` (or a variable) explicitly — `hunyuandit`, `pag_hunyuandit`, `controlnet_hunyuandit`, `transformer_omnigen`, `latte_transformer_3d`, `transformer_skyreels_v2`, `autoencoder_rae`, `deprecated/unidiffuser`. This affects external callers using these public helpers directly.

Not tested: whether any downstream project relies on the `"np"` return path.

Related to #14365, which inventories 20 `deprecate()` call sites past their target version. Splitting this out per the discussion there — @Dev-X25874 is keeping that PR scoped to `vq_model.py`.

### System Info

- diffusers version: 0.40.0.dev0 (`main`, commit `a8345366e`)
- Platform: macOS (Darwin 25.0.0), CPU only
- Python version: 3.11
- PyTorch version: 2.13.0

### Who can help?

@hlky (`git blame` shows the deprecation blocks are yours, so you would know whether the `"np"` path was meant to be removed at 0.33/0.34) and @yiyixuxu

Contributor guide

Open the contributing guide

Research direction

Start in src/diffusers/models/embeddings.py by reading the four public helpers and their output_type deprecation blocks, then inspect deprecate() in utils/deprecation_utils.py. Check the listed in-tree callers and existing embedding tests, if present. Done means default calls no longer raise unexpectedly, the intended public behavior is explicit, and regression coverage verifies the affected helpers.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python, pytorch
Domain
backend, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.