question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'torch._C.PyTorchFileReader' object has no attribute'seek'

See original GitHub issue

Hello,

I am using the following model for sentence similarity

https://huggingface.co/sentence-transformers/stsb-xlm-r-multilingual/tree/main

word_embedding_model = models.Transformer(bert_model_dir)  # , max_seq_length=512
pooling_model = models.Pooling(word_embedding_model.get_word_embedding_dimension())
model = SentenceTransformer(modules=[word_embedding_model, pooling_model], device=device_str)

But, I get this error:

Traceback (most recent call last):

  File "/home/work/anaconda/lib/python3.6/site-packages/torch/serialization.py", line 306, in _check_seekable

    f.seek(f.tell())

AttributeError:'torch._C.PyTorchFileReader' object has no attribute'seek'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/home/work/anaconda/lib/python3.6/site-packages/transformers/modeling_utils.py", line 1205, in from_pretrained

    state_dict = torch.load(resolved_archive_file, map_location="cpu")

  File "/home/work/anaconda/lib/python3.6/site-packages/torch/serialization.py", line 584, in load

    return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args)

  File "/home/work/anaconda/lib/python3.6/site-packages/moxing/framework/file/file_io_patch.py", line 200, in _load

    _check_seekable(f)

  File "/home/work/anaconda/lib/python3.6/site-packages/torch/serialization.py", line 309, in _check_seekable

    raise_err_msg(["seek", "tell"], e)

  File "/home/work/anaconda/lib/python3.6/site-packages/torch/serialization.py", line 302, in raise_err_msg

    raise type(e)(msg)

AttributeError:'torch._C.PyTorchFileReader' object has no attribute'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a buffer like io.BytesIO and try to load from it instead .

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "code/similarity.py", line 118, in <module>

    word_embedding_model = models.Transformer(bert_model_dir) #, max_seq_length=512

  File "/home/work/anaconda/lib/python3.6/site-packages/sentence_transformers/models/Transformer.py", line 30, in __init__

    self.auto_model = AutoModel.from_pretrained(model_name_or_path, config=config, cache_dir=cache_dir)

  File "/home/work/anaconda/lib/python3.6/site-packages/transformers/models/auto/auto_factory.py", line 381, in from_pretrained

    return model_class.from_pretrained(pretrained_model_name_or_path, *model_args, config=config, **kwargs)

  File "/home/work/anaconda/lib/python3.6/site-packages/transformers/modeling_utils.py", line 1208, in from_pretrained

    f"Unable to load weights from pytorch checkpoint file for'{pretrained_model_name_or_path}' "

OSError: Unable to load weights from pytorch checkpoint file for'/home/work/user-job-dir/input/pretrained_models/stsb-xlm-r-multilingual/' at'/home/work/user-job-dir/input /pretrained_models/stsb-xlm-r-multilingual/pytorch_model.bin'If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True. 

I checked on web but could not find any solution. What could be the problem? Thank you.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
nreimerscommented, Jun 11, 2021

Ah ok, that is the problem.

The torch load function requires that the file system supports seek (e.g. see https://www.tutorialspoint.com/python/file_seek.htm)

Apparently, your company cloud file system does not support this elementary file system operation. Hence, torch.load cannot load any file.

Real solution would be to get a better company cloud with a file system that support basic I/O operations.

In PyTorch 1.6, they changed the file format when models are saved. Maybe on your company cloud the old file format works? You can try it with this model: https://public.ukp.informatik.tu-darmstadt.de/reimers/sentence-transformers/v0.2/bert-base-nli-cls-token.zip

It has still the pre PyTorch 1.6. file format.

0reactions
deadsoul44commented, Jun 16, 2021

torch.save(model, 'pytorch_model.bin', _use_new_zipfile_serialization=False)

This is working. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'torch._C.PyTorchFileReader' object has no attribute 'seek'
I tried to load the parameters of the model, but reported this error Code: from naie.datasets import get_data_reference import torch import ...
Read more >
AttributeError: 'str' object has no attribute 'seek' #183 - GitHub
when I run train.py.here are custom dataset: images: data\custom\images\1.jpg data\custom\images\2.jpg .. labels: data\custom\labels\1.txt ...
Read more >
AttributeError: 'ConvertModel' object has no attribute 'seek'
But I got this error: AttributeError: 'ConvertModel' object has no attribute 'seek'. You can only torch.load from a file that is seekable.
Read more >
A2 Voila PosixPath attribute 'tell' error - fast.ai Course Forums
I keep getting this attribute error with Voila running locally. ... AttributeError: 'PosixPath' object has no attribute 'tell'
Read more >
pytorch报错记录_小伟db的博客
AttributeError: 'dict' object has no attribute 'seek'. You can only torch.load from a file that is seekable. Please pre-load the data into a ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found