clarifai 10.11.2rc1__py3-none-any.whl → 10.11.2rc3__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/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/model_upload.py +19 -18
- clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
- clarifai/runners/utils/loader.py +42 -9
- {clarifai-10.11.2rc1.dist-info → clarifai-10.11.2rc3.dist-info}/METADATA +1 -1
- {clarifai-10.11.2rc1.dist-info → clarifai-10.11.2rc3.dist-info}/RECORD +11 -11
- {clarifai-10.11.2rc1.dist-info → clarifai-10.11.2rc3.dist-info}/LICENSE +0 -0
- {clarifai-10.11.2rc1.dist-info → clarifai-10.11.2rc3.dist-info}/WHEEL +0 -0
- {clarifai-10.11.2rc1.dist-info → clarifai-10.11.2rc3.dist-info}/entry_points.txt +0 -0
- {clarifai-10.11.2rc1.dist-info → clarifai-10.11.2rc3.dist-info}/top_level.txt +0 -0
clarifai/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "10.11.
|
1
|
+
__version__ = "10.11.2rc3"
|
Binary file
|
@@ -29,16 +29,19 @@ def _clear_line(n: int = 1) -> None:
|
|
29
29
|
|
30
30
|
class ModelUploader:
|
31
31
|
|
32
|
-
def __init__(self, folder: str, validate_api_ids: bool = True):
|
32
|
+
def __init__(self, folder: str, validate_api_ids: bool = True, download_validation_only=False):
|
33
33
|
"""
|
34
34
|
:param folder: The folder containing the model.py, config.yaml, requirements.txt and
|
35
35
|
checkpoints.
|
36
|
-
:param validate_api_ids: Whether to validate the user_id and app_id in the config file.
|
36
|
+
:param validate_api_ids: Whether to validate the user_id and app_id in the config file. TODO:
|
37
|
+
deprecate in favor of download_validation_only.
|
38
|
+
:param download_validation_only: Whether to skip the API config validation. Set to True if
|
39
|
+
just downloading a checkpoint.
|
37
40
|
"""
|
38
41
|
self._client = None
|
42
|
+
self.download_validation_only = download_validation_only
|
39
43
|
self.folder = self._validate_folder(folder)
|
40
44
|
self.config = self._load_config(os.path.join(self.folder, 'config.yaml'))
|
41
|
-
self.validate_api_ids = validate_api_ids
|
42
45
|
self._validate_config()
|
43
46
|
self.model_proto = self._get_model_proto()
|
44
47
|
self.model_id = self.model_proto.id
|
@@ -46,19 +49,21 @@ class ModelUploader:
|
|
46
49
|
self.inference_compute_info = self._get_inference_compute_info()
|
47
50
|
self.is_v3 = True # Do model build for v3
|
48
51
|
|
49
|
-
|
50
|
-
def _validate_folder(folder):
|
52
|
+
def _validate_folder(self, folder):
|
51
53
|
if not folder.startswith("/"):
|
52
54
|
folder = os.path.join(os.getcwd(), folder)
|
53
55
|
logger.info(f"Validating folder: {folder}")
|
54
56
|
if not os.path.exists(folder):
|
55
57
|
raise FileNotFoundError(f"Folder {folder} not found, please provide a valid folder path")
|
56
58
|
files = os.listdir(folder)
|
57
|
-
assert "requirements.txt" in files, "requirements.txt not found in the folder"
|
58
59
|
assert "config.yaml" in files, "config.yaml not found in the folder"
|
60
|
+
# If just downloading we don't need requirements.txt or the python code, we do need the
|
61
|
+
# 1/ folder to put 1/checkpoints into.
|
59
62
|
assert "1" in files, "Subfolder '1' not found in the folder"
|
60
|
-
|
61
|
-
|
63
|
+
if not self.download_validation_only:
|
64
|
+
assert "requirements.txt" in files, "requirements.txt not found in the folder"
|
65
|
+
subfolder_files = os.listdir(os.path.join(folder, '1'))
|
66
|
+
assert 'model.py' in subfolder_files, "model.py not found in the folder"
|
62
67
|
return folder
|
63
68
|
|
64
69
|
@staticmethod
|
@@ -83,8 +88,6 @@ class ModelUploader:
|
|
83
88
|
return repo_id, hf_token
|
84
89
|
|
85
90
|
def _check_app_exists(self):
|
86
|
-
if not self.validate_api_ids:
|
87
|
-
return True
|
88
91
|
resp = self.client.STUB.GetApp(service_pb2.GetAppRequest(user_app_id=self.client.user_app_id))
|
89
92
|
if resp.status.code == status_code_pb2.SUCCESS:
|
90
93
|
return True
|
@@ -114,16 +117,14 @@ class ModelUploader:
|
|
114
117
|
sys.exit(1)
|
115
118
|
|
116
119
|
def _validate_config(self):
|
117
|
-
self.
|
118
|
-
|
119
|
-
if self.config.get("checkpoints"):
|
120
|
-
self._validate_config_checkpoints()
|
120
|
+
if not self.download_validation_only:
|
121
|
+
self._validate_config_model()
|
121
122
|
|
122
|
-
|
123
|
+
assert "inference_compute_info" in self.config, "inference_compute_info not found in the config file"
|
123
124
|
|
124
|
-
|
125
|
-
|
126
|
-
|
125
|
+
if self.config.get("concepts"):
|
126
|
+
model_type_id = self.config.get('model').get('model_type_id')
|
127
|
+
assert model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE, f"Model type {model_type_id} not supported for concepts"
|
127
128
|
|
128
129
|
if self.config.get("checkpoints"):
|
129
130
|
_, hf_token = self._validate_config_checkpoints()
|
Binary file
|
clarifai/runners/utils/loader.py
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
+
import fnmatch
|
1
2
|
import importlib.util
|
2
3
|
import json
|
3
4
|
import os
|
5
|
+
import shutil
|
4
6
|
import subprocess
|
5
7
|
|
6
8
|
from clarifai.utils.logging import logger
|
@@ -39,7 +41,7 @@ class HuggingFaceLoader:
|
|
39
41
|
def download_checkpoints(self, checkpoint_path: str):
|
40
42
|
# throw error if huggingface_hub wasn't installed
|
41
43
|
try:
|
42
|
-
from huggingface_hub import
|
44
|
+
from huggingface_hub import snapshot_download
|
43
45
|
except ImportError:
|
44
46
|
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
45
47
|
if os.path.exists(checkpoint_path) and self.validate_download(checkpoint_path):
|
@@ -53,16 +55,17 @@ class HuggingFaceLoader:
|
|
53
55
|
logger.error("Model %s not found on Hugging Face" % (self.repo_id))
|
54
56
|
return False
|
55
57
|
|
56
|
-
ignore_patterns =
|
57
|
-
repo_files = list_repo_files(repo_id=self.repo_id, token=self.token)
|
58
|
-
if any(f.endswith(".safetensors") for f in repo_files):
|
59
|
-
logger.info(f"SafeTensors found in {self.repo_id}, downloading only .safetensors files.")
|
60
|
-
ignore_patterns = ["**/original/*", "**/*.pth", "**/*.bin"]
|
58
|
+
self.ignore_patterns = self._get_ignore_patterns()
|
61
59
|
snapshot_download(
|
62
60
|
repo_id=self.repo_id,
|
63
61
|
local_dir=checkpoint_path,
|
64
62
|
local_dir_use_symlinks=False,
|
65
|
-
ignore_patterns=ignore_patterns)
|
63
|
+
ignore_patterns=self.ignore_patterns)
|
64
|
+
# Remove the `.cache` folder if it exists
|
65
|
+
cache_path = os.path.join(checkpoint_path, ".cache")
|
66
|
+
if os.path.exists(cache_path) and os.path.isdir(cache_path):
|
67
|
+
shutil.rmtree(cache_path)
|
68
|
+
|
66
69
|
except Exception as e:
|
67
70
|
logger.error(f"Error downloading model checkpoints {e}")
|
68
71
|
return False
|
@@ -109,11 +112,41 @@ class HuggingFaceLoader:
|
|
109
112
|
from huggingface_hub import list_repo_files
|
110
113
|
except ImportError:
|
111
114
|
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
115
|
+
# Get the list of files on the repo
|
116
|
+
repo_files = list_repo_files(self.repo_id, token=self.token)
|
117
|
+
|
118
|
+
self.ignore_patterns = self._get_ignore_patterns()
|
119
|
+
# Get the list of files on the repo that are not ignored
|
120
|
+
if getattr(self, "ignore_patterns", None):
|
121
|
+
patterns = self.ignore_patterns
|
122
|
+
|
123
|
+
def should_ignore(file_path):
|
124
|
+
return any(fnmatch.fnmatch(file_path, pattern) for pattern in patterns)
|
125
|
+
|
126
|
+
repo_files = [f for f in repo_files if not should_ignore(f)]
|
127
|
+
|
128
|
+
# Check if downloaded files match the files we expect (ignoring ignored patterns)
|
112
129
|
checkpoint_dir_files = [
|
113
130
|
f for dp, dn, fn in os.walk(os.path.expanduser(checkpoint_path)) for f in fn
|
114
131
|
]
|
115
|
-
|
116
|
-
|
132
|
+
|
133
|
+
# Validate by comparing file lists
|
134
|
+
return len(checkpoint_dir_files) >= len(repo_files) and not (
|
135
|
+
len(set(repo_files) - set(checkpoint_dir_files)) > 0) and len(repo_files) > 0
|
136
|
+
|
137
|
+
def _get_ignore_patterns(self):
|
138
|
+
# check if model exists on HF
|
139
|
+
try:
|
140
|
+
from huggingface_hub import list_repo_files
|
141
|
+
except ImportError:
|
142
|
+
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
143
|
+
|
144
|
+
# Get the list of files on the repo that are not ignored
|
145
|
+
repo_files = list_repo_files(self.repo_id, token=self.token)
|
146
|
+
self.ignore_patterns = None
|
147
|
+
if any(f.endswith(".safetensors") for f in repo_files):
|
148
|
+
self.ignore_patterns = ["**/original/*", "**/*.pth", "**/*.bin", "*.pth", "*.bin"]
|
149
|
+
return self.ignore_patterns
|
117
150
|
|
118
151
|
@staticmethod
|
119
152
|
def validate_config(checkpoint_path: str):
|
@@ -1,4 +1,4 @@
|
|
1
|
-
clarifai/__init__.py,sha256=
|
1
|
+
clarifai/__init__.py,sha256=CeWkfe22NXjzgsoSQ84l50ZL9fR1MatZEVOZm2BBGZ4,27
|
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
|
@@ -186,26 +186,26 @@ clarifai/runners/models/model_class.py,sha256=9JSPAr4U4K7xI0kSl-q0mHB06zknm2OR-8
|
|
186
186
|
clarifai/runners/models/model_run_locally.py,sha256=OhzQbmaV8Wwgs2H0KhdDF6Z7bYSaIh4RRA0QwSiv5vY,20644
|
187
187
|
clarifai/runners/models/model_runner.py,sha256=3vzoastQxkGRDK8T9aojDsLNBb9A3IiKm6YmbFrE9S0,6241
|
188
188
|
clarifai/runners/models/model_servicer.py,sha256=X4715PVA5PBurRTYcwSEudg8fShGV6InAF4mmRlRcHg,2826
|
189
|
-
clarifai/runners/models/model_upload.py,sha256=
|
189
|
+
clarifai/runners/models/model_upload.py,sha256=L5BbODARRDBXIV8DBe9_6jT37oNQw4PuzRrwKfy37mg,23250
|
190
190
|
clarifai/runners/models/__pycache__/__init__.cpython-310.pyc,sha256=GTFjzypyx5wnDGqxYeY01iya1CELKb5fOFBFLV031yU,171
|
191
191
|
clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc,sha256=xni4ij1KhISxAia1j-Q1PDSX65tOYYjyfPlIxOxtlFs,8273
|
192
192
|
clarifai/runners/models/__pycache__/model_class.cpython-310.pyc,sha256=OxOQDH4G_XXvXCOChWLjONFVcDWdr6T00JjQvKx1AgA,1889
|
193
193
|
clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc,sha256=_vm1H_HBCwWRpl-3mVjRIVbvHDYM6-sz9OheR1BmzcE,17040
|
194
194
|
clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc,sha256=lMrT9MMO3sLTo11zSv5XYTBQte3oY23esUFV4Wdnquw,5108
|
195
195
|
clarifai/runners/models/__pycache__/model_servicer.cpython-310.pyc,sha256=w5kENnKCiiZSpZF6g7N1wljHbnan3pi_mhZBm_VvD4Q,2489
|
196
|
-
clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc,sha256=
|
196
|
+
clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc,sha256=3iBqzh3IXS42yi4fYLJTZ594G9UGYX9xXw4NItrA5sI,19274
|
197
197
|
clarifai/runners/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
198
198
|
clarifai/runners/utils/const.py,sha256=eyBrj5ywuGKPF-IFipm7yjiYyLhnsKhMNZ6xF-OvykQ,1250
|
199
199
|
clarifai/runners/utils/data_handler.py,sha256=sxy9zlAgI6ETuxCQhUgEXAn2GCsaW1GxpK6GTaMne0g,6966
|
200
200
|
clarifai/runners/utils/data_utils.py,sha256=R1iQ82TuQ9JwxCJk8yEB1Lyb0BYVhVbWJI9YDi1zGOs,318
|
201
|
-
clarifai/runners/utils/loader.py,sha256=
|
201
|
+
clarifai/runners/utils/loader.py,sha256=u4dSnOf8JcAlR2wKaWxvz4KzMfJ9oL-9orhgwtVGhJU,5975
|
202
202
|
clarifai/runners/utils/logging.py,sha256=xan5ZQH5XHVyNIIjUAQoc_bS3MrjQjEvBYuo0CQKdho,153
|
203
203
|
clarifai/runners/utils/url_fetcher.py,sha256=v_8JOWmkyFAzsBulsieKX7Nfjy1Yg7wGSZeqfEvw2cg,1640
|
204
204
|
clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc,sha256=PRPZOzUV5Z8grWizu5RKOkki0iLYxZDJBgsLfmCcieE,170
|
205
205
|
clarifai/runners/utils/__pycache__/const.cpython-310.pyc,sha256=oEBBn71Dyzuo25Rrt-UwPSUT7EAOliC1QZUYFVhW4vI,1028
|
206
206
|
clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc,sha256=YVncnM0NaHeMaZAyALxaHCdtUT6n5E3BI99-54Bs6HM,7961
|
207
207
|
clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc,sha256=1e6NiK6bnJiiAo2KPsDmm91BSlbI3mVkQZKbDfh5hBI,642
|
208
|
-
clarifai/runners/utils/__pycache__/loader.cpython-310.pyc,sha256=
|
208
|
+
clarifai/runners/utils/__pycache__/loader.cpython-310.pyc,sha256=smsd1eEst3buel_C8OcOhnyGBzvtBe_wrCEaBqhGTVo,6002
|
209
209
|
clarifai/runners/utils/__pycache__/logging.cpython-310.pyc,sha256=VV0KFcnuYpFFtaG4EeDIgg7c4QEsBLo-eX_NnsyFEhA,331
|
210
210
|
clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc,sha256=jFxVdOmm7DCkgatv1GwIXeefHthpvlkg4ybBlMnmxss,1739
|
211
211
|
clarifai/schema/search.py,sha256=JjTi8ammJgZZ2OGl4K6tIA4zEJ1Fr2ASZARXavI1j5c,2448
|
@@ -234,9 +234,9 @@ clarifai/workflows/__pycache__/__init__.cpython-310.pyc,sha256=oRKg6B7Z-wWQy0EW2
|
|
234
234
|
clarifai/workflows/__pycache__/export.cpython-310.pyc,sha256=cNmGLnww7xVpm4htd1vRhQJoEZ1dhpN1oD8iLLAtVzM,2418
|
235
235
|
clarifai/workflows/__pycache__/utils.cpython-310.pyc,sha256=rm2kWk4a3GOKWoerXpEAEeRvGhEe7wPd0ZZ6jHtEGqY,1925
|
236
236
|
clarifai/workflows/__pycache__/validate.cpython-310.pyc,sha256=QA1i6YdDpY824cqtQvkEaFPpaCa2iqfOwFouqwZfAKY,2139
|
237
|
-
clarifai-10.11.
|
238
|
-
clarifai-10.11.
|
239
|
-
clarifai-10.11.
|
240
|
-
clarifai-10.11.
|
241
|
-
clarifai-10.11.
|
242
|
-
clarifai-10.11.
|
237
|
+
clarifai-10.11.2rc3.dist-info/LICENSE,sha256=mUqF_d12-qE2n41g7C5_sq-BMLOcj6CNN-jevr15YHU,555
|
238
|
+
clarifai-10.11.2rc3.dist-info/METADATA,sha256=asimq_wgoMJRN83rnydqa8kUCc-AQBkwExjt_A01W34,22237
|
239
|
+
clarifai-10.11.2rc3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
240
|
+
clarifai-10.11.2rc3.dist-info/entry_points.txt,sha256=X9FZ4Z-i_r2Ud1RpZ9sNIFYuu_-9fogzCMCRUD9hyX0,51
|
241
|
+
clarifai-10.11.2rc3.dist-info/top_level.txt,sha256=wUMdCQGjkxaynZ6nZ9FAnvBUCgp5RJUVFSy2j-KYo0s,9
|
242
|
+
clarifai-10.11.2rc3.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|