Skip to content

fix(embeddings): change default output_type from np to pt in positional embedding helpers - #14372

Open
AloysJehwin wants to merge 1 commit into
huggingface:mainfrom
AloysJehwin:fix/embeddings-default-output-type
Open

fix(embeddings): change default output_type from np to pt in positional embedding helpers#14372
AloysJehwin wants to merge 1 commit into
huggingface:mainfrom
AloysJehwin:fix/embeddings-default-output-type

Conversation

@AloysJehwin

Copy link
Copy Markdown

What does this PR do?

Fixes #14366

Four public helpers in embeddings.py defaulted to output_type='np', which routes into a deprecate() call with target 0.33.0/0.34.0. Since the current version is 0.40.0, deprecate() raises a ValueError before doing anything — so calling these functions with no arguments crashes.

Changed the default to output_type='pt' in:

  • get_3d_sincos_pos_embed
  • get_2d_sincos_pos_embed
  • get_2d_sincos_pos_embed_from_grid
  • get_1d_sincos_pos_embed_from_grid
  • get_2d_rotary_pos_embed

The deprecated 'np' path is preserved for callers who pass it explicitly.

All eight in-tree call sites already pass output_type='pt' explicitly — this only affects external callers using the default.

Before

from diffusers.models import embeddings as E
E.get_2d_sincos_pos_embed(embed_dim=8, grid_size=2)
# ValueError: The deprecation tuple (..., '0.33.0', ...) should be removed since diffusers' version 0.40.0 is >= 0.33.0

After

E.get_2d_sincos_pos_embed(embed_dim=8, grid_size=2)
# torch.Size([4, 8])  ← works

Implemented with Claude Code assistance. All changed lines reviewed manually.

…tional embedding helpers

Four public helpers defaulted to output_type='np', which routes into a
past-target deprecate() call (target 0.33.0/0.34.0, current 0.40.0).
deprecate() raises once the library version has passed the target, so
calling these functions with their defaults raised ValueError.

Changed the default to output_type='pt' in:
  - get_3d_sincos_pos_embed
  - get_2d_sincos_pos_embed
  - get_2d_sincos_pos_embed_from_grid
  - get_1d_sincos_pos_embed_from_grid
  - get_2d_rotary_pos_embed

The deprecated 'np' path is preserved for backward compatibility when
callers explicitly pass output_type='np', but the no-argument default
no longer crashes.

Fixes huggingface#14366

Signed-off-by: Aloys Jehwin <aloysjehwin@gmail.com>
@AloysJehwin

Copy link
Copy Markdown
Author

Fair point — I went with the minimal change (flip the default) without considering that the intent may be full removal of the np path. Happy to update the PR to remove the deprecated branch entirely if that's the preferred direction, or close and wait for a maintainer to confirm the intended approach. Let me know.

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

Labels

fixes-issue models size/S PR with diff < 50 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Public embeddings.py helpers raise ValueError with default arguments

1 participant