MCPcopy
hub / github.com/huggingface/diffusers / push_to_hub

Method push_to_hub

src/diffusers/utils/hub_utils.py:518–592  ·  view source on GitHub ↗

Upload model, scheduler, or pipeline files to the 🤗 Hugging Face Hub. Parameters: repo_id (`str`): The name of the repository you want to push your model, scheduler, or pipeline files to. It should contain your organization name when push

(
        self,
        repo_id: str,
        commit_message: str | None = None,
        private: bool | None = None,
        token: str | None = None,
        create_pr: bool = False,
        safe_serialization: bool = True,
        variant: str | None = None,
        subfolder: str | None = None,
    )

Source from the content-addressed store, hash-verified

516 )
517
518 def push_to_hub(
519 self,
520 repo_id: str,
521 commit_message: str | None = None,
522 private: bool | None = None,
523 token: str | None = None,
524 create_pr: bool = False,
525 safe_serialization: bool = True,
526 variant: str | None = None,
527 subfolder: str | None = None,
528 ) -> str:
529 """
530 Upload model, scheduler, or pipeline files to the 🤗 Hugging Face Hub.
531
532 Parameters:
533 repo_id (`str`):
534 The name of the repository you want to push your model, scheduler, or pipeline files to. It should
535 contain your organization name when pushing to an organization. `repo_id` can also be a path to a local
536 directory.
537 commit_message (`str`, *optional*):
538 Message to commit while pushing. Default to `"Upload {object}"`.
539 private (`bool`, *optional*):
540 Whether to make the repo private. If `None` (default), the repo will be public unless the
541 organization's default is private. This value is ignored if the repo already exists.
542 token (`str`, *optional*):
543 The token to use as HTTP bearer authorization for remote files. The token generated when running `hf
544 auth login` (stored in `~/.huggingface`).
545 create_pr (`bool`, *optional*, defaults to `False`):
546 Whether or not to create a PR with the uploaded files or directly commit.
547 safe_serialization (`bool`, *optional*, defaults to `True`):
548 Whether or not to convert the model weights to the `safetensors` format.
549 variant (`str`, *optional*):
550 If specified, weights are saved in the format `pytorch_model.<variant>.bin`.
551
552 Examples:
553
554 ```python
555 from diffusers import UNet2DConditionModel
556
557 unet = UNet2DConditionModel.from_pretrained("stabilityai/stable-diffusion-2", subfolder="unet")
558
559 # Push the `unet` to your namespace with the name "my-finetuned-unet".
560 unet.push_to_hub("my-finetuned-unet")
561
562 # Push the `unet` to an organization with the name "my-finetuned-unet".
563 unet.push_to_hub("your-org/my-finetuned-unet")
564 ```
565 """
566 repo_id = create_repo(repo_id, private=private, token=token, exist_ok=True).repo_id
567
568 # Create a new empty model card and eventually tag it
569 if not subfolder:
570 model_card = load_or_create_model_card(repo_id, token=token)
571 model_card = populate_model_card(model_card)
572
573 # Save all files.
574 save_kwargs = {"safe_serialization": safe_serialization}
575 if "Scheduler" not in self.__class__.__name__:

Calls 6

_upload_folderMethod · 0.95
populate_model_cardFunction · 0.85
saveMethod · 0.80
updateMethod · 0.45
save_pretrainedMethod · 0.45