# TextClassifier object has no attribute 'push\_to\_hub'

**URL:** <https://discuss.huggingface.co/t/textclassifier-object-has-no-attribute-push-to-hub/82185>\
**Category:** Beginners\
**Created:** [April 17, 2024, 8:19am UTC](https://discuss.huggingface.co/t/textclassifier-object-has-no-attribute-push-to-hub/82185 "2024-04-17T08:19:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gigza](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gigza](https://discuss.huggingface.co/u/gigza)\
**Post date:** [April 17, 2024, 8:19am UTC](https://discuss.huggingface.co/t/textclassifier-object-has-no-attribute-push-to-hub/82185/1 "2024-04-17T08:19:52Z")

</div>

I am unable to push finetuned BertModel to huggingface hub. Please find code below.

```auto
class TextClassifier(nn.Module):

  def __init__ (self, n_classes):
    super(TextClassifier, self). __init__ ()
    self.bert = BertModel.from_pretrained(PRE_TRAINED_MODEL_NAME)
    self.out = nn.Linear(self.bert.config.hidden_size, n_classes)

```

```auto
torch.save(model.state_dict(), 'best_model_state.bin')
model = TextClassifier(2)
model.load_state_dict(torch.load('best_model_state.bin'))
model.push_to_hub("gigza/test-model")

```

Getting the error

```auto
AttributeError Traceback (most recent call last)

[<ipython-input-26-2acd9ec8989a>](https://3256pquw44t-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20240411-060128_RC00_623759654#) in <cell line: 12>() 10 #repo.push_to_hub(commit_message="Add model") 11 ---> 12 model.push_to_hub("gigza/test-model")

[/usr/local/lib/python3.10/dist-packages/torch/nn/modules/module.py](https://3256pquw44t-496ff2e9c6d22116-0-colab.googleusercontent.com/outputframe.html?vrz=colab_20240411-060128_RC00_623759654#) in __getattr__ (self, name) 1686 if name in modules: 1687 return modules[name] -> 1688 raise AttributeError(f"'{type(self). __name__ }' object has no attribute '{name}'") 1689 1690 def __setattr__ (self, name: str, value: Union[Tensor, 'Module']) -> None:

AttributeError: 'TextClassifier' object has no attribute 'push_to_hub'

```

Please advise on how to proceed further.

---

<div class="post-metadata">

**Author:** ![gigza](https://avatars.discourse-cdn.com/v4/letter/g/90db22/32.png) [@gigza](https://discuss.huggingface.co/u/gigza)\
**Post date:** [April 25, 2024, 6:39pm UTC](https://discuss.huggingface.co/t/textclassifier-object-has-no-attribute-push-to-hub/82185/2 "2024-04-25T18:39:42Z")

</div>

Once I used BertForSequenceClassification instead of BertModel + Linear, I was able to push the model to hub.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/hellohellohello/original/2X/d/de4155eb4aa4108ecb32a1389d7cc37ae69f88b7.png) [@system](https://discuss.huggingface.co/u/system)\
**Post date:** [April 26, 2024, 6:40am UTC](https://discuss.huggingface.co/t/textclassifier-object-has-no-attribute-push-to-hub/82185/3 "2024-04-26T06:40:38Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
