#
Models

🤗 Diffusers provides pretrained models for popular algorithms and modules to create custom diffusion systems. The primary function of models is to denoise an input sample as modeled by the distribution p θ(x t−1∣x t)p_{\theta}(x_{t-1}|x_{t})p θ​(x t−1​∣x t​).

All models are built from the base ModelMixin class which is a `torch.nn.Module` providing basic functionality for saving and loading models, locally and from the Hugging Face Hub.

##
ModelMixin

###
class diffusers.ModelMixin

< source >

( )

Base class for all models.

ModelMixin takes care of storing the model configuration and provides methods for loading, downloading and saving models.

- config_name (`str`) — Filename to save a model to when calling save_pretrained().

####
compile_repeated_blocks

< source >

( *args **kwargs )

Compiles only the frequently repeated sub-modules of a model (e.g. the Transformer layers) instead of compiling the entire model. This technique—often called regional compilation (see the PyTorch recipe https://docs.pytorch.org/tutorials/recipes/regional_compilation.html) can reduce end-to-end compile time substantially, while preserving the runtime speed-ups you would expect from a full `torch.compile`.

The set of sub-modules to compile is discovered by the presence of `_repeated_blocks` attribute in the model definition. Define this attribute on your model subclass as a list/tuple of class names (strings). Every module whose class name matches will be compiled.

Once discovered, each matching sub-module is compiled by calling `submodule.compile(*args, **kwargs)`. Any positional or keyword arguments you supply to `compile_repeated_blocks` are forwarded verbatim to `torch.compile`.

####
dequantize

< source >

( )

Potentially dequantize the model in case it has been quantized by a quantization method that support dequantization.

####
disable_gradient_checkpointing

< source >

( )

Deactivates gradient checkpointing for the current model (may be referred to as activation checkpointing or checkpoint activations in other frameworks).

####
disable_npu_flash_attention

< source >

( )

disable npu flash attention from torch_npu

####
disable_xformers_memory_efficient_attention

< source >

( )

Disable memory efficient attention from xFormers.

####
disable_xla_flash_attention

< source >

( )

Disable the flash attention pallals kernel for torch_xla.

####
enable_gradient_checkpointing

< source >

( gradient_checkpointing_func: typing.Optional[typing.Callable] = None )

Parameters

- gradient_checkpointing_func (`Callable`, optional) — The function to use for gradient checkpointing. If `None`, the default PyTorch checkpointing function is used (`torch.utils.checkpoint.checkpoint`).

Activates gradient checkpointing for the current model (may be referred to as activation checkpointing or checkpoint activations in other frameworks).

####
enable_group_offload

< source >

( onload_device: device offload_device: device = device(type='cpu') offload_type: str = 'block_level' num_blocks_per_group: typing.Optional[int] = None non_blocking: bool = False use_stream: bool = False record_stream: bool = False low_cpu_mem_usage = False offload_to_disk_path: typing.Optional[str] = None )

Activates group offloading for the current model.

See apply_group_offloading() for more information.

Example:

    >>> from diffusers import CogVideoXTransformer3DModel

    >>> transformer = CogVideoXTransformer3DModel.from_pretrained(
    ...     "THUDM/CogVideoX-5b", subfolder="transformer", torch_dtype=torch.bfloat16
    ... )

    >>> transformer.enable_group_offload(
    ...     onload_device=torch.device("cuda"),
    ...     offload_device=torch.device("cpu"),
    ...     offload_type="leaf_level",
    ...     use_stream=True,
    ... )

####
enable_layerwise_casting

< source >

( storage_dtype: dtype = torch.float8_e4m3fn compute_dtype: typing.Optional[torch.dtype] = None skip_modules_pattern: typing.Optional[typing.Tuple[str, ...]] = None skip_modules_classes: typing.Optional[typing.Tuple[typing.Type[torch.nn.modules.module.Module], ...]] = None non_blocking: bool = False )

Parameters

- storage_dtype (`torch.dtype`) — The dtype to which the model should be cast for storage.
- compute_dtype (`torch.dtype`) — The dtype to which the model weights should be cast during the forward pass.
- skip_modules_pattern (`Tuple[str, ...]`, optional) — A list of patterns to match the names of the modules to skip during the layerwise casting process. If set to `None`, default skip patterns are used to ignore certain internal layers of modules and PEFT layers.
- skip_modules_classes (`Tuple[Type[torch.nn.Module], ...]`, optional) — A list of module classes to skip during the layerwise casting process.
- non_blocking (`bool`, optional, defaults to `False`) — If `True`, the weight casting operations are non-blocking.

Activates layerwise casting for the current model.

Layerwise casting is a technique that casts the model weights to a lower precision dtype for storage but upcasts them on-the-fly to a higher precision dtype for computation. This process can significantly reduce the memory footprint from model weights, but may lead to some quality degradation in the outputs. Most degradations are negligible, mostly stemming from weight casting in normalization and modulation layers.

By default, most models in diffusers set the `_skip_layerwise_casting_patterns` attribute to ignore patch embedding, positional embedding and normalization layers. This is because these layers are most likely precision-critical for quality. If you wish to change this behavior, you can set the `_skip_layerwise_casting_patterns` attribute to `None`, or call apply_layerwise_casting() with custom arguments.

Example:

Using enable_layerwise_casting():

    >>> from diffusers import CogVideoXTransformer3DModel

    >>> transformer = CogVideoXTransformer3DModel.from_pretrained(
    ...     "THUDM/CogVideoX-5b", subfolder="transformer", torch_dtype=torch.bfloat16
    ... )

    >>> # Enable layerwise casting via the model, which ignores certain modules by default
    >>> transformer.enable_layerwise_casting(storage_dtype=torch.float8_e4m3fn, compute_dtype=torch.bfloat16)

####
enable_npu_flash_attention

< source >

( )

Enable npu flash attention from torch_npu

####
enable_xformers_memory_efficient_attention

< source >

( attention_op: typing.Optional[typing.Callable] = None )

Parameters

- attention_op (`Callable`, optional) — Override the default `None` operator for use as `op` argument to the `memory_efficient_attention()` function of xFormers.

Enable memory efficient attention from xFormers.

When this option is enabled, you should observe lower GPU memory usage and a potential speed up during inference. Speed up during training is not guaranteed.

⚠️ When memory efficient attention and sliced attention are both enabled, memory efficient attention takes precedent.

Examples:

    >>> import torch
    >>> from diffusers import UNet2DConditionModel
    >>> from xformers.ops import MemoryEfficientAttentionFlashAttentionOp

    >>> model = UNet2DConditionModel.from_pretrained(
    ...     "stabilityai/stable-diffusion-2-1", subfolder="unet", torch_dtype=torch.float16
    ... )
    >>> model = model.to("cuda")
    >>> model.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)

####
enable_xla_flash_attention

< source >

( partition_spec: typing.Optional[typing.Callable] = None **kwargs )

Enable the flash attention pallals kernel for torch_xla.

####
from_pretrained

< source >

( pretrained_model_name_or_path: typing.Union[str, os.PathLike, NoneType] **kwargs )

Parameters

- pretrained_model_name_or_path (`str` or `os.PathLike`, optional) — Can be either:
  - A string, the model id (for example `google/ddpm-celebahq-256`) of a pretrained model hosted on the Hub.
  - A path to a directory (for example `./my_model_directory`) containing the model weights saved with save_pretrained().
- cache_dir (`Union[str, os.PathLike]`, optional) — Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used.
- torch_dtype (`torch.dtype`, optional) — Override the default `torch.dtype` and load the model with another dtype.
- force_download (`bool`, optional, defaults to `False`) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
- proxies (`Dict[str, str]`, optional) — A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
- output_loading_info (`bool`, optional, defaults to `False`) — Whether or not to also return a dictionary containing missing keys, unexpected keys and error messages.
- local_files_only(`bool`, optional, defaults to `False`) — Whether to only load local model weights and configuration files or not. If set to `True`, the model won’t be downloaded from the Hub.
- token (`str` or bool, optional) — The token to use as HTTP bearer authorization for remote files. If `True`, the token generated from `diffusers-cli login` (stored in `~/.huggingface`) is used.
- revision (`str`, optional, defaults to `"main"`) — The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier allowed by Git.
- from_flax (`bool`, optional, defaults to `False`) — Load the model weights from a Flax checkpoint save file.
- subfolder (`str`, optional, defaults to `""`) — The subfolder location of a model file within a larger model repository on the Hub or locally.
- mirror (`str`, optional) — Mirror source to resolve accessibility issues if you’re downloading a model in China. We do not guarantee the timeliness or safety of the source, and you should refer to the mirror site for more information.
- device_map (`Union[int, str, torch.device]` or `Dict[str, Union[int, str, torch.device]]`, optional) — A map that specifies where each submodule should go. It doesn’t need to be defined for each parameter/buffer name; once a given module name is inside, every submodule of it will be sent to the same device. Defaults to `None`, meaning that the model will be loaded on CPU.

  Examples:

Instantiate a pretrained PyTorch model from a pretrained model configuration.

The model is set in evaluation mode - `model.eval()` - by default, and dropout modules are deactivated. To train the model, set it back in training mode with `model.train()`.

To use private or gated models, log-in with `huggingface-cli login`. You can also activate the special “offline-mode” to use this method in a firewalled environment.

Example:

    from diffusers import UNet2DConditionModel

    unet = UNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5", subfolder="unet")

If you get the error message below, you need to finetune the weights for your downstream task:

    Some weights of UNet2DConditionModel were not initialized from the model checkpoint at runwayml/stable-diffusion-v1-5 and are newly initialized because the shapes did not match:
    - conv_in.weight: found shape torch.Size([320, 4, 3, 3]) in the checkpoint and torch.Size([320, 9, 3, 3]) in the model instantiated
    You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.

####
get_memory_footprint

< source >

( return_buffers = True )

Parameters

- return_buffers (`bool`, optional, defaults to `True`) — Whether to return the size of the buffer tensors in the computation of the memory footprint. Buffers are tensors that do not require gradients and not registered as parameters. E.g. mean and std in batch norm layers. Please see: https://discuss.pytorch.org/t/what-pytorch-means-by-buffers/120266/2

Get the memory footprint of a model. This will return the memory footprint of the current model in bytes. Useful to benchmark the memory footprint of the current model and design some tests. Solution inspired from the PyTorch discussions: https://discuss.pytorch.org/t/gpu-memory-that-model-uses/56822/2

####
num_parameters

< source >

( only_trainable: bool = False exclude_embeddings: bool = False ) →
`int`

Parameters

- only_trainable (`bool`, optional, defaults to `False`) — Whether or not to return only the number of trainable parameters.
- exclude_embeddings (`bool`, optional, defaults to `False`) — Whether or not to return only the number of non-embedding parameters.

Returns

`int`

The number of parameters.

Get number of (trainable or non-embedding) parameters in the module.

Example:

    from diffusers import UNet2DConditionModel

    model_id = "runwayml/stable-diffusion-v1-5"
    unet = UNet2DConditionModel.from_pretrained(model_id, subfolder="unet")
    unet.num_parameters(only_trainable=True)
    859520964

####
save_pretrained

< source >

( save_directory: typing.Union[str, os.PathLike] is_main_process: bool = True save_function: typing.Optional[typing.Callable] = None safe_serialization: bool = True variant: typing.Optional[str] = None max_shard_size: typing.Union[int, str] = '10GB' push_to_hub: bool = False **kwargs )

Parameters

- save_directory (`str` or `os.PathLike`) — Directory to save a model and its configuration file to. Will be created if it doesn’t exist.
- is_main_process (`bool`, optional, defaults to `True`) — Whether the process calling this is the main process or not. Useful during distributed training and you need to call this function on all processes. In this case, set `is_main_process=True` only on the main process to avoid race conditions.
- save_function (`Callable`) — The function to use to save the state dictionary. Useful during distributed training when you need to replace `torch.save` with another method. Can be configured with the environment variable `DIFFUSERS_SAVE_MODE`.
- safe_serialization (`bool`, optional, defaults to `True`) — Whether to save the model using `safetensors` or the traditional PyTorch way with `pickle`.
- variant (`str`, optional) — If specified, weights are saved in the format `pytorch_model.<variant>.bin`.
- max_shard_size (`int` or `str`, defaults to `"10GB"`) — The maximum size for a checkpoint before being sharded. Checkpoints shard will then be each of size lower than this size. If expressed as a string, needs to be digits followed by a unit (like `"5GB"`). If expressed as an integer, the unit is bytes. Note that this limit will be decreased after a certain period of time (starting from Oct 2024) to allow users to upgrade to the latest version of `diffusers`. This is to establish a common default size for this argument across different libraries in the Hugging Face ecosystem (`transformers`, and `accelerate`, for example).
- push_to_hub (`bool`, optional, defaults to `False`) — Whether or not to push your model to the Hugging Face Hub after saving it. You can specify the repository you want to push to with `repo_id` (will default to the name of `save_directory` in your namespace).
- kwargs (`Dict[str, Any]`, optional) — Additional keyword arguments passed along to the push_to_hub() method.

Save a model and its configuration file to a directory so that it can be reloaded using the from_pretrained() class method.

####
set_use_npu_flash_attention

< source >

( valid: bool )

Set the switch for the npu flash attention.

##
FlaxModelMixin

###
class diffusers.FlaxModelMixin

< source >

( )

Base class for all Flax models.

FlaxModelMixin takes care of storing the model configuration and provides methods for loading, downloading and saving models.

- config_name (`str`) — Filename to save a model to when calling save_pretrained().

####
from_pretrained

< source >

( pretrained_model_name_or_path: typing.Union[str, os.PathLike] dtype: dtype = <class 'jax.numpy.float32'> *model_args **kwargs )

Parameters

- pretrained_model_name_or_path (`str` or `os.PathLike`) — Can be either:
  - A string, the model id (for example `runwayml/stable-diffusion-v1-5`) of a pretrained model hosted on the Hub.
  - A path to a directory (for example `./my_model_directory`) containing the model weights saved using save_pretrained().
- dtype (`jax.numpy.dtype`, optional, defaults to `jax.numpy.float32`) — The data type of the computation. Can be one of `jax.numpy.float32`, `jax.numpy.float16` (on GPUs) and `jax.numpy.bfloat16` (on TPUs).

  This can be used to enable mixed-precision training or half-precision inference on GPUs or TPUs. If specified, all the computation will be performed with the given `dtype`.

  This only specifies the dtype of the computation and does not influence the dtype of model parameters.

  If you wish to change the dtype of the model parameters, see to_fp16() and to_bf16().

- model_args (sequence of positional arguments, optional) — All remaining positional arguments are passed to the underlying model’s `__init__` method.
- cache_dir (`Union[str, os.PathLike]`, optional) — Path to a directory where a downloaded pretrained model configuration is cached if the standard cache is not used.
- force_download (`bool`, optional, defaults to `False`) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.
- proxies (`Dict[str, str]`, optional) — A dictionary of proxy servers to use by protocol or endpoint, for example, `{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
- local_files_only(`bool`, optional, defaults to `False`) — Whether to only load local model weights and configuration files or not. If set to `True`, the model won’t be downloaded from the Hub.
- revision (`str`, optional, defaults to `"main"`) — The specific model version to use. It can be a branch name, a tag name, a commit id, or any identifier allowed by Git.
- from_pt (`bool`, optional, defaults to `False`) — Load the model weights from a PyTorch checkpoint save file.
- kwargs (remaining dictionary of keyword arguments, optional) — Can be used to update the configuration object (after it is loaded) and initiate the model (for example, `output_attentions=True`). Behaves differently depending on whether a `config` is provided or automatically loaded:
  - If a configuration is provided with `config`, `kwargs` are directly passed to the underlying model’s `__init__` method (we assume all relevant updates to the configuration have already been done).
  - If a configuration is not provided, `kwargs` are first passed to the configuration class initialization function from_config(). Each key of the `kwargs` that corresponds to a configuration attribute is used to override said attribute with the supplied `kwargs` value. Remaining keys that do not correspond to any configuration attribute are passed to the underlying model’s `__init__` function.

Instantiate a pretrained Flax model from a pretrained model configuration.

Examples:

    >>> from diffusers import FlaxUNet2DConditionModel

    >>> # Download model and configuration from huggingface.co and cache.
    >>> model, params = FlaxUNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5")
    >>> # Model was saved using *save_pretrained('./test/saved_model/')* (for example purposes, not runnable).
    >>> model, params = FlaxUNet2DConditionModel.from_pretrained("./test/saved_model/")

If you get the error message below, you need to finetune the weights for your downstream task:

    Some weights of UNet2DConditionModel were not initialized from the model checkpoint at runwayml/stable-diffusion-v1-5 and are newly initialized because the shapes did not match:
    - conv_in.weight: found shape torch.Size([320, 4, 3, 3]) in the checkpoint and torch.Size([320, 9, 3, 3]) in the model instantiated
    You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.

####
save_pretrained

< source >

( save_directory: typing.Union[str, os.PathLike] params: typing.Union[typing.Dict, flax.core.frozen_dict.FrozenDict] is_main_process: bool = True push_to_hub: bool = False **kwargs )

Parameters

- save_directory (`str` or `os.PathLike`) — Directory to save a model and its configuration file to. Will be created if it doesn’t exist.
- params (`Union[Dict, FrozenDict]`) — A `PyTree` of model parameters.
- is_main_process (`bool`, optional, defaults to `True`) — Whether the process calling this is the main process or not. Useful during distributed training and you need to call this function on all processes. In this case, set `is_main_process=True` only on the main process to avoid race conditions.
- push_to_hub (`bool`, optional, defaults to `False`) — Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the repository you want to push to with `repo_id` (will default to the name of `save_directory` in your namespace).
- kwargs (`Dict[str, Any]`, optional) — Additional key word arguments passed along to the push_to_hub() method.

Save a model and its configuration file to a directory so that it can be reloaded using the from_pretrained() class method.

####
to_bf16

< source >

( params: typing.Union[typing.Dict, flax.core.frozen_dict.FrozenDict] mask: typing.Any = None )

Parameters

- params (`Union[Dict, FrozenDict]`) — A `PyTree` of model parameters.
- mask (`Union[Dict, FrozenDict]`) — A `PyTree` with same structure as the `params` tree. The leaves should be booleans. It should be `True` for params you want to cast, and `False` for those you want to skip.

Cast the floating-point `params` to `jax.numpy.bfloat16`. This returns a new `params` tree and does not cast the `params` in place.

This method can be used on a TPU to explicitly convert the model parameters to bfloat16 precision to do full half-precision training or to save weights in bfloat16 for inference in order to save memory and improve speed.

Examples:

    >>> from diffusers import FlaxUNet2DConditionModel

    >>> # load model
    >>> model, params = FlaxUNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5")
    >>> # By default, the model parameters will be in fp32 precision, to cast these to bfloat16 precision
    >>> params = model.to_bf16(params)
    >>> # If you don't want to cast certain parameters (for example layer norm bias and scale)
    >>> # then pass the mask as follows
    >>> from flax import traverse_util

    >>> model, params = FlaxUNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5")
    >>> flat_params = traverse_util.flatten_dict(params)
    >>> mask = {
    ...     path: (path[-2] != ("LayerNorm", "bias") and path[-2:] != ("LayerNorm", "scale"))
    ...     for path in flat_params
    ... }
    >>> mask = traverse_util.unflatten_dict(mask)
    >>> params = model.to_bf16(params, mask)

####
to_fp16

< source >

( params: typing.Union[typing.Dict, flax.core.frozen_dict.FrozenDict] mask: typing.Any = None )

Parameters

- params (`Union[Dict, FrozenDict]`) — A `PyTree` of model parameters.
- mask (`Union[Dict, FrozenDict]`) — A `PyTree` with same structure as the `params` tree. The leaves should be booleans. It should be `True` for params you want to cast, and `False` for those you want to skip.

Cast the floating-point `params` to `jax.numpy.float16`. This returns a new `params` tree and does not cast the `params` in place.

This method can be used on a GPU to explicitly convert the model parameters to float16 precision to do full half-precision training or to save weights in float16 for inference in order to save memory and improve speed.

Examples:

    >>> from diffusers import FlaxUNet2DConditionModel

    >>> # load model
    >>> model, params = FlaxUNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5")
    >>> # By default, the model params will be in fp32, to cast these to float16
    >>> params = model.to_fp16(params)
    >>> # If you want don't want to cast certain parameters (for example layer norm bias and scale)
    >>> # then pass the mask as follows
    >>> from flax import traverse_util

    >>> model, params = FlaxUNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5")
    >>> flat_params = traverse_util.flatten_dict(params)
    >>> mask = {
    ...     path: (path[-2] != ("LayerNorm", "bias") and path[-2:] != ("LayerNorm", "scale"))
    ...     for path in flat_params
    ... }
    >>> mask = traverse_util.unflatten_dict(mask)
    >>> params = model.to_fp16(params, mask)

####
to_fp32

< source >

( params: typing.Union[typing.Dict, flax.core.frozen_dict.FrozenDict] mask: typing.Any = None )

Parameters

- params (`Union[Dict, FrozenDict]`) — A `PyTree` of model parameters.
- mask (`Union[Dict, FrozenDict]`) — A `PyTree` with same structure as the `params` tree. The leaves should be booleans. It should be `True` for params you want to cast, and `False` for those you want to skip.

Cast the floating-point `params` to `jax.numpy.float32`. This method can be used to explicitly convert the model parameters to fp32 precision. This returns a new `params` tree and does not cast the `params` in place.

Examples:

    >>> from diffusers import FlaxUNet2DConditionModel

    >>> # Download model and configuration from huggingface.co
    >>> model, params = FlaxUNet2DConditionModel.from_pretrained("runwayml/stable-diffusion-v1-5")
    >>> # By default, the model params will be in fp32, to illustrate the use of this method,
    >>> # we'll first cast to fp16 and back to fp32
    >>> params = model.to_f16(params)
    >>> # now cast back to fp32
    >>> params = model.to_fp32(params)

##
PushToHubMixin

###
class diffusers.utils.PushToHubMixin

< source >

( )

A Mixin to push a model, scheduler, or pipeline to the Hugging Face Hub.

####
push_to_hub

< source >

( repo_id: str commit_message: typing.Optional[str] = None private: typing.Optional[bool] = None token: typing.Optional[str] = None create_pr: bool = False safe_serialization: bool = True variant: typing.Optional[str] = None )

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 pushing to an organization. `repo_id` can also be a path to a local directory.
- commit_message (`str`, optional) — Message to commit while pushing. Default to `"Upload {object}"`.
- private (`bool`, optional) — Whether to make the repo private. If `None` (default), the repo will be public unless the organization’s default is private. This value is ignored if the repo already exists.
- token (`str`, optional) — The token to use as HTTP bearer authorization for remote files. The token generated when running `huggingface-cli login` (stored in `~/.huggingface`).
- create_pr (`bool`, optional, defaults to `False`) — Whether or not to create a PR with the uploaded files or directly commit.
- safe_serialization (`bool`, optional, defaults to `True`) — Whether or not to convert the model weights to the `safetensors` format.
- variant (`str`, optional) — If specified, weights are saved in the format `pytorch_model.<variant>.bin`.

Upload model, scheduler, or pipeline files to the 🤗 Hugging Face Hub.

Examples:

    from diffusers import UNet2DConditionModel

    unet = UNet2DConditionModel.from_pretrained("stabilityai/stable-diffusion-2", subfolder="unet")

    # Push the `unet` to your namespace with the name "my-finetuned-unet".
    unet.push_to_hub("my-finetuned-unet")

    # Push the `unet` to an organization with the name "my-finetuned-unet".
    unet.push_to_hub("your-org/my-finetuned-unet")

< > Update on GitHub