clarifai 11.2.1__py3-none-any.whl → 11.2.2__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/client/app.py +1 -1
- clarifai/runners/models/model_builder.py +21 -8
- clarifai/runners/models/model_run_locally.py +1 -1
- clarifai/runners/utils/loader.py +36 -6
- {clarifai-11.2.1.dist-info → clarifai-11.2.2.dist-info}/METADATA +1 -1
- {clarifai-11.2.1.dist-info → clarifai-11.2.2.dist-info}/RECORD +11 -11
- {clarifai-11.2.1.dist-info → clarifai-11.2.2.dist-info}/WHEEL +1 -1
- {clarifai-11.2.1.dist-info → clarifai-11.2.2.dist-info}/entry_points.txt +0 -0
- {clarifai-11.2.1.dist-info → clarifai-11.2.2.dist-info}/licenses/LICENSE +0 -0
- {clarifai-11.2.1.dist-info → clarifai-11.2.2.dist-info}/top_level.txt +0 -0
clarifai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "11.2.
|
1
|
+
__version__ = "11.2.2"
|
clarifai/client/app.py
CHANGED
@@ -629,7 +629,7 @@ class App(Lister, BaseClient):
|
|
629
629
|
|
630
630
|
Args:
|
631
631
|
model_id (str): The model ID for the model to interact with.
|
632
|
-
|
632
|
+
model_version (Dict): The model version ID for the model version to interact with.
|
633
633
|
|
634
634
|
Returns:
|
635
635
|
Model: A Model object for the existing model ID.
|
@@ -171,7 +171,14 @@ class ModelBuilder:
|
|
171
171
|
|
172
172
|
# get from config.yaml otherwise fall back to HF_TOKEN env var.
|
173
173
|
hf_token = self.config.get("checkpoints").get("hf_token", os.environ.get("HF_TOKEN", None))
|
174
|
-
|
174
|
+
|
175
|
+
allowed_file_patterns = self.config.get("checkpoints").get('allowed_file_patterns', None)
|
176
|
+
if isinstance(allowed_file_patterns, str):
|
177
|
+
allowed_file_patterns = [allowed_file_patterns]
|
178
|
+
ignore_file_patterns = self.config.get("checkpoints").get('ignore_file_patterns', None)
|
179
|
+
if isinstance(ignore_file_patterns, str):
|
180
|
+
ignore_file_patterns = [ignore_file_patterns]
|
181
|
+
return loader_type, repo_id, hf_token, when, allowed_file_patterns, ignore_file_patterns
|
175
182
|
|
176
183
|
def _check_app_exists(self):
|
177
184
|
resp = self.client.STUB.GetApp(service_pb2.GetAppRequest(user_app_id=self.client.user_app_id))
|
@@ -216,7 +223,7 @@ class ModelBuilder:
|
|
216
223
|
assert model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE, f"Model type {model_type_id} not supported for concepts"
|
217
224
|
|
218
225
|
if self.config.get("checkpoints"):
|
219
|
-
loader_type, _, hf_token, _ = self._validate_config_checkpoints()
|
226
|
+
loader_type, _, hf_token, _, _, _ = self._validate_config_checkpoints()
|
220
227
|
|
221
228
|
if loader_type == "huggingface" and hf_token:
|
222
229
|
is_valid_token = HuggingFaceLoader.validate_hftoken(hf_token)
|
@@ -480,8 +487,10 @@ class ModelBuilder:
|
|
480
487
|
if not self.config.get("checkpoints"):
|
481
488
|
logger.info("No checkpoints specified in the config file")
|
482
489
|
return path
|
490
|
+
clarifai_model_type_id = self.config.get('model').get('model_type_id')
|
483
491
|
|
484
|
-
loader_type, repo_id, hf_token, when = self._validate_config_checkpoints(
|
492
|
+
loader_type, repo_id, hf_token, when, allowed_file_patterns, ignore_file_patterns = self._validate_config_checkpoints(
|
493
|
+
)
|
485
494
|
if stage not in ["build", "upload", "runtime"]:
|
486
495
|
raise Exception("Invalid stage provided, must be one of ['build', 'upload', 'runtime']")
|
487
496
|
if when != stage:
|
@@ -490,14 +499,18 @@ class ModelBuilder:
|
|
490
499
|
)
|
491
500
|
return path
|
492
501
|
|
493
|
-
success =
|
502
|
+
success = False
|
494
503
|
if loader_type == "huggingface":
|
495
|
-
loader = HuggingFaceLoader(
|
504
|
+
loader = HuggingFaceLoader(
|
505
|
+
repo_id=repo_id, token=hf_token, model_type_id=clarifai_model_type_id)
|
496
506
|
# for runtime default to /tmp path
|
497
507
|
if stage == "runtime" and checkpoint_path_override is None:
|
498
508
|
checkpoint_path_override = self.default_runtime_checkpoint_path()
|
499
509
|
path = checkpoint_path_override if checkpoint_path_override else self.checkpoint_path
|
500
|
-
success = loader.download_checkpoints(
|
510
|
+
success = loader.download_checkpoints(
|
511
|
+
path,
|
512
|
+
allowed_file_patterns=allowed_file_patterns,
|
513
|
+
ignore_file_patterns=ignore_file_patterns)
|
501
514
|
|
502
515
|
if loader_type:
|
503
516
|
if not success:
|
@@ -569,7 +582,7 @@ class ModelBuilder:
|
|
569
582
|
logger.debug(f"Will tar it into file: {file_path}")
|
570
583
|
|
571
584
|
model_type_id = self.config.get('model').get('model_type_id')
|
572
|
-
loader_type, repo_id, hf_token, when = self._validate_config_checkpoints()
|
585
|
+
loader_type, repo_id, hf_token, when, _, _ = self._validate_config_checkpoints()
|
573
586
|
|
574
587
|
if (model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE) and 'concepts' not in self.config:
|
575
588
|
logger.info(
|
@@ -617,7 +630,7 @@ class ModelBuilder:
|
|
617
630
|
# First check for the env variable, then try querying huggingface. If all else fails, use the default.
|
618
631
|
checkpoint_size = os.environ.get('CHECKPOINT_SIZE_BYTES', 0)
|
619
632
|
if not checkpoint_size:
|
620
|
-
_, repo_id, _, _ = self._validate_config_checkpoints()
|
633
|
+
_, repo_id, _, _, _, _ = self._validate_config_checkpoints()
|
621
634
|
checkpoint_size = HuggingFaceLoader.get_huggingface_checkpoint_total_size(repo_id)
|
622
635
|
if not checkpoint_size:
|
623
636
|
checkpoint_size = self.DEFAULT_CHECKPOINT_SIZE
|
@@ -479,7 +479,7 @@ def main(model_path,
|
|
479
479
|
manager = ModelRunLocally(model_path)
|
480
480
|
# get whatever stage is in config.yaml to force download now
|
481
481
|
# also always write to where upload/build wants to, not the /tmp folder that runtime stage uses
|
482
|
-
_, _, _, when = manager.builder._validate_config_checkpoints()
|
482
|
+
_, _, _, when, _, _ = manager.builder._validate_config_checkpoints()
|
483
483
|
manager.builder.download_checkpoints(
|
484
484
|
stage=when, checkpoint_path_override=manager.builder.checkpoint_path)
|
485
485
|
if inside_container:
|
clarifai/runners/utils/loader.py
CHANGED
@@ -6,6 +6,7 @@ import shutil
|
|
6
6
|
|
7
7
|
import requests
|
8
8
|
|
9
|
+
from clarifai.runners.utils.const import CONCEPTS_REQUIRED_MODEL_TYPE
|
9
10
|
from clarifai.utils.logging import logger
|
10
11
|
|
11
12
|
|
@@ -13,9 +14,10 @@ class HuggingFaceLoader:
|
|
13
14
|
|
14
15
|
HF_DOWNLOAD_TEXT = "The 'huggingface_hub' package is not installed. Please install it using 'pip install huggingface_hub'."
|
15
16
|
|
16
|
-
def __init__(self, repo_id=None, token=None):
|
17
|
+
def __init__(self, repo_id=None, token=None, model_type_id=None):
|
17
18
|
self.repo_id = repo_id
|
18
19
|
self.token = token
|
20
|
+
self.clarifai_model_type_id = model_type_id
|
19
21
|
if token:
|
20
22
|
if self.validate_hftoken(token):
|
21
23
|
try:
|
@@ -43,13 +45,17 @@ class HuggingFaceLoader:
|
|
43
45
|
f"Error setting up Hugging Face token, please make sure you have the correct token: {e}")
|
44
46
|
return False
|
45
47
|
|
46
|
-
def download_checkpoints(self,
|
48
|
+
def download_checkpoints(self,
|
49
|
+
checkpoint_path: str,
|
50
|
+
allowed_file_patterns=None,
|
51
|
+
ignore_file_patterns=None):
|
47
52
|
# throw error if huggingface_hub wasn't installed
|
48
53
|
try:
|
49
54
|
from huggingface_hub import snapshot_download
|
50
55
|
except ImportError:
|
51
56
|
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
52
|
-
if os.path.exists(checkpoint_path) and self.validate_download(
|
57
|
+
if os.path.exists(checkpoint_path) and self.validate_download(
|
58
|
+
checkpoint_path, allowed_file_patterns, ignore_file_patterns):
|
53
59
|
logger.info("Checkpoints already exist")
|
54
60
|
return True
|
55
61
|
else:
|
@@ -61,10 +67,16 @@ class HuggingFaceLoader:
|
|
61
67
|
return False
|
62
68
|
|
63
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
|
64
75
|
snapshot_download(
|
65
76
|
repo_id=self.repo_id,
|
66
77
|
local_dir=checkpoint_path,
|
67
78
|
local_dir_use_symlinks=False,
|
79
|
+
allow_patterns=allowed_file_patterns,
|
68
80
|
ignore_patterns=self.ignore_patterns)
|
69
81
|
# Remove the `.cache` folder if it exists
|
70
82
|
cache_path = os.path.join(checkpoint_path, ".cache")
|
@@ -75,7 +87,8 @@ class HuggingFaceLoader:
|
|
75
87
|
logger.error(f"Error downloading model checkpoints {e}")
|
76
88
|
return False
|
77
89
|
finally:
|
78
|
-
is_downloaded = self.validate_download(checkpoint_path
|
90
|
+
is_downloaded = self.validate_download(checkpoint_path, allowed_file_patterns,
|
91
|
+
ignore_file_patterns)
|
79
92
|
if not is_downloaded:
|
80
93
|
logger.error("Error validating downloaded model checkpoints")
|
81
94
|
return False
|
@@ -109,9 +122,13 @@ class HuggingFaceLoader:
|
|
109
122
|
from huggingface_hub import file_exists, repo_exists
|
110
123
|
except ImportError:
|
111
124
|
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
112
|
-
|
125
|
+
if self.clarifai_model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE:
|
126
|
+
return repo_exists(self.repo_id) and file_exists(self.repo_id, 'config.json')
|
127
|
+
else:
|
128
|
+
return repo_exists(self.repo_id)
|
113
129
|
|
114
|
-
def validate_download(self, checkpoint_path: str
|
130
|
+
def validate_download(self, checkpoint_path: str, allowed_file_patterns: list,
|
131
|
+
ignore_file_patterns: list):
|
115
132
|
# check if model exists on HF
|
116
133
|
try:
|
117
134
|
from huggingface_hub import list_repo_files
|
@@ -120,7 +137,20 @@ class HuggingFaceLoader:
|
|
120
137
|
# Get the list of files on the repo
|
121
138
|
repo_files = list_repo_files(self.repo_id, token=self.token)
|
122
139
|
|
140
|
+
# Get the list of files on the repo that are allowed
|
141
|
+
if allowed_file_patterns:
|
142
|
+
|
143
|
+
def should_allow(file_path):
|
144
|
+
return any(fnmatch.fnmatch(file_path, pattern) for pattern in allowed_file_patterns)
|
145
|
+
|
146
|
+
repo_files = [f for f in repo_files if should_allow(f)]
|
147
|
+
|
123
148
|
self.ignore_patterns = self._get_ignore_patterns()
|
149
|
+
if ignore_file_patterns:
|
150
|
+
if self.ignore_patterns:
|
151
|
+
self.ignore_patterns.extend(ignore_file_patterns)
|
152
|
+
else:
|
153
|
+
self.ignore_patterns = ignore_file_patterns
|
124
154
|
# Get the list of files on the repo that are not ignored
|
125
155
|
if getattr(self, "ignore_patterns", None):
|
126
156
|
patterns = self.ignore_patterns
|
@@ -1,4 +1,4 @@
|
|
1
|
-
clarifai/__init__.py,sha256=
|
1
|
+
clarifai/__init__.py,sha256=_cDM_DxpY5KiS6333RgrXKdnvdwjkQID_vppBsYvGPM,23
|
2
2
|
clarifai/cli.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
3
3
|
clarifai/errors.py,sha256=RwzTajwds51wLD0MVlMC5kcpBnzRpreDLlazPSBZxrg,2605
|
4
4
|
clarifai/versions.py,sha256=jctnczzfGk_S3EnVqb2FjRKfSREkNmvNEwAAa_VoKiQ,222
|
@@ -11,7 +11,7 @@ clarifai/cli/deployment.py,sha256=Vv92Qo7Q3UmMiCdrGQ4qNVNVzfcDyl-GB6B7kx8gyFw,25
|
|
11
11
|
clarifai/cli/model.py,sha256=PR-A7V3D78iAjNx2hNeputiWuIyINrx2SJmjKtfMoQ4,12079
|
12
12
|
clarifai/cli/nodepool.py,sha256=eYo3l9NMSwjeFzsuwKSYVkR1FdZ7_NcCdNvzGsBBMzY,3139
|
13
13
|
clarifai/client/__init__.py,sha256=xI1U0l5AZdRThvQAXCLsd9axxyFzXXJ22m8LHqVjQRU,662
|
14
|
-
clarifai/client/app.py,sha256=
|
14
|
+
clarifai/client/app.py,sha256=FnKvKksYZwdry0e4Obh-trdSO1mv6QcVAa3kzKiQMpU,38340
|
15
15
|
clarifai/client/base.py,sha256=hSHOqkXbSKyaRDeylMMnkhUHCAHhEqno4KI0CXGziBA,7536
|
16
16
|
clarifai/client/compute_cluster.py,sha256=EvW9TJjPvInUlggfg1A98sxoWH8_PY5rCVXZhsj6ac0,8705
|
17
17
|
clarifai/client/dataset.py,sha256=y3zKT_VhP1gyN3OO-b3cPeW21ZXyKbQ7ZJkEG06bsTU,32096
|
@@ -66,16 +66,16 @@ clarifai/runners/server.py,sha256=xHDLdhQApCgYG19QOKXqJNCGNyw1Vsvobq3UdryDrVc,41
|
|
66
66
|
clarifai/runners/dockerfile_template/Dockerfile.template,sha256=5cjv7U8PmWa3DB_5B1CqSYh_6GE0E0np52TIAa7EIDE,2312
|
67
67
|
clarifai/runners/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
68
68
|
clarifai/runners/models/base_typed_model.py,sha256=0QCWxch8CcyJSKvE1D4PILd2RSnQZHTmx4DXlQQ6dpo,7856
|
69
|
-
clarifai/runners/models/model_builder.py,sha256=
|
69
|
+
clarifai/runners/models/model_builder.py,sha256=NAZiOm2ok-ThQ-jcAyBTRRCFufmyxGY76vlkLMpYHq4,33320
|
70
70
|
clarifai/runners/models/model_class.py,sha256=9JSPAr4U4K7xI0kSl-q0mHB06zknm2OR-8XIgBCto94,1611
|
71
|
-
clarifai/runners/models/model_run_locally.py,sha256=
|
71
|
+
clarifai/runners/models/model_run_locally.py,sha256=jz4ZvRj0eMCEziV3X37wH2AEe3Gl9Icx7Quy1ymaDe0,20556
|
72
72
|
clarifai/runners/models/model_runner.py,sha256=PyxwK-33hLlhkD07tTXkjWZ_iNlZHl9_8AZ2W7WfExI,6097
|
73
73
|
clarifai/runners/models/model_servicer.py,sha256=jtQmtGeQlvQ5ttMvVw7CMnNzq-rLkTaxR2IWF9SnHwk,2808
|
74
74
|
clarifai/runners/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
75
75
|
clarifai/runners/utils/const.py,sha256=bwj-Pcw558-pasdIFbNhnkn-9oiCdojYH1fNTTUG2gU,1048
|
76
76
|
clarifai/runners/utils/data_handler.py,sha256=sxy9zlAgI6ETuxCQhUgEXAn2GCsaW1GxpK6GTaMne0g,6966
|
77
77
|
clarifai/runners/utils/data_utils.py,sha256=R1iQ82TuQ9JwxCJk8yEB1Lyb0BYVhVbWJI9YDi1zGOs,318
|
78
|
-
clarifai/runners/utils/loader.py,sha256=
|
78
|
+
clarifai/runners/utils/loader.py,sha256=Sl0m29RDtMPx2cIiSbbDFtKHQj2ktXQ5CnkvaHi-zDc,8804
|
79
79
|
clarifai/runners/utils/url_fetcher.py,sha256=v_8JOWmkyFAzsBulsieKX7Nfjy1Yg7wGSZeqfEvw2cg,1640
|
80
80
|
clarifai/schema/search.py,sha256=JjTi8ammJgZZ2OGl4K6tIA4zEJ1Fr2ASZARXavI1j5c,2448
|
81
81
|
clarifai/urls/helper.py,sha256=tjoMGGHuWX68DUB0pk4MEjrmFsClUAQj2jmVEM_Sy78,4751
|
@@ -93,9 +93,9 @@ clarifai/workflows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
|
|
93
93
|
clarifai/workflows/export.py,sha256=vICRhIreqDSShxLKjHNM2JwzKsf1B4fdXB0ciMcA70k,1945
|
94
94
|
clarifai/workflows/utils.py,sha256=nGeB_yjVgUO9kOeKTg4OBBaBz-AwXI3m-huSVj-9W18,1924
|
95
95
|
clarifai/workflows/validate.py,sha256=yJq03MaJqi5AK3alKGJJBR89xmmjAQ31sVufJUiOqY8,2556
|
96
|
-
clarifai-11.2.
|
97
|
-
clarifai-11.2.
|
98
|
-
clarifai-11.2.
|
99
|
-
clarifai-11.2.
|
100
|
-
clarifai-11.2.
|
101
|
-
clarifai-11.2.
|
96
|
+
clarifai-11.2.2.dist-info/licenses/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
|
97
|
+
clarifai-11.2.2.dist-info/METADATA,sha256=mWqPwNuC1LdGkPWUu5ugnqADyHzcwR18PA66roRCPj4,22472
|
98
|
+
clarifai-11.2.2.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
99
|
+
clarifai-11.2.2.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
|
100
|
+
clarifai-11.2.2.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
|
101
|
+
clarifai-11.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|