clarifai 11.3.0rc2__py3-none-any.whl → 11.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- clarifai/__init__.py +1 -1
- clarifai/cli/__main__.py +1 -1
- clarifai/cli/base.py +144 -136
- clarifai/cli/compute_cluster.py +45 -31
- clarifai/cli/deployment.py +93 -76
- clarifai/cli/model.py +578 -180
- clarifai/cli/nodepool.py +100 -82
- clarifai/client/__init__.py +12 -2
- clarifai/client/app.py +973 -911
- clarifai/client/auth/helper.py +345 -342
- clarifai/client/auth/register.py +7 -7
- clarifai/client/auth/stub.py +107 -106
- clarifai/client/base.py +185 -178
- clarifai/client/compute_cluster.py +214 -180
- clarifai/client/dataset.py +793 -698
- clarifai/client/deployment.py +55 -50
- clarifai/client/input.py +1223 -1088
- clarifai/client/lister.py +47 -45
- clarifai/client/model.py +1939 -1717
- clarifai/client/model_client.py +525 -502
- clarifai/client/module.py +82 -73
- clarifai/client/nodepool.py +358 -213
- clarifai/client/runner.py +58 -0
- clarifai/client/search.py +342 -309
- clarifai/client/user.py +419 -414
- clarifai/client/workflow.py +294 -274
- clarifai/constants/dataset.py +11 -17
- clarifai/constants/model.py +8 -2
- clarifai/datasets/export/inputs_annotations.py +233 -217
- clarifai/datasets/upload/base.py +63 -51
- clarifai/datasets/upload/features.py +43 -38
- clarifai/datasets/upload/image.py +237 -207
- clarifai/datasets/upload/loaders/coco_captions.py +34 -32
- clarifai/datasets/upload/loaders/coco_detection.py +72 -65
- clarifai/datasets/upload/loaders/imagenet_classification.py +57 -53
- clarifai/datasets/upload/loaders/xview_detection.py +274 -132
- clarifai/datasets/upload/multimodal.py +55 -46
- clarifai/datasets/upload/text.py +55 -47
- clarifai/datasets/upload/utils.py +250 -234
- clarifai/errors.py +51 -50
- clarifai/models/api.py +260 -238
- clarifai/modules/css.py +50 -50
- clarifai/modules/pages.py +33 -33
- clarifai/rag/rag.py +312 -288
- clarifai/rag/utils.py +91 -84
- clarifai/runners/models/model_builder.py +906 -802
- clarifai/runners/models/model_class.py +370 -331
- clarifai/runners/models/model_run_locally.py +459 -419
- clarifai/runners/models/model_runner.py +170 -162
- clarifai/runners/models/model_servicer.py +78 -70
- clarifai/runners/server.py +111 -101
- clarifai/runners/utils/code_script.py +225 -187
- clarifai/runners/utils/const.py +4 -1
- clarifai/runners/utils/data_types/__init__.py +12 -0
- clarifai/runners/utils/data_types/data_types.py +598 -0
- clarifai/runners/utils/data_utils.py +387 -440
- clarifai/runners/utils/loader.py +247 -227
- clarifai/runners/utils/method_signatures.py +411 -386
- clarifai/runners/utils/openai_convertor.py +108 -109
- clarifai/runners/utils/serializers.py +175 -179
- clarifai/runners/utils/url_fetcher.py +35 -35
- clarifai/schema/search.py +56 -63
- clarifai/urls/helper.py +125 -102
- clarifai/utils/cli.py +129 -123
- clarifai/utils/config.py +127 -87
- clarifai/utils/constants.py +49 -0
- clarifai/utils/evaluation/helpers.py +503 -466
- clarifai/utils/evaluation/main.py +431 -393
- clarifai/utils/evaluation/testset_annotation_parser.py +154 -144
- clarifai/utils/logging.py +324 -306
- clarifai/utils/misc.py +60 -56
- clarifai/utils/model_train.py +165 -146
- clarifai/utils/protobuf.py +126 -103
- clarifai/versions.py +3 -1
- clarifai/workflows/export.py +48 -50
- clarifai/workflows/utils.py +39 -36
- clarifai/workflows/validate.py +55 -43
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/METADATA +16 -6
- clarifai-11.4.0.dist-info/RECORD +109 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/WHEEL +1 -1
- clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/errors.cpython-311.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
- clarifai/client/cli/__init__.py +0 -0
- clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
- clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/client/cli/base_cli.py +0 -88
- clarifai/client/cli/model_cli.py +0 -29
- clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-311.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/imagenet_classification.cpython-311.pyc +0 -0
- clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-311.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/dockerfile_template/Dockerfile.cpu.template +0 -31
- clarifai/runners/dockerfile_template/Dockerfile.cuda.template +0 -42
- clarifai/runners/dockerfile_template/Dockerfile.nim +0 -71
- clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/base_typed_model.py +0 -238
- clarifai/runners/models/model_class_refract.py +0 -80
- clarifai/runners/models/model_upload.py +0 -607
- clarifai/runners/models/temp.py +0 -25
- clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
- clarifai/runners/utils/data_handler.py +0 -231
- clarifai/runners/utils/data_handler_refract.py +0 -213
- clarifai/runners/utils/data_types.py +0 -469
- clarifai/runners/utils/logger.py +0 -0
- clarifai/runners/utils/openai_format.py +0 -87
- clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
- clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/helpers.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-311.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
- clarifai-11.3.0rc2.dist-info/RECORD +0 -322
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/entry_points.txt +0 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info/licenses}/LICENSE +0 -0
- {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/top_level.txt +0 -0
clarifai/runners/utils/loader.py
CHANGED
@@ -11,236 +11,256 @@ from clarifai.utils.logging import logger
|
|
11
11
|
|
12
12
|
|
13
13
|
class HuggingFaceLoader:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
14
|
+
HF_DOWNLOAD_TEXT = "The 'huggingface_hub' package is not installed. Please install it using 'pip install huggingface_hub'."
|
15
|
+
|
16
|
+
def __init__(self, repo_id=None, token=None, model_type_id=None):
|
17
|
+
self.repo_id = repo_id
|
18
|
+
self.token = token
|
19
|
+
self.clarifai_model_type_id = model_type_id
|
20
|
+
if token:
|
21
|
+
if self.validate_hftoken(token):
|
22
|
+
try:
|
23
|
+
from huggingface_hub import login
|
24
|
+
except ImportError:
|
25
|
+
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
26
|
+
login(token=token)
|
27
|
+
logger.info("Hugging Face token validated")
|
28
|
+
else:
|
29
|
+
self.token = None
|
30
|
+
logger.info("Continuing without Hugging Face token")
|
31
|
+
|
32
|
+
@classmethod
|
33
|
+
def validate_hftoken(cls, hf_token: str):
|
34
|
+
try:
|
35
|
+
if importlib.util.find_spec("huggingface_hub") is None:
|
36
|
+
raise ImportError(cls.HF_DOWNLOAD_TEXT)
|
37
|
+
from huggingface_hub import HfApi
|
38
|
+
|
39
|
+
api = HfApi()
|
40
|
+
api.whoami(token=hf_token)
|
41
|
+
return True
|
42
|
+
except Exception as e:
|
43
|
+
logger.error(
|
44
|
+
f"Error setting up Hugging Face token, please make sure you have the correct token: {e}"
|
45
|
+
)
|
46
|
+
return False
|
47
|
+
|
48
|
+
def download_checkpoints(
|
49
|
+
self, checkpoint_path: str, allowed_file_patterns=None, ignore_file_patterns=None
|
50
|
+
):
|
51
|
+
# throw error if huggingface_hub wasn't installed
|
23
52
|
try:
|
24
|
-
|
53
|
+
from huggingface_hub import snapshot_download
|
25
54
|
except ImportError:
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
55
|
+
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
56
|
+
if os.path.exists(checkpoint_path) and self.validate_download(
|
57
|
+
checkpoint_path, allowed_file_patterns, ignore_file_patterns
|
58
|
+
):
|
59
|
+
logger.info("Checkpoints already exist")
|
60
|
+
return True
|
61
|
+
else:
|
62
|
+
os.makedirs(checkpoint_path, exist_ok=True)
|
63
|
+
try:
|
64
|
+
is_hf_model_exists = self.validate_hf_model()
|
65
|
+
if not is_hf_model_exists:
|
66
|
+
logger.error("Model %s not found on Hugging Face" % (self.repo_id))
|
67
|
+
return False
|
68
|
+
|
69
|
+
self.ignore_patterns = self._get_ignore_patterns()
|
70
|
+
if ignore_file_patterns:
|
71
|
+
if self.ignore_patterns:
|
72
|
+
self.ignore_patterns.extend(ignore_file_patterns)
|
73
|
+
else:
|
74
|
+
self.ignore_patterns = ignore_file_patterns
|
75
|
+
snapshot_download(
|
76
|
+
repo_id=self.repo_id,
|
77
|
+
local_dir=checkpoint_path,
|
78
|
+
local_dir_use_symlinks=False,
|
79
|
+
allow_patterns=allowed_file_patterns,
|
80
|
+
ignore_patterns=self.ignore_patterns,
|
81
|
+
)
|
82
|
+
# Remove the `.cache` folder if it exists
|
83
|
+
cache_path = os.path.join(checkpoint_path, ".cache")
|
84
|
+
if os.path.exists(cache_path) and os.path.isdir(cache_path):
|
85
|
+
shutil.rmtree(cache_path)
|
86
|
+
|
87
|
+
except Exception as e:
|
88
|
+
logger.error(f"Error downloading model checkpoints {e}")
|
89
|
+
return False
|
90
|
+
finally:
|
91
|
+
is_downloaded = self.validate_download(
|
92
|
+
checkpoint_path, allowed_file_patterns, ignore_file_patterns
|
93
|
+
)
|
94
|
+
if not is_downloaded:
|
95
|
+
logger.error("Error validating downloaded model checkpoints")
|
96
|
+
return False
|
97
|
+
return True
|
98
|
+
|
99
|
+
def download_config(self, checkpoint_path: str):
|
100
|
+
# throw error if huggingface_hub wasn't installed
|
101
|
+
try:
|
102
|
+
from huggingface_hub import hf_hub_download
|
103
|
+
except ImportError:
|
104
|
+
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
105
|
+
if os.path.exists(checkpoint_path) and os.path.exists(
|
106
|
+
os.path.join(checkpoint_path, 'config.json')
|
107
|
+
):
|
108
|
+
logger.info("HF model's config.json already exists")
|
109
|
+
return True
|
110
|
+
os.makedirs(checkpoint_path, exist_ok=True)
|
111
|
+
try:
|
112
|
+
is_hf_model_exists = self.validate_hf_model()
|
113
|
+
if not is_hf_model_exists:
|
114
|
+
logger.error("Model %s not found on Hugging Face" % (self.repo_id))
|
115
|
+
return False
|
116
|
+
hf_hub_download(
|
117
|
+
repo_id=self.repo_id, filename='config.json', local_dir=checkpoint_path
|
118
|
+
)
|
119
|
+
except Exception as e:
|
120
|
+
logger.error(f"Error downloading model's config.json {e}")
|
121
|
+
return False
|
122
|
+
return True
|
123
|
+
|
124
|
+
def validate_hf_model(
|
125
|
+
self,
|
126
|
+
):
|
127
|
+
# check if model exists on HF
|
128
|
+
try:
|
129
|
+
from huggingface_hub import file_exists, repo_exists
|
130
|
+
except ImportError:
|
131
|
+
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
132
|
+
if self.clarifai_model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE:
|
133
|
+
return repo_exists(self.repo_id) and file_exists(self.repo_id, 'config.json')
|
134
|
+
else:
|
135
|
+
return repo_exists(self.repo_id)
|
136
|
+
|
137
|
+
def validate_download(
|
138
|
+
self, checkpoint_path: str, allowed_file_patterns: list, ignore_file_patterns: list
|
139
|
+
):
|
140
|
+
# check if model exists on HF
|
141
|
+
try:
|
142
|
+
from huggingface_hub import list_repo_files
|
143
|
+
except ImportError:
|
144
|
+
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
145
|
+
# Get the list of files on the repo
|
146
|
+
repo_files = list_repo_files(self.repo_id, token=self.token)
|
147
|
+
|
148
|
+
# Get the list of files on the repo that are allowed
|
149
|
+
if allowed_file_patterns:
|
150
|
+
|
151
|
+
def should_allow(file_path):
|
152
|
+
return any(
|
153
|
+
fnmatch.fnmatch(file_path, pattern) for pattern in allowed_file_patterns
|
154
|
+
)
|
155
|
+
|
156
|
+
repo_files = [f for f in repo_files if should_allow(f)]
|
68
157
|
|
69
158
|
self.ignore_patterns = self._get_ignore_patterns()
|
70
159
|
if ignore_file_patterns:
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
160
|
+
if self.ignore_patterns:
|
161
|
+
self.ignore_patterns.extend(ignore_file_patterns)
|
162
|
+
else:
|
163
|
+
self.ignore_patterns = ignore_file_patterns
|
164
|
+
# Get the list of files on the repo that are not ignored
|
165
|
+
if getattr(self, "ignore_patterns", None):
|
166
|
+
patterns = self.ignore_patterns
|
167
|
+
|
168
|
+
def should_ignore(file_path):
|
169
|
+
return any(fnmatch.fnmatch(file_path, pattern) for pattern in patterns)
|
170
|
+
|
171
|
+
repo_files = [f for f in repo_files if not should_ignore(f)]
|
172
|
+
|
173
|
+
# Check if downloaded files match the files we expect (ignoring ignored patterns)
|
174
|
+
checkpoint_dir_files = []
|
175
|
+
for dp, dn, fn in os.walk(os.path.expanduser(checkpoint_path)):
|
176
|
+
checkpoint_dir_files.extend(
|
177
|
+
[os.path.relpath(os.path.join(dp, f), checkpoint_path) for f in fn]
|
178
|
+
)
|
179
|
+
|
180
|
+
# Validate by comparing file lists
|
181
|
+
return (
|
182
|
+
len(checkpoint_dir_files) >= len(repo_files)
|
183
|
+
and not (len(set(repo_files) - set(checkpoint_dir_files)) > 0)
|
184
|
+
and len(repo_files) > 0
|
185
|
+
)
|
186
|
+
|
187
|
+
def _get_ignore_patterns(self):
|
188
|
+
# check if model exists on HF
|
189
|
+
try:
|
190
|
+
from huggingface_hub import list_repo_files
|
191
|
+
except ImportError:
|
192
|
+
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
193
|
+
|
194
|
+
# Get the list of files on the repo that are not ignored
|
195
|
+
repo_files = list_repo_files(self.repo_id, token=self.token)
|
196
|
+
self.ignore_patterns = None
|
197
|
+
if any(f.endswith(".safetensors") for f in repo_files):
|
198
|
+
self.ignore_patterns = [
|
199
|
+
"**/original/*",
|
200
|
+
"**/*.pth",
|
201
|
+
"**/*.bin",
|
202
|
+
"*.pth",
|
203
|
+
"*.bin",
|
204
|
+
"**/.cache/*",
|
205
|
+
]
|
206
|
+
return self.ignore_patterns
|
207
|
+
|
208
|
+
@staticmethod
|
209
|
+
def validate_config(checkpoint_path: str):
|
210
|
+
# check if downloaded config.json exists
|
211
|
+
return os.path.exists(checkpoint_path) and os.path.exists(
|
212
|
+
os.path.join(checkpoint_path, 'config.json')
|
213
|
+
)
|
214
|
+
|
215
|
+
@staticmethod
|
216
|
+
def validate_concept(checkpoint_path: str):
|
217
|
+
# check if downloaded concept exists in hf model
|
218
|
+
config_path = os.path.join(checkpoint_path, 'config.json')
|
219
|
+
with open(config_path, 'r') as f:
|
220
|
+
config = json.load(f)
|
221
|
+
|
222
|
+
labels = config.get('id2label', None)
|
223
|
+
if labels:
|
224
|
+
return True
|
112
225
|
return False
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
# Get the list of files on the repo that are not ignored
|
155
|
-
if getattr(self, "ignore_patterns", None):
|
156
|
-
patterns = self.ignore_patterns
|
157
|
-
|
158
|
-
def should_ignore(file_path):
|
159
|
-
return any(fnmatch.fnmatch(file_path, pattern) for pattern in patterns)
|
160
|
-
|
161
|
-
repo_files = [f for f in repo_files if not should_ignore(f)]
|
162
|
-
|
163
|
-
# Check if downloaded files match the files we expect (ignoring ignored patterns)
|
164
|
-
checkpoint_dir_files = []
|
165
|
-
for dp, dn, fn in os.walk(os.path.expanduser(checkpoint_path)):
|
166
|
-
checkpoint_dir_files.extend(
|
167
|
-
[os.path.relpath(os.path.join(dp, f), checkpoint_path) for f in fn])
|
168
|
-
|
169
|
-
# Validate by comparing file lists
|
170
|
-
return len(checkpoint_dir_files) >= len(repo_files) and not (
|
171
|
-
len(set(repo_files) - set(checkpoint_dir_files)) > 0) and len(repo_files) > 0
|
172
|
-
|
173
|
-
def _get_ignore_patterns(self):
|
174
|
-
# check if model exists on HF
|
175
|
-
try:
|
176
|
-
from huggingface_hub import list_repo_files
|
177
|
-
except ImportError:
|
178
|
-
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
179
|
-
|
180
|
-
# Get the list of files on the repo that are not ignored
|
181
|
-
repo_files = list_repo_files(self.repo_id, token=self.token)
|
182
|
-
self.ignore_patterns = None
|
183
|
-
if any(f.endswith(".safetensors") for f in repo_files):
|
184
|
-
self.ignore_patterns = [
|
185
|
-
"**/original/*", "**/*.pth", "**/*.bin", "*.pth", "*.bin", "**/.cache/*"
|
186
|
-
]
|
187
|
-
return self.ignore_patterns
|
188
|
-
|
189
|
-
@staticmethod
|
190
|
-
def validate_config(checkpoint_path: str):
|
191
|
-
# check if downloaded config.json exists
|
192
|
-
return os.path.exists(checkpoint_path) and os.path.exists(
|
193
|
-
os.path.join(checkpoint_path, 'config.json'))
|
194
|
-
|
195
|
-
@staticmethod
|
196
|
-
def validate_concept(checkpoint_path: str):
|
197
|
-
# check if downloaded concept exists in hf model
|
198
|
-
config_path = os.path.join(checkpoint_path, 'config.json')
|
199
|
-
with open(config_path, 'r') as f:
|
200
|
-
config = json.load(f)
|
201
|
-
|
202
|
-
labels = config.get('id2label', None)
|
203
|
-
if labels:
|
204
|
-
return True
|
205
|
-
return False
|
206
|
-
|
207
|
-
@staticmethod
|
208
|
-
def fetch_labels(checkpoint_path: str):
|
209
|
-
# Fetch labels for classification, detection and segmentation models
|
210
|
-
config_path = os.path.join(checkpoint_path, 'config.json')
|
211
|
-
with open(config_path, 'r') as f:
|
212
|
-
config = json.load(f)
|
213
|
-
|
214
|
-
labels = config['id2label']
|
215
|
-
return labels
|
216
|
-
|
217
|
-
@staticmethod
|
218
|
-
def get_huggingface_checkpoint_total_size(repo_name):
|
219
|
-
"""
|
220
|
-
Fetches the JSON data for a Hugging Face model using the API with `?blobs=true`.
|
221
|
-
Calculates the total size from the JSON output.
|
222
|
-
|
223
|
-
Args:
|
224
|
-
repo_name (str): The name of the model on Hugging Face Hub. e.g. "casperhansen/llama-3-8b-instruct-awq"
|
225
|
-
|
226
|
-
Returns:
|
227
|
-
int: The total size in bytes.
|
228
|
-
"""
|
229
|
-
try:
|
230
|
-
url = f"https://huggingface.co/api/models/{repo_name}?blobs=true"
|
231
|
-
response = requests.get(url)
|
232
|
-
response.raise_for_status() # Raise an exception for bad status codes
|
233
|
-
json_data = response.json()
|
234
|
-
|
235
|
-
if isinstance(json_data, str):
|
236
|
-
data = json.loads(json_data)
|
237
|
-
else:
|
238
|
-
data = json_data
|
239
|
-
|
240
|
-
total_size = 0
|
241
|
-
for file in data['siblings']:
|
242
|
-
total_size += file['size']
|
243
|
-
return total_size
|
244
|
-
except Exception as e:
|
245
|
-
logger.error(f"Error fetching checkpoint size from huggingface.co: {e}")
|
246
|
-
return 0
|
226
|
+
|
227
|
+
@staticmethod
|
228
|
+
def fetch_labels(checkpoint_path: str):
|
229
|
+
# Fetch labels for classification, detection and segmentation models
|
230
|
+
config_path = os.path.join(checkpoint_path, 'config.json')
|
231
|
+
with open(config_path, 'r') as f:
|
232
|
+
config = json.load(f)
|
233
|
+
|
234
|
+
labels = config['id2label']
|
235
|
+
return labels
|
236
|
+
|
237
|
+
@staticmethod
|
238
|
+
def get_huggingface_checkpoint_total_size(repo_name):
|
239
|
+
"""
|
240
|
+
Fetches the JSON data for a Hugging Face model using the API with `?blobs=true`.
|
241
|
+
Calculates the total size from the JSON output.
|
242
|
+
|
243
|
+
Args:
|
244
|
+
repo_name (str): The name of the model on Hugging Face Hub. e.g. "casperhansen/llama-3-8b-instruct-awq"
|
245
|
+
|
246
|
+
Returns:
|
247
|
+
int: The total size in bytes.
|
248
|
+
"""
|
249
|
+
try:
|
250
|
+
url = f"https://huggingface.co/api/models/{repo_name}?blobs=true"
|
251
|
+
response = requests.get(url)
|
252
|
+
response.raise_for_status() # Raise an exception for bad status codes
|
253
|
+
json_data = response.json()
|
254
|
+
|
255
|
+
if isinstance(json_data, str):
|
256
|
+
data = json.loads(json_data)
|
257
|
+
else:
|
258
|
+
data = json_data
|
259
|
+
|
260
|
+
total_size = 0
|
261
|
+
for file in data['siblings']:
|
262
|
+
total_size += file['size']
|
263
|
+
return total_size
|
264
|
+
except Exception as e:
|
265
|
+
logger.error(f"Error fetching checkpoint size from huggingface.co: {e}")
|
266
|
+
return 0
|