401 Error when trying to upload model from local machine

Hello everyone,
im currently training LLMs locally with the Unsloth framework. After training they provide a way to upload your model to the Huggingface Hub.

model.push_to_hub_gguf(
“LuuWee/modelspacename”, # Change hf to your username!
tokenizer,
quantization_method = [“q4_k_m”, “q8_0”, “q5_k_m”,],
token = “hf_access_token”,
)

For it to upload you need to add your username and an Accesstoken in the request. This worked for me when i trained in Google Colab. I tried the same thing in my local environment and i got this error.

HfHubHTTPError: 401 Client Error: Unauthorized for url: https://huggingface.co/api/models/hf/model/preupload/main (Request ID: Root=1-682c51bd-2d7e194c6c897da00154ebba;4a67b560-fee0-4368-a3e9-a018e79e904b)

Invalid credentials in Authorization header

I was able to login via the huggingface-cli with the same token and i could also do the login via python. But saving the model still throws this error.

1 Like

There doesn’t seem to be a specific issue on GitHub, so if it’s working on Colab, I think it’s a network problem. There are too many possible causes for a 401 error.