constants.py 2.52 KB
Newer Older
1
# Copyright 2024 The HuggingFace Inc. team. All rights reserved.
2
3
4
5
6
7
8
9
10
11
12
13
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
14
import importlib
15
16
import os

17
from huggingface_hub.constants import HF_HOME
18
19
from packaging import version

20
21
from ..dependency_versions_check import dep_version_check
from .import_utils import ENV_VARS_TRUE_VALUES, is_peft_available, is_transformers_available
22

23

24
25
MIN_PEFT_VERSION = "0.6.0"
MIN_TRANSFORMERS_VERSION = "4.34.0"
26
_CHECK_PEFT = os.environ.get("_CHECK_PEFT", "1") in ENV_VARS_TRUE_VALUES
27

28
29
30

CONFIG_NAME = "config.json"
WEIGHTS_NAME = "diffusion_pytorch_model.bin"
31
WEIGHTS_INDEX_NAME = "diffusion_pytorch_model.bin.index.json"
32
33
34
FLAX_WEIGHTS_NAME = "diffusion_flax_model.msgpack"
ONNX_WEIGHTS_NAME = "model.onnx"
SAFETENSORS_WEIGHTS_NAME = "diffusion_pytorch_model.safetensors"
35
SAFE_WEIGHTS_INDEX_NAME = "diffusion_pytorch_model.safetensors.index.json"
36
SAFETENSORS_FILE_EXTENSION = "safetensors"
37
ONNX_EXTERNAL_WEIGHTS_NAME = "weights.pb"
38
HUGGINGFACE_CO_RESOLVE_ENDPOINT = os.environ.get("HF_ENDPOINT", "https://huggingface.co")
39
DIFFUSERS_DYNAMIC_MODULE_NAME = "diffusers_modules"
40
HF_MODULES_CACHE = os.getenv("HF_MODULES_CACHE", os.path.join(HF_HOME, "modules"))
41
DEPRECATED_REVISION_ARGS = ["fp16", "non-ema"]
42
43
44
45

# Below should be `True` if the current version of `peft` and `transformers` are compatible with
# PEFT backend. Will automatically fall back to PEFT backend if the correct versions of the libraries are
# available.
46
# For PEFT it is has to be greater than or equal to 0.6.0 and for transformers it has to be greater than or equal to 4.34.0.
47
48
_required_peft_version = is_peft_available() and version.parse(
    version.parse(importlib.metadata.version("peft")).base_version
49
) >= version.parse(MIN_PEFT_VERSION)
50
51
_required_transformers_version = is_transformers_available() and version.parse(
    version.parse(importlib.metadata.version("transformers")).base_version
52
) >= version.parse(MIN_TRANSFORMERS_VERSION)
53
54

USE_PEFT_BACKEND = _required_peft_version and _required_transformers_version
55
56
57

if USE_PEFT_BACKEND and _CHECK_PEFT:
    dep_version_check("peft")