Skip to content

Conversation

@Kaihui-intel
Copy link
Contributor

@Kaihui-intel Kaihui-intel commented Oct 30, 2025

torch_dtype -> dtype
#776

Kaihui-intel and others added 2 commits October 30, 2025 04:39
Signed-off-by: Kaihui-intel <kaihui.tang@intel.com>
@wenhuach21
Copy link
Contributor

This change cannot be applied directly, since users running Transformers versions below 4.57 would no longer be supported.

@wenhuach21 wenhuach21 self-requested a review October 30, 2025 08:47
Copy link
Contributor

@wenhuach21 wenhuach21 left a comment

Choose a reason for hiding this comment

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

as said in comment

@Kaihui-intel
Copy link
Contributor Author

as said in comment

Do we need to upgrade transformers in requirement?

transformers>=4.38

Will it bring other problems?

@wenhuach21
Copy link
Contributor

as said in comment

Do we need to upgrade transformers in requirement?

transformers>=4.38

Will it bring other problems?

not a good option for now

@wenhuach21
Copy link
Contributor

1 one option is waiting for another 2 or 3 months to upgrade the trasnsformers
2 another is trying the way gpt suggested

import functools
import warnings

def support_legacy_keys(legacy_map: dict):
    """
    legacy_map: dict, key = 新参数名, value = 旧参数名
    """
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            for new_key, old_key in legacy_map.items():
                if old_key in kwargs:
                    if new_key in kwargs:
                        raise ValueError(f"Cannot use both '{new_key}' and '{old_key}'")
                    warnings.warn(f"'{old_key}' is deprecated, use '{new_key}' instead", DeprecationWarning)
                    kwargs[new_key] = kwargs.pop(old_key)
            return func(*args, **kwargs)
        return wrapper
    return decorator

使用示例:

@support_legacy_keys({"dtype": "torch_dtype"})
def quan(*, dtype=None):
    print(f"dtype = {dtype}")

# 调用方式
quan(dtype="torch.float16")       # 新参数
quan(torch_dtype="torch.float16") # 老参数,会自动映射并提示

@Kaihui-intel
Copy link
Contributor Author

Kaihui-intel commented Oct 31, 2025

1 one option is waiting for another 2 or 3 months to upgrade the trasnsformers 2 another is trying the way gpt suggested

import functools
import warnings

def support_legacy_keys(legacy_map: dict):
    """
    legacy_map: dict, key = 新参数名, value = 旧参数名
    """
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            for new_key, old_key in legacy_map.items():
                if old_key in kwargs:
                    if new_key in kwargs:
                        raise ValueError(f"Cannot use both '{new_key}' and '{old_key}'")
                    warnings.warn(f"'{old_key}' is deprecated, use '{new_key}' instead", DeprecationWarning)
                    kwargs[new_key] = kwargs.pop(old_key)
            return func(*args, **kwargs)
        return wrapper
    return decorator

使用示例:

@support_legacy_keys({"dtype": "torch_dtype"})
def quan(*, dtype=None):
    print(f"dtype = {dtype}")

# 调用方式
quan(dtype="torch.float16")       # 新参数
quan(torch_dtype="torch.float16") # 老参数,会自动映射并提示

For 2, we also need to add a judgment on the transformers version. I prefer option 1.
Do we still have examples of dependencies v4.38-v4.57?

@wenhuach21
Copy link
Contributor

1 one option is waiting for another 2 or 3 months to upgrade the trasnsformers 2 another is trying the way gpt suggested

import functools
import warnings

def support_legacy_keys(legacy_map: dict):
    """
    legacy_map: dict, key = 新参数名, value = 旧参数名
    """
    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            for new_key, old_key in legacy_map.items():
                if old_key in kwargs:
                    if new_key in kwargs:
                        raise ValueError(f"Cannot use both '{new_key}' and '{old_key}'")
                    warnings.warn(f"'{old_key}' is deprecated, use '{new_key}' instead", DeprecationWarning)
                    kwargs[new_key] = kwargs.pop(old_key)
            return func(*args, **kwargs)
        return wrapper
    return decorator

使用示例:

@support_legacy_keys({"dtype": "torch_dtype"})
def quan(*, dtype=None):
    print(f"dtype = {dtype}")

# 调用方式
quan(dtype="torch.float16")       # 新参数
quan(torch_dtype="torch.float16") # 老参数,会自动映射并提示

For 2, we also need to add a judgment on the transformers version. I prefer option 1. Do we still have examples of dependencies v4.38-v4.57?

This should not depend on our examples or perspective; we need to make decisions from the users’ point of view

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants