Trainer.model.push_to_hub() does not allow a private repository flag
Author: qzc438
Pull request: no
Labels: name: trainer

name: Feature request

### System Info

As the title described.

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Use the function Trainer.model.push_to_hub().

### Expected behavior

Trainer.model.push_to_hub() allows a private repository flag.

Comments:
Hi @qzc438, thanks for opening this issue! 

The easiest way to enable this is to set `hub_private_repo=True` in [TrainingArgs](https://huggingface.co/docs/transformers/v4.44.1/en/main_classes/trainer#transformers.TrainingArguments.hub_private_repo). 

I would be nice to have this as a flag in the method too. Would you like to open a PR to add this? cc @muellerzr 

Dear team,

Can you check this link: https://github.com/huggingface/transformers/issues/25219
From what I can see, hub_private_repo=True is not working.

Sincerely,
Zhangcheng Qiang



Hi @qzc438, 

Could you run the example code from [this comment](https://github.com/huggingface/transformers/issues/25219#issuecomment-1668408539) and confirm if it works? 

I was unable to reproduce the reported issue in #25219. If you can provide an minimal code snippet which reproduces `hub_private_repo=True` not working and your environment information then we can try and dig into it 

Dear team,

I am trying to, but I cannot find a way to track the visibility of the
hugging face models in the audit log. I have tried your enterprise version,
but this information is still untrackable.

Sincerely,
Zhangcheng Qiang

On Tue, 27 Aug 2024 at 20:49, amyeroberts ***@***.***> wrote:

> Hi @qzc438 <https://github.com/qzc438>,
>
> Could you run the example code from this comment
> <https://github.com/huggingface/transformers/issues/25219#issuecomment-1668408539>
> and confirm if it works?
>
> I was unable to reproduce the reported issue in #25219
> <https://github.com/huggingface/transformers/issues/25219>. If you can
> provide an minimal code snippet which reproduces hub_private_repo=True
> not working and your environment information then we can try and dig into it
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/huggingface/transformers/issues/32909#issuecomment-2312187692>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AOVDZBHVTA3CQ5WSB25XF7TZTRKT3AVCNFSM6AAAAABM3IYLBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGMJSGE4DONRZGI>
> .
> You are receiving this because you were mentioned.Message ID:
> ***@***.***>
>


Hi @qzc438, are you [referring to these](https://huggingface.co/docs/hub/en/audit-logs)? Is this related to this issue? 

Yes, I am not sure whether the audit log provides the function to check visibility.

By visibility, do you mean whether the created repo is public or private? 

Yes, you are right.

I'm not super familiar with the audit logs - however I think they're centered around recording actions and activity of users. 

For a given repo and its name, you should be able to see directly on the hub whether it's private e.g. for a repo of mine

<img width="1026" alt="Screenshot 2024-08-28 at 12 36 25" src="https://github.com/user-attachments/assets/2a9ca4b6-42c0-43a5-8da8-69e9ceb060e3">


Yes, I see. The main point is that once you set the repository to private or public during creation, any changes in the code will not reflect the visibility. I tried to use the audit log to check if any intermediate changes happened.

> once you set the repository to private or public during creation, any changes in the code will not reflect the visibility

@qzc438 Just to be clear and make sure I understand the behaviour you're describing are you saying that: 

* A repo is created- let's say with the name `foo/bar` and `public` visibility
* You run a training pass, with `push_to_hub_model_id="foo/bar"` and `hub_private_repo=True` set in the training arguments
* When `trainer.push_to_hub` is called, the artefacts are pushed to `foo/bar`, and the repo `foo/bar` remains `public`

Is this correct? 

Yes, you are correct. Also, if you create a private repository, it cannot change to the public by running the code hub_private_repo=False.

OK, I see. Yes, this behaviour is expected. The arguments controlling if a repo is private or not, only apply to the repo's creation.