def import_model(
    name: Tag | str,
    model_name_or_path: str | os.PathLike[str],
    *,
    proxies: dict[str, str] | None = None,
    revision: str = "main",
    variant: str | None = None,
    pipeline_class: str | type[diffusers.DiffusionPipeline] | None = None,
    sync_with_hub_version: bool = False,
    signatures: dict[str, ModelSignatureDict | ModelSignature] | None = None,
    labels: dict[str, str] | None = None,
    custom_objects: dict[str, t.Any] | None = None,
    external_modules: t.List[ModuleType] | None = None,
    metadata: dict[str, t.Any] | None = None,
    # ...
) -> bentoml.Model:
    """
    Import Diffusion model from a artifact URI to the BentoML model store.

    Args:
        name:
            The name to give to the model in the BentoML store. This must be a valid
            :obj:`~bentoml.Tag` name.
        model_name_or_path:
            Can be either:
            - A string, the *repo id* of a pretrained pipeline hosted inside a model repo on
              https://huggingface.co/ Valid repo ids have to be located under a user or organization name, like
              `CompVis/ldm-text2im-large-256`.
            - A path to a *directory* containing pipeline weights saved using
              [`~DiffusionPipeline.save_pretrained`], e.g., `./my_pipeline_directory/`.
        proxies (`Dict[str, str]`, *optional*):
            A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
            'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
        revision (`str`, *optional*, defaults to `"main"`):
            The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
            git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
            identifier allowed by git.
        variant (`str`, *optional*):
            Variant of the model to import. For example there's "fp16" and "fp32" variant for "DeepFloyd/IF-I-XL-v1.0".
            This may save download bandwidth and local disk space.
        sync_with_hub_version (`bool`, default to False):
            If sync_with_hub_version is true, then the model imported by
        signatures:
            Signatures of predict methods to be used. If not provided, the signatures
            default to {"__call__": {"batchable": False}}. See
            :obj:`~bentoml.types.ModelSignature` for more details.
        labels:
            A default set of management labels to be associated with the model. For
            example: ``{"training-set": "data-v1"}``.
        custom_objects:
            Custom objects to be saved with the model. An example is
            ``{"my-normalizer": normalizer}``. Custom objects are serialized with
            cloudpickle.
        metadata:
            Metadata to be associated with the model. An example is ``{"param_a": .2}``.

            Metadata is intended for display in a model management UI and therefore all
            values in metadata dictionary must be a primitive Python type, such as
            ``str`` or ``int``.

    Returns:
        A :obj:`~bentoml.Model` instance referencing a saved model in the local BentoML
        model store.

    Example:

    .. code-block:: python

        import bentoml

        bentoml.diffusers.import_model(
            'my_sd15_model',
            "runwayml/stable-diffusion-v1-5",
            signatures={
                "__call__": {"batchable": False},
            }
        )
    """

    tag = Tag.from_taglike(name)

    try:
        model = bentoml.models.get(tag)
        return model
    except bentoml.exceptions.NotFound:
        pass

    if sync_with_hub_version:
        if tag.version is not None:
            logger.warn(
                f"sync_with_hub_version is True, user provided version {tag.version} may be overridden by huggingface hub's commit hash"
            )

    context = ModelContext(
        framework_name="diffusers",
        framework_versions={"diffusers": diffusers.__version__},
    )

    if signatures is None:
        signatures = {
            "__call__": {"batchable": False},
        }
        logger.info(
            'Using the default model signature for diffusers (%s) for model "%s".',
            signatures,
            name,
        )

    if pipeline_class and isinstance(pipeline_class, str):
        pipeline_class = t.cast(
            type[diffusers.DiffusionPipeline], _str2cls(pipeline_class)
        )

    options_dict: dict[str, str] = {}
    if pipeline_class:
        cls_str = f"{pipeline_class.__module__}.{pipeline_class.__name__}"
        options_dict["pipeline_class"] = cls_str
    if variant:
        options_dict["variant"] = variant

    options = ModelOptions(**options_dict) if options_dict else None

    if os.path.isdir(model_name_or_path):
        src_dir = model_name_or_path
        if sync_with_hub_version:
            raise BentoMLException(
                "Cannot sync version with huggingface hub when importing a local model"
            )

    elif pipeline_class:
        src_dir = pipeline_class.download(
            model_name_or_path, proxies=proxies, revision=revision, variant=variant
        )

        if sync_with_hub_version:
            from huggingface_hub.file_download import REGEX_COMMIT_HASH

            version = extract_commit_hash(src_dir, REGEX_COMMIT_HASH)
            if version is not None:
                if variant is not None:
                    version = version + "-" + variant
                tag.version = version

    else:
        from huggingface_hub import snapshot_download

        src_dir = snapshot_download(
            model_name_or_path,
            proxies=proxies,
            revision=revision,
        )

        if sync_with_hub_version:
            from huggingface_hub.file_download import REGEX_COMMIT_HASH

            version = extract_commit_hash(src_dir, REGEX_COMMIT_HASH)
            if version is not None:
                tag.version = version

    with bentoml.models._create(  # type: ignore
        tag,
        module=MODULE_NAME,
        api_version=API_VERSION,
        signatures=signatures,
        labels=labels,
        options=options,
        custom_objects=custom_objects,
        external_modules=external_modules,
        metadata=metadata,
        context=context,
    ) as bento_model:
        diffusion_model_dir = bento_model.path_of(DIFFUSION_MODEL_FOLDER)
        ignore = shutil.ignore_patterns(".git")

        model_config_file = os.path.join(src_dir, DIFFUSION_MODEL_CONFIG_FILE)
        if not os.path.exists(model_config_file):
            raise BentoMLException(f'artifact "{src_dir}" is not a Diffusion model')

        shutil.copytree(src_dir, diffusion_model_dir, symlinks=False, ignore=ignore)

        return bento_model
Import Diffusion model from a artifact URI to the BentoML model store.

Args:
name:
The name to give to the model in the BentoML store. This must be a valid
:obj:`~bentoml.Tag` name.
model_name_or_path:
Can be either:
- A string, the *repo id* of a pretrained pipeline hosted inside a model repo on
https://huggingface.co/ Valid repo ids have to be located under a user or organization name, like
`CompVis/ldm-text2im-large-256`.
- A path to a *directory* containing pipeline weights saved using
[`~DiffusionPipeline.save_pretrained`], e.g., `./my_pipeline_directory/`.
proxies (`Dict[str, str]`, *optional*):
A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
revision (`str`, *optional*, defaults to `"main"`):
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
identifier allowed by git.
variant (`str`, *optional*):
Variant of the model to import. For example there's "fp16" and "fp32" variant for "DeepFloyd/IF-I-XL-v1.0".
This may save download bandwidth and local disk space.
sync_with_hub_version (`bool`, default to False):
If sync_with_hub_version is true, then the model imported by
signatures:
Signatures of predict methods to be used. If not provided, the signatures
default to {"__call__": {"batchable": False}}. See
:obj:`~bentoml.types.ModelSignature` for more details.
labels:
A default set of management labels to be associated with the model. For
example: ``{"training-set": "data-v1"}``.
custom_objects:
Custom objects to be saved with the model. An example is
``{"my-normalizer": normalizer}``. Custom objects are serialized with
cloudpickle.
metadata:
Metadata to be associated with the model. An example is ``{"param_a": .2}``.

Metadata is intended for display in a model management UI and therefore all
values in metadata dictionary must be a primitive Python type, such as
``str`` or ``int``.

Returns:
A :obj:`~bentoml.Model` instance referencing a saved model in the local BentoML
model store.

Example:

.. code-block:: python

import bentoml

bentoml.diffusers.import_model(
'my_sd15_model',
"runwayml/stable-diffusion-v1-5",
signatures={
"__call__": {"batchable": False},
}
)
src/bentoml/_internal/frameworks/diffusers.py