clarifai 11.1.5rc7__py3-none-any.whl → 11.1.6__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/model.py +40 -50
- clarifai/client/model.py +365 -95
- clarifai/runners/__init__.py +7 -2
- clarifai/runners/dockerfile_template/Dockerfile.template +1 -4
- clarifai/runners/models/base_typed_model.py +238 -0
- clarifai/runners/models/model_builder.py +9 -26
- clarifai/runners/models/model_class.py +28 -273
- clarifai/runners/models/model_run_locally.py +78 -3
- clarifai/runners/models/model_runner.py +0 -2
- clarifai/runners/models/model_servicer.py +2 -11
- clarifai/runners/utils/data_handler.py +205 -308
- {clarifai-11.1.5rc7.dist-info → clarifai-11.1.6.dist-info}/METADATA +26 -16
- clarifai-11.1.6.dist-info/RECORD +101 -0
- {clarifai-11.1.5rc7.dist-info → clarifai-11.1.6.dist-info}/WHEEL +1 -1
- clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/cli/__main__.py~ +0 -4
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__main__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/runner.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
- clarifai/client/model_client.py +0 -432
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-310.pyc +0 -0
- clarifai/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/_utils.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/build.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/create.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/config.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/inference_parameter.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/output.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/serializer.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/triton_config.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/wrappers.cpython-310.pyc +0 -0
- clarifai/models/model_serving/repo_build/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/repo_build/__pycache__/build.cpython-310.pyc +0 -0
- clarifai/models/model_serving/repo_build/static_files/__pycache__/base_test.cpython-310-pytest-7.2.0.pyc +0 -0
- clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/server.cpython-310.pyc +0 -0
- clarifai/runners/dockerfile_template/Dockerfile.debug +0 -11
- clarifai/runners/dockerfile_template/Dockerfile.debug~ +0 -9
- clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_servicer.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_types.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/method_signatures.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/serializers.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
- clarifai/runners/utils/data_types.py +0 -334
- clarifai/runners/utils/method_signatures.py +0 -452
- clarifai/runners/utils/serializers.py +0 -132
- clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/helpers.cpython-310.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- clarifai-11.1.5rc7.dist-info/RECORD +0 -203
- {clarifai-11.1.5rc7.dist-info → clarifai-11.1.6.dist-info}/LICENSE +0 -0
- {clarifai-11.1.5rc7.dist-info → clarifai-11.1.6.dist-info}/entry_points.txt +0 -0
- {clarifai-11.1.5rc7.dist-info → clarifai-11.1.6.dist-info}/top_level.txt +0 -0
@@ -7,11 +7,14 @@ import subprocess
|
|
7
7
|
import sys
|
8
8
|
import tempfile
|
9
9
|
import time
|
10
|
+
import traceback
|
10
11
|
import venv
|
11
12
|
|
12
13
|
from clarifai_grpc.grpc.api import resources_pb2, service_pb2
|
14
|
+
from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
|
13
15
|
|
14
16
|
from clarifai.runners.models.model_builder import ModelBuilder
|
17
|
+
from clarifai.runners.utils.url_fetcher import ensure_urls_downloaded
|
15
18
|
from clarifai.utils.logging import logger
|
16
19
|
|
17
20
|
|
@@ -108,13 +111,85 @@ class ModelRunLocally:
|
|
108
111
|
for i in range(1):
|
109
112
|
yield request
|
110
113
|
|
114
|
+
def _run_model_inference(self, model):
|
115
|
+
"""Perform inference using the model."""
|
116
|
+
request = self._build_request()
|
117
|
+
stream_request = self._build_stream_request()
|
118
|
+
|
119
|
+
ensure_urls_downloaded(request)
|
120
|
+
predict_response = None
|
121
|
+
generate_response = None
|
122
|
+
stream_response = None
|
123
|
+
try:
|
124
|
+
predict_response = model.predict(request)
|
125
|
+
except NotImplementedError:
|
126
|
+
logger.info("Model does not implement predict() method.")
|
127
|
+
except Exception as e:
|
128
|
+
logger.error(f"Model Prediction failed: {e}")
|
129
|
+
traceback.print_exc()
|
130
|
+
predict_response = service_pb2.MultiOutputResponse(status=status_pb2.Status(
|
131
|
+
code=status_code_pb2.MODEL_PREDICTION_FAILED,
|
132
|
+
description="Prediction failed",
|
133
|
+
details="",
|
134
|
+
internal_details=str(e),
|
135
|
+
))
|
136
|
+
|
137
|
+
if predict_response:
|
138
|
+
if predict_response.outputs[0].status.code != status_code_pb2.SUCCESS:
|
139
|
+
logger.error(f"Moddel Prediction failed: {predict_response}")
|
140
|
+
else:
|
141
|
+
logger.info(f"Model Prediction succeeded: {predict_response}")
|
142
|
+
|
143
|
+
try:
|
144
|
+
generate_response = model.generate(request)
|
145
|
+
except NotImplementedError:
|
146
|
+
logger.info("Model does not implement generate() method.")
|
147
|
+
except Exception as e:
|
148
|
+
logger.error(f"Model Generation failed: {e}")
|
149
|
+
traceback.print_exc()
|
150
|
+
generate_response = service_pb2.MultiOutputResponse(status=status_pb2.Status(
|
151
|
+
code=status_code_pb2.MODEL_GENERATION_FAILED,
|
152
|
+
description="Generation failed",
|
153
|
+
details="",
|
154
|
+
internal_details=str(e),
|
155
|
+
))
|
156
|
+
|
157
|
+
if generate_response:
|
158
|
+
generate_first_res = next(generate_response)
|
159
|
+
if generate_first_res.outputs[0].status.code != status_code_pb2.SUCCESS:
|
160
|
+
logger.error(f"Moddel Prediction failed: {generate_first_res}")
|
161
|
+
else:
|
162
|
+
logger.info(
|
163
|
+
f"Model Prediction succeeded for generate and first response: {generate_first_res}")
|
164
|
+
|
165
|
+
try:
|
166
|
+
stream_response = model.stream(stream_request)
|
167
|
+
except NotImplementedError:
|
168
|
+
logger.info("Model does not implement stream() method.")
|
169
|
+
except Exception as e:
|
170
|
+
logger.error(f"Model Stream failed: {e}")
|
171
|
+
traceback.print_exc()
|
172
|
+
stream_response = service_pb2.MultiOutputResponse(status=status_pb2.Status(
|
173
|
+
code=status_code_pb2.MODEL_STREAM_FAILED,
|
174
|
+
description="Stream failed",
|
175
|
+
details="",
|
176
|
+
internal_details=str(e),
|
177
|
+
))
|
178
|
+
|
179
|
+
if stream_response:
|
180
|
+
stream_first_res = next(stream_response)
|
181
|
+
if stream_first_res.outputs[0].status.code != status_code_pb2.SUCCESS:
|
182
|
+
logger.error(f"Moddel Prediction failed: {stream_first_res}")
|
183
|
+
else:
|
184
|
+
logger.info(
|
185
|
+
f"Model Prediction succeeded for stream and first response: {stream_first_res}")
|
186
|
+
|
111
187
|
def _run_test(self):
|
112
188
|
"""Test the model locally by making a prediction."""
|
113
189
|
# Create the model
|
114
190
|
model = self.builder.create_model_instance()
|
115
|
-
#
|
116
|
-
|
117
|
-
model.test()
|
191
|
+
# send an inference.
|
192
|
+
self._run_model_inference(model)
|
118
193
|
|
119
194
|
def test_model(self):
|
120
195
|
"""Test the model by running it locally in the virtual environment."""
|
@@ -82,8 +82,6 @@ class ModelRunner(BaseRunner, HealthProbeRequestHandler):
|
|
82
82
|
ensure_urls_downloaded(request)
|
83
83
|
|
84
84
|
resp = self.model.predict_wrapper(request)
|
85
|
-
if resp.status.code != status_code_pb2.SUCCESS:
|
86
|
-
return service_pb2.RunnerItemOutput(multi_output_response=resp)
|
87
85
|
successes = [o.status.code == status_code_pb2.SUCCESS for o in resp.outputs]
|
88
86
|
if all(successes):
|
89
87
|
status = status_pb2.Status(
|
@@ -1,4 +1,3 @@
|
|
1
|
-
import os
|
2
1
|
from itertools import tee
|
3
2
|
from typing import Iterator
|
4
3
|
|
@@ -7,8 +6,6 @@ from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
|
|
7
6
|
|
8
7
|
from ..utils.url_fetcher import ensure_urls_downloaded
|
9
8
|
|
10
|
-
_RAISE_EXCEPTIONS = os.getenv("RAISE_EXCEPTIONS", "false").lower() in ("true", "1")
|
11
|
-
|
12
9
|
|
13
10
|
class ModelServicer(service_pb2_grpc.V2Servicer):
|
14
11
|
"""
|
@@ -36,8 +33,6 @@ class ModelServicer(service_pb2_grpc.V2Servicer):
|
|
36
33
|
try:
|
37
34
|
return self.model.predict_wrapper(request)
|
38
35
|
except Exception as e:
|
39
|
-
if _RAISE_EXCEPTIONS:
|
40
|
-
raise
|
41
36
|
return service_pb2.MultiOutputResponse(status=status_pb2.Status(
|
42
37
|
code=status_code_pb2.MODEL_PREDICTION_FAILED,
|
43
38
|
description="Failed",
|
@@ -55,10 +50,8 @@ class ModelServicer(service_pb2_grpc.V2Servicer):
|
|
55
50
|
ensure_urls_downloaded(request)
|
56
51
|
|
57
52
|
try:
|
58
|
-
|
53
|
+
return self.model.generate_wrapper(request)
|
59
54
|
except Exception as e:
|
60
|
-
if _RAISE_EXCEPTIONS:
|
61
|
-
raise
|
62
55
|
yield service_pb2.MultiOutputResponse(status=status_pb2.Status(
|
63
56
|
code=status_code_pb2.MODEL_PREDICTION_FAILED,
|
64
57
|
description="Failed",
|
@@ -81,10 +74,8 @@ class ModelServicer(service_pb2_grpc.V2Servicer):
|
|
81
74
|
ensure_urls_downloaded(req)
|
82
75
|
|
83
76
|
try:
|
84
|
-
|
77
|
+
return self.model.stream_wrapper(request_copy)
|
85
78
|
except Exception as e:
|
86
|
-
if _RAISE_EXCEPTIONS:
|
87
|
-
raise
|
88
79
|
yield service_pb2.MultiOutputResponse(status=status_pb2.Status(
|
89
80
|
code=status_code_pb2.MODEL_PREDICTION_FAILED,
|
90
81
|
description="Failed",
|