Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

CTRL model can not work in huggingface transformers #80

Open
yananchen1989 opened this issue Apr 7, 2021 · 2 comments
Open

CTRL model can not work in huggingface transformers #80

yananchen1989 opened this issue Apr 7, 2021 · 2 comments

Comments

@yananchen1989
Copy link

torch ver: 1.8.1+cu102
transformers ver: 4.4.2

I adopt the example codes from https://github.com/huggingface/transformers/blob/master/examples/text-generation/run_generation.py
to generate text by using ctrl.
here is the head part of my codes:

import torch
from transformers import CTRLTokenizer, CTRLLMHeadModel
tokenizer = CTRLTokenizer.from_pretrained('ctrl')
model = CTRLLMHeadModel.from_pretrained('ctrl')

encoded_prompt = tokenizer.encode("Links Hello, my dog is cute", add_special_tokens=False)

ERROR:

ValueError Traceback (most recent call last)
in
----> 1 encoded_prompt = tokenizer.encode("Links Hello, my dog is cute", add_special_tokens=False)

~/yanan/env/lib/python3.6/site-packages/transformers/tokenization_utils_base.py in encode(self, text, text_pair, add_special_tokens, padding, truncation, max_length, stride, return_tensors, **kwargs)
2030 stride=stride,
2031 return_tensors=return_tensors,
-> 2032 **kwargs,
2033 )
2034

~/yanan/env/lib/python3.6/site-packages/transformers/tokenization_utils_base.py in encode_plus(self, text, text_pair, add_special_tokens, padding, truncation, max_length, stride, is_split_into_words, pad_to_multiple_of, return_tensors, return_token_type_ids, return_attention_mask, return_overflowing_tokens, return_special_tokens_mask, return_offsets_mapping, return_length, verbose, **kwargs)
2355 return_length=return_length,
2356 verbose=verbose,
-> 2357 **kwargs,
2358 )
2359

~/yanan/env/lib/python3.6/site-packages/transformers/tokenization_utils.py in _encode_plus(self, text, text_pair, add_special_tokens, padding_strategy, truncation_strategy, max_length, stride, is_split_into_words, pad_to_multiple_of, return_tensors, return_token_type_ids, return_attention_mask, return_overflowing_tokens, return_special_tokens_mask, return_offsets_mapping, return_length, verbose, **kwargs)
458 return_special_tokens_mask=return_special_tokens_mask,
459 return_length=return_length,
--> 460 verbose=verbose,
461 )
462

~/yanan/env/lib/python3.6/site-packages/transformers/tokenization_utils_base.py in prepare_for_model(self, ids, pair_ids, add_special_tokens, padding, truncation, max_length, stride, pad_to_multiple_of, return_tensors, return_token_type_ids, return_attention_mask, return_overflowing_tokens, return_special_tokens_mask, return_offsets_mapping, return_length, verbose, prepend_batch_axis, **kwargs)
2792 padding=padding_strategy.value,
2793 pad_to_multiple_of=pad_to_multiple_of,
-> 2794 return_attention_mask=return_attention_mask,
2795 )
2796

~/yanan/env/lib/python3.6/site-packages/transformers/tokenization_utils_base.py in pad(self, encoded_inputs, padding, max_length, pad_to_multiple_of, return_attention_mask, return_tensors, verbose)
2591 else:
2592 raise ValueError(
-> 2593 f"type of {first_element} unknown: {type(first_element)}. "
2594 f"Should be one of a python, numpy, pytorch or tensorflow object."
2595 )

ValueError: type of None unknown: <class 'NoneType'>. Should be one of a python, numpy, pytorch or tensorflow object.

@yananchen1989
Copy link
Author

python run_generation.py --model_type ctrl --model_name ctrl --temperature 0 --repetition 1.2

04/07/2021 10:22:08 - WARNING - main - device: cpu, n_gpu: 0, 16-bits training: False
04/07/2021 10:23:25 - INFO - main - Namespace(device=device(type='cpu'), fp16=False, k=0, length=20, model_name_or_path='ctrl', model_type='ctrl', n_gpu=0, no_cuda=False, num_return_sequences=1, p=0.9, padding_text='', prefix='', prompt='', repetition_penalty=1.2, seed=42, stop_token=None, temperature=0.0, xlm_language='')
Model prompt >>> Links Hello, my dog is cute
2021-04-07 10:24:00.280690: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2021-04-07 10:24:00.280732: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
File "run_generation.py", line 290, in
main()
File "run_generation.py", line 231, in main
preprocessed_prompt_text = prepare_input(args, model, tokenizer, prompt_text)
File "run_generation.py", line 92, in prepare_ctrl_input
encoded_prompt = tokenizer.encode(prompt_text, add_special_tokens=False)
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py", line 2032, in encode
**kwargs,
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py", line 2357, in encode_plus
**kwargs,
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils.py", line 460, in _encode_plus
verbose=verbose,
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py", line 2794, in prepare_for_model
return_attention_mask=return_attention_mask,
File "/usr/local/lib/python3.6/dist-packages/transformers/tokenization_utils_base.py", line 2593, in pad
f"type of {first_element} unknown: {type(first_element)}. "
ValueError: type of None unknown: <class 'NoneType'>. Should be one of a python, numpy, pytorch or tensorflow object.

@sandcobainer
Copy link

Any updates on this? I haven't found any documentation about how to run the CTRL model from huggingface transformers either.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants