declare-lab/tango2
92
1# Copyright 2023 The HuggingFace Inc. team. All rights reserved.2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14 15 16import os17 18from packaging import version19 20from .. import __version__21from .accelerate_utils import apply_forward_hook22from .constants import (23 CONFIG_NAME,24 DEPRECATED_REVISION_ARGS,25 DIFFUSERS_CACHE,26 DIFFUSERS_DYNAMIC_MODULE_NAME,27 FLAX_WEIGHTS_NAME,28 HF_MODULES_CACHE,29 HUGGINGFACE_CO_RESOLVE_ENDPOINT,30 ONNX_EXTERNAL_WEIGHTS_NAME,31 ONNX_WEIGHTS_NAME,32 SAFETENSORS_WEIGHTS_NAME,33 WEIGHTS_NAME,34)35from .deprecation_utils import deprecate36from .doc_utils import replace_example_docstring37from .dynamic_modules_utils import get_class_from_dynamic_module38from .hub_utils import (39 HF_HUB_OFFLINE,40 _add_variant,41 _get_model_file,42 extract_commit_hash,43 http_user_agent,44)45from .import_utils import (46 ENV_VARS_TRUE_AND_AUTO_VALUES,47 ENV_VARS_TRUE_VALUES,48 USE_JAX,49 USE_TF,50 USE_TORCH,51 DummyObject,52 OptionalDependencyNotAvailable,53 is_accelerate_available,54 is_accelerate_version,55 is_flax_available,56 is_inflect_available,57 is_k_diffusion_available,58 is_k_diffusion_version,59 is_librosa_available,60 is_note_seq_available,61 is_omegaconf_available,62 is_onnx_available,63 is_safetensors_available,64 is_scipy_available,65 is_tensorboard_available,66 is_tf_available,67 is_torch_available,68 is_torch_version,69 is_transformers_available,70 is_transformers_version,71 is_unidecode_available,72 is_wandb_available,73 is_xformers_available,74 requires_backends,75)76from .logging import get_logger77from .outputs import BaseOutput78from .pil_utils import PIL_INTERPOLATION79from .torch_utils import is_compiled_module, randn_tensor80 81 82if is_torch_available():83 from .testing_utils import (84 floats_tensor,85 load_hf_numpy,86 load_image,87 load_numpy,88 nightly,89 parse_flag_from_env,90 print_tensor_test,91 require_torch_2,92 require_torch_gpu,93 skip_mps,94 slow,95 torch_all_close,96 torch_device,97 )98 99from .testing_utils import export_to_video100 101 102logger = get_logger(__name__)103 104 105def check_min_version(min_version):106 if version.parse(__version__) < version.parse(min_version):107 if "dev" in min_version:108 error_message = (109 "This example requires a source install from HuggingFace diffusers (see "110 "`https://huggingface.co/docs/diffusers/installation#install-from-source`),"111 )112 else:113 error_message = f"This example requires a minimum version of {min_version},"114 error_message += f" but the version found is {__version__}.\n"115 raise ImportError(error_message)116 