Skip to content

[core] deprecate torch_dtype and prefer dtype following transformers.#14205

Open
sayakpaul wants to merge 2 commits into
mainfrom
deprecate-torch-dtype
Open

[core] deprecate torch_dtype and prefer dtype following transformers.#14205
sayakpaul wants to merge 2 commits into
mainfrom
deprecate-torch-dtype

Conversation

@sayakpaul

Copy link
Copy Markdown
Member

@sayakpaul sayakpaul requested review from DN6 and yiyixuxu July 16, 2026 09:25
@github-actions github-actions Bot added size/L PR with diff > 200 LOC tests modular-pipelines utils pipelines ip-adapter and removed size/L PR with diff > 200 LOC labels Jul 16, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@github-actions github-actions Bot added the size/L PR with diff > 200 LOC label Jul 16, 2026

logger = logging.get_logger(__name__)

_TORCH_DTYPE_DEPRECATION_MESSAGE = "Please use `dtype` instead."

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would introduce a utility function here

def _resolve_dtype(dtype, torch_dtype):
    """Resolve the deprecated `torch_dtype` argument into `dtype`."""
    if torch_dtype is None:
        return dtype
    if dtype is not None:
        raise ValueError(
            "You have passed both `dtype` and `torch_dtype`. Please only pass `dtype`, `torch_dtype` is deprecated."
        )
    deprecate("torch_dtype", "1.0.0", _TORCH_DTYPE_DEPRECATION_MESSAGE)
    return torch_dtype

The call sites become simpler

# from_pretrained
torch_dtype = kwargs.pop("torch_dtype", None)
dtype = _resolve_dtype(kwargs.pop("dtype", None), torch_dtype)

# from_pipe
torch_dtype = kwargs.pop("torch_dtype", None)
dtype = _resolve_dtype(kwargs.pop("dtype", None), torch_dtype) or torch.float32

# modular_pipeline_utils.load
torch_dtype = kwargs.pop("torch_dtype", None)
if torch_dtype is not None:
    kwargs["dtype"] = _resolve_dtype(kwargs.get("dtype"), torch_dtype)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants