# AttributeError: 'NoneType' object has no attribute 'pad\_token'

**URL:** <https://discuss.huggingface.co/t/attributeerror-nonetype-object-has-no-attribute-pad-token/33843>\
**Category:** 🤗Optimum\
**Created:** [March 15, 2023, 8:09am UTC](https://discuss.huggingface.co/t/attributeerror-nonetype-object-has-no-attribute-pad-token/33843 "2023-03-15T08:09:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gustavv99](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@gustavv99](https://discuss.huggingface.co/u/gustavv99)\
**Post date:** [March 15, 2023, 8:09am UTC](https://discuss.huggingface.co/t/attributeerror-nonetype-object-has-no-attribute-pad-token/33843/1 "2023-03-15T08:09:46Z")

</div>

Anyone ever experienced such a problem? I am using google colab to test optimising huggingface transformers with optimum, when using such models:

MODEL = “joeddav/xlm-roberta-large-xnli” or  
MODEL = “MoritzLaurer/mDeBERTa-v3-base-mnli-xnli”

And loading it to the onnx version:

from optimum.onnxruntime import ORTModelForSequenceClassification  
from transformers import AutoTokenizer  
from pathlib import Path

MODEL = “MoritzLaurer/mDeBERTa-v3-base-mnli-xnli”

onnx\_path = Path(“onnx”)

# load vanilla transformers and convert to onnx

model = ORTModelForSequenceClassification.from\_pretrained(MODEL, from\_transformers=True)  
tokenizer = AutoTokenizer.from\_pretrained(MODEL)

# save onnx checkpoint and tokenizer

model.save\_pretrained(onnx\_path)  
tokenizer.save\_pretrained(onnx\_path)

And then applying it to a zero shot classification pipeline:

from transformers import pipeline

TASK = “zero-shot-classification”

vanilla\_zero\_shot = pipeline(TASK, model, device=0)

print(f"pipeline is loaded on device {vanilla\_zero\_shot.model.device}")

print(vanilla\_zero\_shot(purposes[0], industry\_sectors, multi\_label=True))

I get such erorr:  
AttributeError Traceback (most recent call last)  
 in   
5 vanilla\_zero\_shot = pipeline(TASK, model, device=0)  
6 print(f"pipeline is loaded on device {vanilla\_zero\_shot.model.device}")  
----\> 7 print(vanilla\_zero\_shot(purposes[0], industry\_sectors, multi\_label=True))

9 frames  
/usr/local/lib/python3.9/dist-packages/transformers/pipelines/zero\_shot\_classification.py in \_parse\_and\_tokenize(self, sequence\_pairs, padding, add\_special\_tokens, truncation, \*\*kwargs)  
107 “”"  
108 return\_tensors = self.framework  
 → 109 if self.tokenizer.pad\_token is None:  
110 # Override for tokenizers not supporting padding  
111 logger.error(

AttributeError: ‘NoneType’ object has no attribute ‘pad\_token’

It work when using regular AutoModelForSequenceClassification and I can’t figure out why it doesn’t work here, perhaps these models are not supported by the onnx runtime?

---

<div class="post-metadata">

**Author:** ![regisss](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/regisss/32/22467_2.png) [@regisss](https://discuss.huggingface.co/u/regisss)\
**Post date:** [May 3, 2023, 6:15pm UTC](https://discuss.huggingface.co/t/attributeerror-nonetype-object-has-no-attribute-pad-token/33843/2 "2023-05-03T18:15:44Z")

</div>

Hi @gustavv99, with the `pipeline` from Transformers you’ll have to also provide the tokenizer as follows:

```python
vanilla_zero_shot = pipeline(TASK, model=model, tokenizer=tokenizer, device=0)

```
