clovaai / donut

Official Implementation of OCR-free Document Understanding Transformer (Donut) and Synthetic Document Generator (SynthDoG), ECCV 2022
https://arxiv.org/abs/2111.15664
MIT License
5.75k stars 466 forks source link

size mismatch for encoder.model.layers.1.downsample.norm.weight: copying a param with shape torch.Size([1024]) from checkpoint, the shape in current model is torch.Size([512]). #206

Open Sridhar-Ranganaboina opened 1 year ago

Sridhar-Ranganaboina commented 1 year ago

size mismatch for encoder.model.layers.1.downsample.norm.weight: copying a param with shape torch.Size([1024]) from checkpoint, the shape in current model is torch.Size([512]).

Getting this error at line no: 596 in model.py model = super(DonutModel, cls).from_pretrained(pretrained_model_name_or_path, revision="official", *model_args, **kwargs)

jzsyuan commented 1 year ago

ignore_mismatched_sizes=True

gwkrsrch commented 1 year ago

Hi, thank you for bringing this issue to our attention. It appears that the problem is likely related to the environment configuration. We will resolve this issue, while also updating the repository accordingly. In the meantime, we kindly request you to refer to the recently updated Google Colab demos and verify that the versions of the essential libraries are in alignment. You can find the necessary information at this link: GitHub Issue Comment

yaoliUoA commented 1 year ago

the google colab demo has the same size mismatch issue too.

I have reproduced the error in the "colab-demo-for-donut-base-finetuned-docvqa.ipynb" too.

/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py in _load_pretrained_model(cls, model, state_dict, loaded_keys, resolved_archive_file, pretrained_model_name_or_path, ignore_mismatched_sizes, sharded_metadata, _fast_init, low_cpu_mem_usage, device_map, offload_folder, offload_state_dict, dtype, is_quantized, keep_in_fp32_modules) 3530 "\n\tYou may consider adding ignore_mismatched_sizes=True in the model from_pretrained method." 3531 ) -> 3532 raise RuntimeError(f"Error(s) in loading state_dict for {model.class.name}:\n\t{error_msg}") 3533 3534 if is_quantized:

RuntimeError: Error(s) in loading state_dict for DonutModel: size mismatch for encoder.model.layers.1.downsample.norm.weight: copying a param with shape torch.Size([1024]) from checkpoint, the shape in current model is torch.Size([512]). size mismatch for encoder.model.layers.1.downsample.norm.bias: copying a param with shape torch.Size([1024]) from checkpoint, the shape in current model is torch.Size([512]). size mismatch for encoder.model.layers.1.downsample.reduction.weight: copying a param with shape torch.Size([512, 1024]) from checkpoint, the shape in current model is torch.Size([256, 512]). size mismatch for encoder.model.layers.2.downsample.norm.weight: copying a param with shape torch.Size([2048]) from checkpoint, the shape in current model is torch.Size([1024]). size mismatch for encoder.model.layers.2.downsample.norm.bias: copying a param with shape torch.Size([2048]) from checkpoint, the shape in current model is torch.Size([1024]). size mismatch for encoder.model.layers.2.downsample.reduction.weight: copying a param with shape torch.Size([1024, 2048]) from checkpoint, the shape in current model is torch.Size([512, 1024]). You may consider adding ignore_mismatched_sizes=True in the model from_pretrained method.

ariefwijaya commented 1 year ago

any update for this?

crackthedata commented 1 year ago

any update on this? Tried multiple versions of timm and transformers and still getting the same error

david-fm commented 10 months ago

Be sure to have the proper version:

!pip install transformers==4.25.1 !pip install pytorch-lightning==1.6.4 !pip install timm==0.5.4 !pip install gradio !pip install donut-python

and compare the app code with the corresponding Google Colab notebook