TextClassifier object has no attribute 'push_to_hub'
I am unable to push finetuned BertModel to huggingface hub. Please find code below.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)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 errorAttributeError 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.
2024-04-25T18:39:42Z
Once I used BertForSequenceClassification instead of BertModel + Linear, I was able to push the model to hub.
2024-04-26T06:40:38Z
This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.