Uploading a Model (Python push_to_hub)

I am trying to push a model to my model repo and it is giving me an error saying I dont have write access. I have created a write token and I am passing that into hugging face for authentication. I’m not sure what’s going wrong here.

It says I successfully login and have write access.

!huggingface-cli login

    _|    _|  _|    _|    _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|_|_|_|    _|_|      _|_|_|  _|_|_|_|
    _|    _|  _|    _|  _|        _|          _|    _|_|    _|  _|            _|        _|    _|  _|        _|
    _|_|_|_|  _|    _|  _|  _|_|  _|  _|_|    _|    _|  _|  _|  _|  _|_|      _|_|_|    _|_|_|_|  _|        _|_|_|
    _|    _|  _|    _|  _|    _|  _|    _|    _|    _|    _|_|  _|    _|      _|        _|    _|  _|        _|
    _|    _|    _|_|      _|_|_|    _|_|_|  _|_|_|  _|      _|    _|_|_|      _|        _|    _|    _|_|_|  _|_|_|_|

    To login, `huggingface_hub` requires a token generated from https://huggingface.co/settings/tokens .
Token: 
Add token as git credential? (Y/n) n
Token is valid (permission: write).
Your token has been saved to /root/.cache/huggingface/token
Login successful

Then I go to push the model and it does not work.

model.push_to_hub('kaylub/testing') #Private repo, I created to test this.
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py in hf_raise_for_status(response, endpoint_name)
    285     try:
--> 286         response.raise_for_status()
    287     except HTTPError as e:

10 frames
HTTPError: 403 Client Error: Forbidden for url: https://huggingface.co/api/models/kaylub/testing/preupload/main

The above exception was the direct cause of the following exception:

HfHubHTTPError                            Traceback (most recent call last)
/usr/local/lib/python3.10/dist-packages/huggingface_hub/utils/_errors.py in hf_raise_for_status(response, endpoint_name)
    331         # Convert `HTTPError` into a `HfHubHTTPError` to display request information
    332         # as well (request id and/or server error message)
--> 333         raise HfHubHTTPError(str(e), response=response) from e
    334 
    335 

HfHubHTTPError: 403 Client Error: Forbidden for url: https://huggingface.co/api/models/kaylub/testing/preupload/main (Request ID: Root=1-65b2b5c0-1f99eb0b23b2db4c672e41f1;cec81efe-b59d-483c-ba38-da4dcddca49a)

Forbidden: you must use a write token to upload to a repository.

I also tried to passing the token into push_to_hub and tried authenticating using the hugging face python package but it didnt seem to work either.

I am facing this issue and am unable to push any finetuned transformer model to :hugs:Hub. Did you resolve this? Is there any resolution for this?

do

import huggingface_hub
huggingface_hub.logout()

then again login with write token. This should work.

1 Like