PTQ4ViT icon indicating copy to clipboard operation
PTQ4ViT copied to clipboard

How to load the quantized models with PTQ4ViT into the net?

Open uniqzheng opened this issue 2 years ago • 4 comments

Hi! Thanks for your great work! There was a problem when I was trying to load the quantized model 'vit_base_patch16_384.pth' (you've provided) into the net created by timm.create_model. The error is as follows.

RuntimeError: Error(s) in loading state_dict for VisionTransformer: Missing key(s) in state_dict: "cls_token", "pos_embed", "patch_embed.proj.weight", "patch_embed.proj.bias", "blocks.0.norm1.weight", "blocks.0.norm1.bias", "blocks.0.attn.qkv.weight", "blocks.0.attn.qkv.bias", "blocks.0.attn.proj.weight", "blocks.0.attn.proj.bias", "blocks.0.norm2.weight", "blocks.0.norm2.bias", "blocks.0.mlp.fc1.weight", "blocks.0.mlp.fc1.bias", "blocks.0.mlp.fc2.weight", "blocks.0.mlp.fc2.bias".......

Would you please provide the correct method to load your quantized model? Thank you a lot~

uniqzheng avatar May 23 '22 09:05 uniqzheng

The quantized models only contains NN parameters in int8, which cannot be loaded and put into use directly. I would suggest you follow the given example files and quantize a model from given FP32 ones, which doesn't take too much time in our experiment setting.

SuperVan-Young avatar May 28 '22 03:05 SuperVan-Young

I've only taken notice of the issues recently. I'll start working on a more user-friendly interface ASAP, so that you don't have to quantize a model from scratch .

SuperVan-Young avatar May 28 '22 03:05 SuperVan-Young

Many thanks!!

uniqzheng avatar May 29 '22 14:05 uniqzheng

Excellent work! But Ialso want to know when will the quantized model can be loaded by myself ? Looking forward your reply, thank you and have a good work!

Wuyy-fairy avatar Mar 08 '23 12:03 Wuyy-fairy