# Where to put use\_auth\_token in the code if you can't run hugginface-cli login command?

**URL:** <https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701>\
**Category:** Beginners\
**Created:** [November 15, 2021, 3:44am UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701 "2021-11-15T03:44:28Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gildesh](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gildesh](https://discuss.huggingface.co/u/gildesh)\
**Post date:** [November 15, 2021, 3:44am UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701/1 "2021-11-15T03:44:28Z")

</div>

I am training a bart\_large\_cnn model for summarization, where I have used : -

```auto
training_args = Seq2SeqTrainingArguments(
    output_dir="results",
    num_train_epochs=1, # demo
    do_train=True,
    do_eval=True,
    per_device_train_batch_size=4, # demo
    per_device_eval_batch_size=4,
    # learning_rate=3e-05,
    warmup_steps=500,
    weight_decay=0.1,
    label_smoothing_factor=0.1,
    predict_with_generate=True,
    logging_dir="logs",
    logging_steps=50,
    save_total_limit=3,
    push_to_hub=True,
)

```

but when I try to compile :-

```auto
trainer = Seq2SeqTrainer(
    model=model,
    args=training_args,
    data_collator=data_collator,
    train_dataset=train_data,
    eval_dataset=validation_data,
    tokenizer=tokenizer,
    compute_metrics=compute_metrics
)

```

it gives an error :-

`HTTPError: Invalid user token. If you didn't pass a user token, make sure you are properly logged in by executing `huggingface-cli login`, and if you did pass a user token, double-check it's correct.`

Now, in the user documentation, its written that either pass the token as :-

`!huggingface-cli login`

or

`use_auth_token='token_value'`

I tried putting this token value as below :-

the first command (cli-login) doesn’t run (takes forever). so I used the second option as below; -

```auto
model = AutoModelForSeq2SeqLM.from_pretrained(model_name,use_auth_token='token_value')

tokenizer = AutoTokenizer.from_pretrained(model_name,use_auth_token = 'token_value')

```

but the same error keeps popping up.  
Where else can I put this token value to push my model to the hub?

---

<div class="post-metadata">

**Author:** ![gildesh](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gildesh](https://discuss.huggingface.co/u/gildesh)\
**Post date:** [November 15, 2021, 5:35am UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701/2 "2021-11-15T05:35:37Z")

</div>

I added the following parameter (hub\_token) in the training\_args as below :-

```auto
training_args = Seq2SeqTrainingArguments(
    output_dir="results",
    num_train_epochs=1, # demo
    do_train=True,
    do_eval=True,
    per_device_train_batch_size=4, # demo
    per_device_eval_batch_size=4,
    # learning_rate=3e-05,
    warmup_steps=500,
    weight_decay=0.1,
    label_smoothing_factor=0.1,
    predict_with_generate=True,
    logging_dir="logs",
    logging_steps=50,
    save_total_limit=3,
    push_to_hub=True,
    hub_token = 'token value'
)

```

but when I try to compile :-

```auto
trainer = Seq2SeqTrainer(
    model=model,
    args=training_args,
    data_collator=data_collator,
    train_dataset=train_data,
    eval_dataset=validation_data,
    tokenizer=tokenizer,
    compute_metrics=compute_metrics
)

```

```auto
FileNotFoundError: [WinError 2] The system cannot find the file specified
During handling of the above exception, another exception occurred:
File "C:\Users\abhay.saini\AppData\Local\Programs\Python\Python39\lib\site-packages\huggingface_hub\repository.py", line 489, in check_git_versions
    raise EnvironmentError(
OSError: Looks like you do not have git-lfs installed, please install. You can install from https://git-lfs.github.com/. Then run `git lfs install` (you only have to do this once).

```

I did then try installing git-lfs

```auto
pip install git-lfs
Requirement already satisfied: git-lfs in c:\users\abhay.saini\appdata\local\programs\python\python39\lib\site-packages (1.6)

```

but the error persists…  
Can anyone help?

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [November 15, 2021, 12:53pm UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701/3 "2021-11-15T12:53:20Z")

</div>

You need to do the `git lfs install` command for your last problem. As you found out, the `hub_token` argument is the right way to pass along your token!

---

<div class="post-metadata">

**Author:** ![nickmuchi](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nickmuchi/32/29420_2.png) [@nickmuchi](https://discuss.huggingface.co/u/nickmuchi)\
**Post date:** [January 3, 2022, 9:16pm UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701/4 "2022-01-03T21:16:20Z")

</div>

getting same error, did you manage to solve this?

---

<div class="post-metadata">

**Author:** ![kalsig](https://avatars.discourse-cdn.com/v4/letter/k/dfb087/32.png) [@kalsig](https://discuss.huggingface.co/u/kalsig)\
**Post date:** [September 16, 2022, 4:48pm UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701/5 "2022-09-16T16:48:26Z")

</div>

accept this

> **[CompVis/stable-diffusion-v1-4 · Hugging Face](https://huggingface.co/CompVis/stable-diffusion-v1-4)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

---

<div class="post-metadata">

**Author:** ![anisharitakula](https://avatars.discourse-cdn.com/v4/letter/a/82dd89/32.png) [@anisharitakula](https://discuss.huggingface.co/u/anisharitakula)\
**Post date:** [May 16, 2023, 7:49am UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701/6 "2023-05-16T07:49:42Z")

</div>

I am getting the same error even after using pip install git-lfs. Anyone managed to find a solution?

---

<div class="post-metadata">

**Author:** ![Ulkryxx](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ulkryxx/32/40410_2.png) [@Ulkryxx](https://discuss.huggingface.co/u/Ulkryxx)\
**Post date:** [February 5, 2025, 4:05am UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701/7 "2025-02-05T04:05:57Z")

</div>

Well, its been just over 3 years since the OP posted, but I must echo the general question within these responses… Has anyone solved this?

I have been scouring the internet and cannot find a fix.

---

<div class="post-metadata">

**Author:** ![Ulkryxx](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ulkryxx/32/40410_2.png) [@Ulkryxx](https://discuss.huggingface.co/u/Ulkryxx)\
**Post date:** [February 5, 2025, 4:24am UTC](https://discuss.huggingface.co/t/where-to-put-use-auth-token-in-the-code-if-you-cant-run-hugginface-cli-login-command/11701/8 "2025-02-05T04:24:52Z")

</div>

I think I found a fix: [huggingface-cli login doesn't work · Issue #2765 · huggingface/huggingface\_hub · GitHub](https://github.com/huggingface/huggingface_hub/issues/2765)
