huggingface / huggingface/diffusers

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

Đang mở
#14,366 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug models
Ngôn ngữ chính
Python
Star
34.5k
Fork
7.3k
Merge trung bình
3 ngày 3 giờ
Pull request đã merge (30 ngày)
91

Mô tả

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

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
numpy, python, pytorch
Lĩnh vực
backend, machine-learning
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
72/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.