Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sending directly torch/tf/np dtype for generating dummy inputs #2117

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

JingyaHuang
Copy link
Contributor

@JingyaHuang JingyaHuang commented Dec 5, 2024

What does this PR do?

Currently always via git push DTYPE_MAPPER:

class DTYPE_MAPPER:

It would be nice to directly accept the different dtypes of frameworks. Eg. I could load a model in torch.bfloat16 in this case, I would like to define the dummy inputs dtype with model.dtype instead of going through a reversed dict of the DTYPE_MAPPER.

@HuggingFaceDocBuilderDev

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.

Copy link
Member

@IlyasMoutawwakil IlyasMoutawwakil left a comment

Choose a reason for hiding this comment

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

Thanks ! This looks better and more flexible ! I left a couple of comments

optimum/utils/input_generators.py Outdated Show resolved Hide resolved
optimum/utils/input_generators.py Show resolved Hide resolved
optimum/utils/input_generators.py Outdated Show resolved Hide resolved
@IlyasMoutawwakil
Copy link
Member

tests are failing, seems like some string inputs are still being passed around

dtype = 'int64'

    @staticmethod
    def infer_framework_from_dtype(dtype):
        if is_torch_available() and isinstance(dtype, torch.dtype):
            framework = "pt"
        elif is_tf_available() and isinstance(dtype, tf.dtypes.DType):
            framework = "tf"
        elif isinstance(dtype, type):
            framework = "np"
        else:
>           raise ValueError(
                f"Unable to create a tensor/array with dtype({dtype}). Please ensure the corresponding framework is installed."
            )
E           ValueError: Unable to create a tensor/array with dtype(int64). Please ensure the corresponding framework is installed.

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.

4 participants