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

How to quantify google/vit-base-patch16-224 pytorch_model.bin to int8 type with neural-compressor #1612

Open
yingmuying opened this issue Feb 19, 2024 · 3 comments
Assignees

Comments

@yingmuying
Copy link

No description provided.

@Kaihui-intel
Copy link
Collaborator

Hi @yingmuying
Thanks for raising this issue.
You can use dynamic quantization for the model:

from neural_compressor.config import PostTrainingQuantConfig
from neural_compressor import quantization

config = PostTrainingQuantConfig(device='cpu', approach='dynamic', domain='auto')
q_model = quantization.fit(your_model, config)

If you want to use other quantization methods, please refer to examples.

@yingmuying
Copy link
Author

yingmuying commented Feb 22, 2024 via email

@Kaihui-intel
Copy link
Collaborator

Kaihui-intel commented Feb 23, 2024

Hi @yingmuying , Thanks for your reply.
The PostTrainingQuantConfig is used to configure quantization parameters, you can refer to config-docstring to understand the meaning of parameters. There are some other descriptions to help you understand.

About static asymmetric/asymmetric quantization, you can configure by setting scheme field in op_type_dict or op_name_dict.
e.g.

    from neural_compressor.config import PostTrainingQuantConfig
    op_type_dict = {
        'Conv':{
            "weight": {
                "dtype": ["fp32"],
                "scheme": ["sym"],
            },
            "activation": {
                "dtype": ["fp32"]
            }
        }
    }
    config = PostTrainingQuantConfig(device='cpu', approach='static', domain='auto', op_type_dict=op_type_dict)

or match all layers by ".*":

op_type_dict = {".*": {"weight": {"dtype": ["int8"], "scheme": "sym"}, "activation": {"dtype": ["fp32"]}}} 
config = PostTrainingQuantConfig(device='cpu', approach='static', domain='auto', op_type_dict=op_type_dict)

more usage in specify-quantization-rules

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

No branches or pull requests

3 participants