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

RuntimeError: unexpected EOF, expected 7491165 more bytes. The file might be corrupted. #1491

Closed
amankedia opened this issue Oct 11, 2019 · 16 comments

Comments

@amankedia
Copy link

❓ Questions & Help

I tried a small chunk of code from the Readme.md

import torch
from transformers import *
MODELS = [(BertModel,       BertTokenizer,       'bert-base-uncased')]
for model_class, tokenizer_class, pretrained_weights in MODELS:
    # Load pretrained model/tokenizer
    tokenizer = tokenizer_class.from_pretrained(pretrained_weights)
    model = model_class.from_pretrained(pretrained_weights)
    input_ids = torch.tensor([tokenizer.encode("Here is some text to encode", add_special_tokens=True)])  # Add special tokens takes care of adding [CLS], [SEP], <s>... tokens in the right way for each model.
    with torch.no_grad():
        last_hidden_states = model(input_ids)[0]

It is giving me the following error

RuntimeError                              Traceback (most recent call last)
<ipython-input-3-6528fe9b0472> in <module>
      3     tokenizer = tokenizer_class.from_pretrained(pretrained_weights)
----> 4     model = model_class.from_pretrained(pretrained_weights)

~/.conda/envs/transformers/lib/python3.7/site-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    343 
    344         if state_dict is None and not from_tf:
--> 345             state_dict = torch.load(resolved_archive_file, map_location='cpu')
    346 
    347         missing_keys = []

~/.conda/envs/transformers/lib/python3.7/site-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    424         if sys.version_info >= (3, 0) and 'encoding' not in pickle_load_args.keys():
    425             pickle_load_args['encoding'] = 'utf-8'
--> 426         return _load(f, map_location, pickle_module, **pickle_load_args)
    427     finally:
    428         if new_fd:

~/.conda/envs/transformers/lib/python3.7/site-packages/torch/serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
    618     for key in deserialized_storage_keys:
    619         assert key in deserialized_objects
--> 620         deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
    621         if offset is not None:
    622             offset = f.tell()

RuntimeError: unexpected EOF, expected 7491165 more bytes. The file might be corrupted.

Haven't modified anything in the library.

@LysandreJik
Copy link
Member

Hi! It seems to me that the file that was downloaded was corrupted, probably because of lacking space or a network error. Could you try using the from_pretrained with the force_download option ?

@amankedia
Copy link
Author

That worked. Thanks!

@prasadheeramani
Copy link

If you are using Window 10 machine, deleting vgg16-something in folder C:\Users\UserName\.cache\torch\checkpoints would solve probelm.

@iamxpy
Copy link

iamxpy commented Jan 24, 2020

Using force_download option also works for me.

@iitbombombay
Copy link

Hi! It seems to me that the file that was downloaded was corrupted, probably because of lacking space or a network error. Could you try using the from_pretrained with the force_download option ?

where to use this in the code?

Using force_download option also works for me.

Using force_download option also works for me.

Hi! It seems to me that the file that was downloaded was corrupted, probably because of lacking space or a network error. Could you try using the from_pretrained with the force_download option ?

how or where to use this in my code

@LysandreJik
Copy link
Member

Well, what's your code? from_pretrained should be the method you use to load models/configurations/tokenizers.

model = model_class.from_pretrained(pretrained_weights, force_download=True)

@lui-shex
Copy link

I want to run mmdetection demo image_demo.py but has this problems
I use google colab pytorch 1.3.1 .
Traceback (most recent call last):
File "demo/image_demo.py", line 26, in
main()
File "demo/image_demo.py", line 18, in main
model = init_detector(args.config, args.checkpoint, device=args.device)
File "/content/mmdetection/mmdet/apis/inference.py", line 35, in init_detector
checkpoint = load_checkpoint(model, checkpoint)
File "/root/mmcv/mmcv/runner/checkpoint.py", line 224, in load_checkpoint
checkpoint = _load_checkpoint(filename, map_location)
File "/root/mmcv/mmcv/runner/checkpoint.py", line 200, in _load_checkpoint
checkpoint = torch.load(filename, map_location=map_location)
File "/content/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 426, in load
return _load(f, map_location, pickle_module, **pickle_load_args)
File "/content/anaconda3/lib/python3.7/site-packages/torch/serialization.py", line 620, in _load
deserialized_objects[key]._set_from_file(f, offset, f_should_read_directly)
RuntimeError: storage has wrong size: expected -4934180888905747925 got 64

@suyashhchougule
Copy link

suyashhchougule commented Apr 9, 2021

if you are loading any weights in code, there might be problem with that just redownload the weights.. worked for me.

@saakshi077
Copy link

Using force_download option also works for me.

Where to add this argument ?

@LysandreJik
Copy link
Member

See this comment #1491 (comment)

@coder-ghw
Copy link

here is my code:
model = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True)
and I encountered the same problem, i delete the relevant files in "C:\Users\UserName.cache\torch\checkpoints" then solve the problem.

@Geraldene
Copy link

I am experiencing the same issue, I am using Ubuntu 18 WSL. When adding the force_download=True I am getting the following error:
/tape/models/modeling_utils.py", line 506, in from_pretrained model = cls(config, *model_args, **model_kwargs) TypeError: __init__() got an unexpected keyword argument 'force_download'

Any solutions will be highly appreciated.

@preciousakpan
Copy link

If you are using Window 10 machine, deleting vgg16-something in folder C:\Users\UserName\.cache\torch\checkpoints would solve probelm.

This worked for me

@alpttex19
Copy link

so how to solve this problem? @Geraldene

@k0001111
Copy link

sorry, what does it mean? could you be more pricesly?

@k0001111
Copy link

Using force_download option also works for me.

how did you use it/?

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

14 participants