# How to push trained models and save it privately on hub?

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%3E%5C
**Category:** 🤗Hub\
**Created:** [November 4, 2022, 11:34am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538 "2022-11-04T11:34:23Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaditya](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/aaditya/32/20855_2.png) [@aaditya](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Faaditya)%5C
**Post date:** [November 4, 2022, 11:34am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F1 "2022-11-04T11:34:24Z")

</div>

Hi, I have already trained a few models and now I want to push all models to the hub but keep them private.

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [November 4, 2022, 12:27pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F2 "2022-11-04T12:27:13Z")

</div>

Hi,

Pushing to the private hub is as easy as `model.push_to_hub(private=True)`

---

<div class="post-metadata">

**Author:** ![aaditya](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/aaditya/32/20855_2.png) [@aaditya](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Faaditya)%5C
**Post date:** [November 4, 2022, 6:22pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F3 "2022-11-04T18:22:08Z")

</div>

I have use same line for pushing model, tokenizer but how to push training args?

---

<div class="post-metadata">

**Author:** ![AlhitawiMohammed22](https://avatars.discourse-cdn.com/v4/letter/a/b5a626/32.png) [@AlhitawiMohammed22](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FAlhitawiMohammed22)%5C
**Post date:** [March 17, 2023, 4:10pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F4 "2023-03-17T16:10:16Z")

</div>

> [@nielsr](#):
>
> private=True

same line for pushing model  
+1

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [April 4, 2023, 6:18pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F6 "2023-04-04T18:18:14Z")

</div>

Sure, here’s the docs: [Models](https://huggingface.co/docs/transformers/v4.27.2/en/main_classes/model#transformers.PreTrainedModel.push_to_hub)

---

<div class="post-metadata">

**Author:** ![RylanSchaeffer](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@RylanSchaeffer](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FRylanSchaeffer)%5C
**Post date:** [July 16, 2024, 1:51pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F7 "2024-07-16T13:51:45Z")

</div>

When I try `trainer.push_to_hub(private=True)`, I receive the error:

```auto
    trainer.push_to_hub(private=True)
  File "/lfs/ampere8/0/rschaef/miniconda3/envs/reward_modeling_env/lib/python3.10/site-packages/transformers/trainer.py", line 4301, in push_to_hub
    self.create_model_card(model_name=model_name, **kwargs)
TypeError: Trainer.create_model_card() got an unexpected keyword argument 'private'
[rank0]: Traceback (most recent call last):
[rank0]: File "/lfs/ampere8/0/rschaef/reward_model_switching_mitigates_overoptimization/src/sft/trainer_sft.py", line 464, in <module>
[rank0]: main()
[rank0]: File "/lfs/ampere8/0/rschaef/reward_model_switching_mitigates_overoptimization/src/sft/trainer_sft.py", line 459, in main
[rank0]: trainer.push_to_hub(private=True)
[rank0]: File "/lfs/ampere8/0/rschaef/miniconda3/envs/reward_modeling_env/lib/python3.10/site-packages/transformers/trainer.py", line 4301, in push_to_hub
[rank0]: self.create_model_card(model_name=model_name, **kwargs)
[rank0]: TypeError: Trainer.create_model_card() got an unexpected keyword argument 'private'

```

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [August 26, 2024, 2:05pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F8 "2024-08-26T14:05:27Z")

</div>

Hi,

What’s your Transformers version? Perhaps it is outdated

---

<div class="post-metadata">

**Author:** ![RylanSchaeffer](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@RylanSchaeffer](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FRylanSchaeffer)%5C
**Post date:** [September 12, 2024, 1:20am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F9 "2024-09-12T01:20:25Z")

</div>

I hit this problem again. Version ‘4.44.0’

---

<div class="post-metadata">

**Author:** ![nielsr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nielsr/32/39617_2.png) [@nielsr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnielsr)%5C
**Post date:** [September 12, 2024, 8:50am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F10 "2024-09-12T08:50:24Z")

</div>

Looking at the [method signature](https://github.com/huggingface/transformers/blob/cea9ec086a14da1320940c5e48d7bd5dbcf32734/src/transformers/trainer.py#L4311), it looks like this method indeed doesn’t support the `private` keyword argument.

Edit: see answer below 🙂

---

<div class="post-metadata">

**Author:** ![nicoberk](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/nicoberk/32/26983_2.png) [@nicoberk](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnicoberk)%5C
**Post date:** [September 12, 2024, 9:43am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F11 "2024-09-12T09:43:10Z")

</div>

You should provide `hub_private_repo=True` in TrainingArgs, see here: [Trainer.model.push\_to\_hub() does not allow a private repository flag · Issue #32909 · huggingface/transformers · GitHub](https://github.com/huggingface/transformers/issues/32909#issuecomment-2304875881)

---

<div class="post-metadata">

**Author:** ![RylanSchaeffer](https://avatars.discourse-cdn.com/v4/letter/r/6f9a4e/32.png) [@RylanSchaeffer](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FRylanSchaeffer)%5C
**Post date:** [September 14, 2024, 5:19pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F12 "2024-09-14T17:19:16Z")

</div>

I’m confused by that GitHub thread for two reasons:

1. It seems like the TrainingArgs’s `hub_private_repo=True` only apply for the creation of the repo?

2. Regardless, I think it’d be good to have the ability to call `trainer.push_to_hub(private=True)` without needing to know to set TrainingArgs.

Should I still open an issue and maybe work on a PR?

---

<div class="post-metadata">

**Author:** ![not-lain](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/not-lain/32/59092_2.png) [@not-lain](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnot-lain)%5C
**Post date:** [September 14, 2024, 5:58pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-push-trained-models-and-save-it-privately-on-hub%2F25538%2F13 "2024-09-14T17:58:33Z")

</div>

@RylanSchaeffer  
I have created an issue at [add `private` parameter to trainer.push\_to\_hub · Issue #33492 · huggingface/transformers · GitHub](https://github.com/huggingface/transformers/issues/33492) to add this feature to the transformers library.

Although @nicoberk 's method does work as specified in the code source in [here](https://github.com/huggingface/transformers/blob/8bd2b1e8c23234cd607ca8d63f53c1edfea27462/src/transformers/trainer.py#L4309) and I highly recommend using it at the moment, but I also agree with you that we should get unified parameters in the push to hub method.
