allenai/unifiedqa

Unable to download and use any of the models

alisonreboud opened this issue · 3 comments

Hi, I am not able to get the models using the readme snippet

from transformers import AutoTokenizer, T5ForConditionalGeneration

model_name = "allenai/unifiedqa-t5-small" # you can specify the model size here
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = T5ForConditionalGeneration.from_pretrained(model_name)

def run_model(input_string, **generator_args):
    input_ids = tokenizer.encode(input_string, return_tensors="pt")
    res = model.generate(input_ids, **generator_args)
    return tokenizer.batch_decode(res, `skip_special_tokens=True)

I get the following error

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/usr/lib/python3.6/tarfile.py in nti(s)
    188             s = nts(s, "ascii", "strict")
--> 189             n = int(s.strip() or "0", 8)
    190         except ValueError:

ValueError: invalid literal for int() with base 8: 'v2\nq\x03((X'

During handling of the above exception, another exception occurred:

InvalidHeaderError                        Traceback (most recent call last)
/usr/lib/python3.6/tarfile.py in next(self)
   2298             try:
-> 2299                 tarinfo = self.tarinfo.fromtarfile(self)
   2300             except EOFHeaderError as e:

/usr/lib/python3.6/tarfile.py in fromtarfile(cls, tarfile)
   1092         buf = tarfile.fileobj.read(BLOCKSIZE)
-> 1093         obj = cls.frombuf(buf, tarfile.encoding, tarfile.errors)
   1094         obj.offset = tarfile.fileobj.tell() - BLOCKSIZE

/usr/lib/python3.6/tarfile.py in frombuf(cls, buf, encoding, errors)
   1034 
-> 1035         chksum = nti(buf[148:156])
   1036         if chksum not in calc_chksums(buf):

/usr/lib/python3.6/tarfile.py in nti(s)
    190         except ValueError:
--> 191             raise InvalidHeaderError("invalid header")
    192     return n

InvalidHeaderError: invalid header

During handling of the above exception, another exception occurred:

ReadError                                 Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/torch/serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
    554         >>> torch.load('tensors.pt', map_location=lambda storage, loc: storage)
--> 555         # Load all tensors onto GPU 1
    556         >>> torch.load('tensors.pt', map_location=lambda storage, loc: storage.cuda(1))

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in legacy_load(f)
    465     pickler.persistent_id = persistent_id
--> 466     pickler.dump(obj)
    467     data_value = data_buf.getvalue()

/usr/lib/python3.6/tarfile.py in open(cls, name, mode, fileobj, bufsize, **kwargs)
   1590                 raise CompressionError("unknown compression type %r" % comptype)
-> 1591             return func(name, filemode, fileobj, **kwargs)
   1592 

/usr/lib/python3.6/tarfile.py in taropen(cls, name, mode, fileobj, **kwargs)
   1620             raise ValueError("mode must be 'r', 'a', 'w' or 'x'")
-> 1621         return cls(name, mode, fileobj, **kwargs)
   1622 

/usr/lib/python3.6/tarfile.py in __init__(self, name, mode, fileobj, format, tarinfo, dereference, ignore_zeros, encoding, errors, pax_headers, debug, errorlevel, copybufsize)
   1483                 self.firstmember = None
-> 1484                 self.firstmember = self.next()
   1485 

/usr/lib/python3.6/tarfile.py in next(self)
   2310                 elif self.offset == 0:
-> 2311                     raise ReadError(str(e))
   2312             except EmptyHeaderError:

ReadError: invalid header

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    855         from_tf = kwargs.pop("from_tf", False)
--> 856         force_download = kwargs.pop("force_download", False)
    857         resume_download = kwargs.pop("resume_download", False)

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in load(f, map_location, pickle_module, **pickle_load_args)
    385             try:
--> 386                 source_lines, _, source_file = get_source_lines_and_file(obj)
    387                 source = ''.join(source_lines)

/usr/local/lib/python3.6/dist-packages/torch/serialization.py in _load(f, map_location, pickle_module, **pickle_load_args)
    558         >>> torch.load('tensors.pt', map_location={'cuda:1':'cuda:0'})
--> 559         # Load tensor from io.BytesIO object
    560         >>> with open('tensor.pt', 'rb') as f:

RuntimeError: /root/.cache/torch/transformers/1fb349953ea9c104fd662676908c1c8496dfe57a33cb2e23b091055f49f76295.1f377393c926073ea459ce25ddbef3e4f3e9be2e4f3bf2d7684d211ff9740b52 is a zip archive (did you mean to use torch.jit.load()?)

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-51-72f3a3fc32af> in <module>
      3 model_name = "allenai/unifiedqa-t5-small" # you can specify the model size here
      4 tokenizer = AutoTokenizer.from_pretrained(model_name)
----> 5 model = T5ForConditionalGeneration.from_pretrained(model_name)
      6 
      7 def run_model(input_string, **generator_args):

/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    857         resume_download = kwargs.pop("resume_download", False)
    858         proxies = kwargs.pop("proxies", None)
--> 859         output_loading_info = kwargs.pop("output_loading_info", False)
    860         local_files_only = kwargs.pop("local_files_only", False)
    861         revision = kwargs.pop("revision", None)

OSError: Unable to load weights from pytorch checkpoint file. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True. "

Trying with from_tf=True, I get

`OSError                                   Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    834                       ``kwargs`` that corresponds to a configuration attribute will be used to override said attribute
--> 835                       with the supplied ``kwargs`` value. Remaining keys that do not correspond to any configuration
    836                       attribute will be passed to the underlying model's ``__init__`` function.

OSError: 

During handling of the above exception, another exception occurred:

OSError                                   Traceback (most recent call last)
<ipython-input-52-ad634a93ae8f> in <module>
      3 model_name = "allenai/unifiedqa-t5-small" # you can specify the model size here
      4 tokenizer = AutoTokenizer.from_pretrained(model_name)
----> 5 model = T5ForConditionalGeneration.from_pretrained(model_name,from_tf=True)
      6 
      7 def run_model(input_string, **generator_args):

/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py in from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
    840             >>> from transformers import BertConfig, BertModel
    841             >>> # Download model and configuration from S3 and cache.
--> 842             >>> model = BertModel.from_pretrained('bert-base-uncased')
    843             >>> # Model was saved using `save_pretrained('./test/saved_model/')` (for example purposes, not runnable).
    844             >>> model = BertModel.from_pretrained('./test/saved_model/')

OSError: Can't load weights for 'allenai/unifiedqa-t5-small'. Make sure that:

- 'allenai/unifiedqa-t5-small' is a correct model identifier listed on 'https://huggingface.co/models'

- or 'allenai/unifiedqa-t5-small' is the correct path to a directory containing a file named one of pytorch_model.bin, tf_model.h5, model.ckpt.`
-

Thanks a lot for your help!

Thanks for reporting the issue!

This is very likely due to the incompatibility of your transformers and pytorch. See this:
huggingface/transformers#7594

Hello thanks for your answer,
actually I was able to solve it upgrading my python version and running this

 from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
  
tokenizer = AutoTokenizer.from_pretrained("allenai/unifiedqa-t5-small")

model = AutoModelForSeq2SeqLM.from_pretrained("allenai/unifiedqa-t5-small")

I had another question : is it possible to get a confidence score as ouput ( I run the model on different text parts and only one has the answer so I would like to keep the one with the highest confidence). I have seen that it should be possible to add a output_scores arg in generate() but it doesnt seem to work)

is it possible to get a confidence score as output ...

See #14