Trainer.model.push_to_hub() should allow private repository flag
Author: arikanev
Pull request: no

### Feature request

Trainer.model.push_to_hub() should allow a push to a private repository, as opposed to just pushing to a public and having to private it after.

### Motivation

I get frustrated having to private my repositories instead of being able to upload models by default to a private repo programmatically.

### Your contribution

I’m not sure I have the bandwidth at the moment or have the infrastructure know how to contribute this option, but if this is of interest to many people and you guys could use the help I can work on a PR.

Comments:
Hi @arikanev, thanks for raising this issue. 

In `TrainingArguments` you can set [hub_private_repo to `True`](https://huggingface.co/docs/transformers/v4.31.0/en/main_classes/trainer#transformers.TrainingArguments.hub_private_repo) to control this. 

Thanks for the heads up! Time saver :) 

Please note, I tried using this in TrainingArguments and it did not work! I set hub_private_repo to True.

Hi @arikanev, OK thanks for reporting.. 

So that we can help, could you provide some more details: 
* A minimal code snippet to reproduce the issue 
* Information about the running environment: run `transformers-cli env` in the terminal and copy-paste the output 
* More information about the expected and observed behaviour: when you say it didn't work, what specifically? Did it fail with an error, not create a repo, create a public repo etc? 

```
training_args = TrainingArguments(
                output_dir="./myLM",  # output directory for model predictions and checkpoints
                overwrite_output_dir=True,
                num_train_epochs=50,  # total number of training epochs
                per_device_train_batch_size=16,  # batch size per device during training
                per_device_eval_batch_size=64,  # batch size for evaluation
                warmup_steps=warmup_steps,  # number of warmup steps for learning rate scheduler
                weight_decay=weight_decay,  # strength of weight decay
                logging_dir="./logs",  # directory for storing logs
                logging_steps=10000,  # when to print log
                evaluation_strategy="steps",
                report_to='wandb',
                save_total_limit=2,
                hub_private_repo=True,
                fp16=True,
            )
            
```


tokenizers-0.13.3 transformers-4.31.0

It created a public repository even though I set private_hub_repo=True

Thanks!




            
            

Hi @arikanev, thanks for confirming. 

That's really weird 🤔 I'm not able to reproduce on my end. Could you try running the following and let me know if it works:

```
python examples/pytorch/language-modeling/run_clm.py \
    --model_name_or_path gpt2 \
    --dataset_name wikitext \
    --dataset_config_name wikitext-2-raw-v1 \
    --per_device_train_batch_size 8 \
    --per_device_eval_batch_size 8 \
    --do_train \
    --do_eval \
    --output_dir /tmp/test-clm \
    --hub_private_repo \
    --push_to_hub \
    --max_train_samples 10 \
    --max_eval_samples 10
```

This is running [this example script](https://github.com/huggingface/transformers/blob/5ee9693a1c77c617ebc43ef20194b6d3b674318e/examples/pytorch/language-modeling/run_clm.py) in transformers.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.