huggingface / huggingface/diffusers

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

オープン
#14,366 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る
bug models
主要言語
Python
スター
34.5k
フォーク
7.3k
平均マージ
3日 3時間
マージ済み PR(30日)
91

説明

### 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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

評価

技術スタック
numpy, python, pytorch
領域
backend, machine-learning
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
静か
明瞭さ
明確に書かれている
初心者へのやさしさ
72/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。