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
@@ -2,180 +2,188 @@ from typing import Iterator
|
|
2
2
|
|
3
3
|
from clarifai_grpc.grpc.api import service_pb2
|
4
4
|
from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
|
5
|
-
|
6
5
|
from clarifai_protocol import BaseRunner
|
7
6
|
from clarifai_protocol.utils.health import HealthProbeRequestHandler
|
8
|
-
from ..utils.url_fetcher import ensure_urls_downloaded
|
9
7
|
|
8
|
+
from ..utils.url_fetcher import ensure_urls_downloaded
|
10
9
|
from .model_class import ModelClass
|
11
10
|
|
12
11
|
|
13
12
|
class ModelRunner(BaseRunner, HealthProbeRequestHandler):
|
14
|
-
"""
|
15
|
-
This is a subclass of the runner class which will handle only the work items relevant to models.
|
16
|
-
"""
|
17
|
-
|
18
|
-
def __init__(
|
19
|
-
self,
|
20
|
-
model: ModelClass,
|
21
|
-
runner_id: str,
|
22
|
-
nodepool_id: str,
|
23
|
-
compute_cluster_id: str,
|
24
|
-
user_id: str = None,
|
25
|
-
check_runner_exists: bool = True,
|
26
|
-
base_url: str = "https://api.clarifai.com",
|
27
|
-
pat: str = None,
|
28
|
-
token: str = None,
|
29
|
-
num_parallel_polls: int = 4,
|
30
|
-
**kwargs,
|
31
|
-
) -> None:
|
32
|
-
super().__init__(
|
33
|
-
runner_id,
|
34
|
-
nodepool_id,
|
35
|
-
compute_cluster_id,
|
36
|
-
user_id,
|
37
|
-
check_runner_exists,
|
38
|
-
base_url,
|
39
|
-
pat,
|
40
|
-
token,
|
41
|
-
num_parallel_polls,
|
42
|
-
**kwargs,
|
43
|
-
)
|
44
|
-
self.model = model
|
45
|
-
|
46
|
-
# After model load successfully set the health probe to ready and startup
|
47
|
-
HealthProbeRequestHandler.is_ready = True
|
48
|
-
HealthProbeRequestHandler.is_startup = True
|
49
|
-
|
50
|
-
def get_runner_item_output_for_status(self,
|
51
|
-
status: status_pb2.Status) -> service_pb2.RunnerItemOutput:
|
52
13
|
"""
|
53
|
-
|
54
|
-
where we may only have a status to return.
|
55
|
-
|
56
|
-
Args:
|
57
|
-
status: status_pb2.Status - the status to return
|
58
|
-
|
59
|
-
Returns:
|
60
|
-
service_pb2.RunnerItemOutput - the RunnerItemOutput message with the status set
|
61
|
-
"""
|
62
|
-
rio = service_pb2.RunnerItemOutput(
|
63
|
-
multi_output_response=service_pb2.MultiOutputResponse(status=status))
|
64
|
-
return rio
|
65
|
-
|
66
|
-
def runner_item_predict(self,
|
67
|
-
runner_item: service_pb2.RunnerItem) -> service_pb2.RunnerItemOutput:
|
14
|
+
This is a subclass of the runner class which will handle only the work items relevant to models.
|
68
15
|
"""
|
69
|
-
Run the model on the given request. You shouldn't need to override this method, see run_input
|
70
|
-
for the implementation to process each input in the request.
|
71
16
|
|
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
|
-
else:
|
99
|
-
status = status_pb2.Status(
|
100
|
-
code=status_code_pb2.FAILURE,
|
101
|
-
description="Failed",
|
102
|
-
)
|
103
|
-
|
104
|
-
resp.status.CopyFrom(status)
|
105
|
-
return service_pb2.RunnerItemOutput(multi_output_response=resp)
|
106
|
-
|
107
|
-
def runner_item_generate(
|
108
|
-
self, runner_item: service_pb2.RunnerItem) -> Iterator[service_pb2.RunnerItemOutput]:
|
109
|
-
# Call the generate() method the underlying model implements.
|
110
|
-
|
111
|
-
if not runner_item.HasField('post_model_outputs_request'):
|
112
|
-
raise Exception("Unexpected work item type: {}".format(runner_item))
|
113
|
-
request = runner_item.post_model_outputs_request
|
114
|
-
ensure_urls_downloaded(request)
|
115
|
-
|
116
|
-
for resp in self.model.generate_wrapper(request):
|
117
|
-
if resp.status.code != status_code_pb2.SUCCESS:
|
118
|
-
yield service_pb2.RunnerItemOutput(multi_output_response=resp)
|
119
|
-
continue
|
120
|
-
successes = []
|
121
|
-
for output in resp.outputs:
|
122
|
-
if not output.HasField('status') or not output.status.code:
|
123
|
-
raise Exception("Output must have a status code, please check the model implementation.")
|
124
|
-
successes.append(output.status.code == status_code_pb2.SUCCESS)
|
125
|
-
if all(successes):
|
126
|
-
status = status_pb2.Status(
|
127
|
-
code=status_code_pb2.SUCCESS,
|
128
|
-
description="Success",
|
129
|
-
)
|
130
|
-
elif any(successes):
|
131
|
-
status = status_pb2.Status(
|
132
|
-
code=status_code_pb2.MIXED_STATUS,
|
133
|
-
description="Mixed Status",
|
134
|
-
)
|
135
|
-
else:
|
136
|
-
status = status_pb2.Status(
|
137
|
-
code=status_code_pb2.FAILURE,
|
138
|
-
description="Failed",
|
139
|
-
)
|
140
|
-
resp.status.CopyFrom(status)
|
141
|
-
|
142
|
-
yield service_pb2.RunnerItemOutput(multi_output_response=resp)
|
143
|
-
|
144
|
-
def runner_item_stream(self, runner_item_iterator: Iterator[service_pb2.RunnerItem]
|
145
|
-
) -> Iterator[service_pb2.RunnerItemOutput]:
|
146
|
-
# Call the generate() method the underlying model implements.
|
147
|
-
for resp in self.model.stream_wrapper(pmo_iterator(runner_item_iterator)):
|
148
|
-
if resp.status.code != status_code_pb2.SUCCESS:
|
149
|
-
yield service_pb2.RunnerItemOutput(multi_output_response=resp)
|
150
|
-
continue
|
151
|
-
successes = []
|
152
|
-
for output in resp.outputs:
|
153
|
-
if not output.HasField('status') or not output.status.code:
|
154
|
-
raise Exception("Output must have a status code, please check the model implementation.")
|
155
|
-
successes.append(output.status.code == status_code_pb2.SUCCESS)
|
156
|
-
if all(successes):
|
157
|
-
status = status_pb2.Status(
|
158
|
-
code=status_code_pb2.SUCCESS,
|
159
|
-
description="Success",
|
160
|
-
)
|
161
|
-
elif any(successes):
|
162
|
-
status = status_pb2.Status(
|
163
|
-
code=status_code_pb2.MIXED_STATUS,
|
164
|
-
description="Mixed Status",
|
17
|
+
def __init__(
|
18
|
+
self,
|
19
|
+
model: ModelClass,
|
20
|
+
runner_id: str,
|
21
|
+
nodepool_id: str,
|
22
|
+
compute_cluster_id: str,
|
23
|
+
user_id: str = None,
|
24
|
+
check_runner_exists: bool = True,
|
25
|
+
base_url: str = "https://api.clarifai.com",
|
26
|
+
pat: str = None,
|
27
|
+
token: str = None,
|
28
|
+
num_parallel_polls: int = 4,
|
29
|
+
**kwargs,
|
30
|
+
) -> None:
|
31
|
+
super().__init__(
|
32
|
+
runner_id,
|
33
|
+
nodepool_id,
|
34
|
+
compute_cluster_id,
|
35
|
+
user_id,
|
36
|
+
check_runner_exists,
|
37
|
+
base_url,
|
38
|
+
pat,
|
39
|
+
token,
|
40
|
+
num_parallel_polls,
|
41
|
+
**kwargs,
|
165
42
|
)
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
43
|
+
self.model = model
|
44
|
+
|
45
|
+
# After model load successfully set the health probe to ready and startup
|
46
|
+
HealthProbeRequestHandler.is_ready = True
|
47
|
+
HealthProbeRequestHandler.is_startup = True
|
48
|
+
|
49
|
+
def get_runner_item_output_for_status(
|
50
|
+
self, status: status_pb2.Status
|
51
|
+
) -> service_pb2.RunnerItemOutput:
|
52
|
+
"""
|
53
|
+
Set the error message in the RunnerItemOutput message subfield, used during exception handling
|
54
|
+
where we may only have a status to return.
|
55
|
+
|
56
|
+
Args:
|
57
|
+
status: status_pb2.Status - the status to return
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
service_pb2.RunnerItemOutput - the RunnerItemOutput message with the status set
|
61
|
+
"""
|
62
|
+
rio = service_pb2.RunnerItemOutput(
|
63
|
+
multi_output_response=service_pb2.MultiOutputResponse(status=status)
|
170
64
|
)
|
171
|
-
|
172
|
-
|
173
|
-
|
65
|
+
return rio
|
66
|
+
|
67
|
+
def runner_item_predict(
|
68
|
+
self, runner_item: service_pb2.RunnerItem
|
69
|
+
) -> service_pb2.RunnerItemOutput:
|
70
|
+
"""
|
71
|
+
Run the model on the given request. You shouldn't need to override this method, see run_input
|
72
|
+
for the implementation to process each input in the request.
|
73
|
+
|
74
|
+
Args:
|
75
|
+
request: service_pb2.PostModelOutputsRequest - the request to run the model on
|
76
|
+
|
77
|
+
Returns:
|
78
|
+
service_pb2.MultiOutputResponse - the response from the model's run_input implementation.
|
79
|
+
"""
|
80
|
+
|
81
|
+
if not runner_item.HasField('post_model_outputs_request'):
|
82
|
+
raise Exception("Unexpected work item type: {}".format(runner_item))
|
83
|
+
request = runner_item.post_model_outputs_request
|
84
|
+
ensure_urls_downloaded(request)
|
85
|
+
|
86
|
+
resp = self.model.predict_wrapper(request)
|
87
|
+
if resp.status.code != status_code_pb2.SUCCESS:
|
88
|
+
return service_pb2.RunnerItemOutput(multi_output_response=resp)
|
89
|
+
successes = [o.status.code == status_code_pb2.SUCCESS for o in resp.outputs]
|
90
|
+
if all(successes):
|
91
|
+
status = status_pb2.Status(
|
92
|
+
code=status_code_pb2.SUCCESS,
|
93
|
+
description="Success",
|
94
|
+
)
|
95
|
+
elif any(successes):
|
96
|
+
status = status_pb2.Status(
|
97
|
+
code=status_code_pb2.MIXED_STATUS,
|
98
|
+
description="Mixed Status",
|
99
|
+
)
|
100
|
+
else:
|
101
|
+
status = status_pb2.Status(
|
102
|
+
code=status_code_pb2.FAILURE,
|
103
|
+
description="Failed",
|
104
|
+
)
|
105
|
+
|
106
|
+
resp.status.CopyFrom(status)
|
107
|
+
return service_pb2.RunnerItemOutput(multi_output_response=resp)
|
108
|
+
|
109
|
+
def runner_item_generate(
|
110
|
+
self, runner_item: service_pb2.RunnerItem
|
111
|
+
) -> Iterator[service_pb2.RunnerItemOutput]:
|
112
|
+
# Call the generate() method the underlying model implements.
|
113
|
+
|
114
|
+
if not runner_item.HasField('post_model_outputs_request'):
|
115
|
+
raise Exception("Unexpected work item type: {}".format(runner_item))
|
116
|
+
request = runner_item.post_model_outputs_request
|
117
|
+
ensure_urls_downloaded(request)
|
118
|
+
|
119
|
+
for resp in self.model.generate_wrapper(request):
|
120
|
+
if resp.status.code != status_code_pb2.SUCCESS:
|
121
|
+
yield service_pb2.RunnerItemOutput(multi_output_response=resp)
|
122
|
+
continue
|
123
|
+
successes = []
|
124
|
+
for output in resp.outputs:
|
125
|
+
if not output.HasField('status') or not output.status.code:
|
126
|
+
raise Exception(
|
127
|
+
"Output must have a status code, please check the model implementation."
|
128
|
+
)
|
129
|
+
successes.append(output.status.code == status_code_pb2.SUCCESS)
|
130
|
+
if all(successes):
|
131
|
+
status = status_pb2.Status(
|
132
|
+
code=status_code_pb2.SUCCESS,
|
133
|
+
description="Success",
|
134
|
+
)
|
135
|
+
elif any(successes):
|
136
|
+
status = status_pb2.Status(
|
137
|
+
code=status_code_pb2.MIXED_STATUS,
|
138
|
+
description="Mixed Status",
|
139
|
+
)
|
140
|
+
else:
|
141
|
+
status = status_pb2.Status(
|
142
|
+
code=status_code_pb2.FAILURE,
|
143
|
+
description="Failed",
|
144
|
+
)
|
145
|
+
resp.status.CopyFrom(status)
|
146
|
+
|
147
|
+
yield service_pb2.RunnerItemOutput(multi_output_response=resp)
|
148
|
+
|
149
|
+
def runner_item_stream(
|
150
|
+
self, runner_item_iterator: Iterator[service_pb2.RunnerItem]
|
151
|
+
) -> Iterator[service_pb2.RunnerItemOutput]:
|
152
|
+
# Call the generate() method the underlying model implements.
|
153
|
+
for resp in self.model.stream_wrapper(pmo_iterator(runner_item_iterator)):
|
154
|
+
if resp.status.code != status_code_pb2.SUCCESS:
|
155
|
+
yield service_pb2.RunnerItemOutput(multi_output_response=resp)
|
156
|
+
continue
|
157
|
+
successes = []
|
158
|
+
for output in resp.outputs:
|
159
|
+
if not output.HasField('status') or not output.status.code:
|
160
|
+
raise Exception(
|
161
|
+
"Output must have a status code, please check the model implementation."
|
162
|
+
)
|
163
|
+
successes.append(output.status.code == status_code_pb2.SUCCESS)
|
164
|
+
if all(successes):
|
165
|
+
status = status_pb2.Status(
|
166
|
+
code=status_code_pb2.SUCCESS,
|
167
|
+
description="Success",
|
168
|
+
)
|
169
|
+
elif any(successes):
|
170
|
+
status = status_pb2.Status(
|
171
|
+
code=status_code_pb2.MIXED_STATUS,
|
172
|
+
description="Mixed Status",
|
173
|
+
)
|
174
|
+
else:
|
175
|
+
status = status_pb2.Status(
|
176
|
+
code=status_code_pb2.FAILURE,
|
177
|
+
description="Failed",
|
178
|
+
)
|
179
|
+
resp.status.CopyFrom(status)
|
180
|
+
|
181
|
+
yield service_pb2.RunnerItemOutput(multi_output_response=resp)
|
174
182
|
|
175
183
|
|
176
184
|
def pmo_iterator(runner_item_iterator):
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
185
|
+
for runner_item in runner_item_iterator:
|
186
|
+
if not runner_item.HasField('post_model_outputs_request'):
|
187
|
+
raise Exception("Unexpected work item type: {}".format(runner_item))
|
188
|
+
ensure_urls_downloaded(runner_item.post_model_outputs_request)
|
189
|
+
yield runner_item.post_model_outputs_request
|
@@ -11,83 +11,91 @@ _RAISE_EXCEPTIONS = os.getenv("RAISE_EXCEPTIONS", "false").lower() in ("true", "
|
|
11
11
|
|
12
12
|
|
13
13
|
class ModelServicer(service_pb2_grpc.V2Servicer):
|
14
|
-
"""
|
15
|
-
This is the servicer that will handle the gRPC requests from either the dev server or runner loop.
|
16
|
-
"""
|
17
|
-
|
18
|
-
def __init__(self, model):
|
19
14
|
"""
|
20
|
-
|
21
|
-
model: The class that will handle the model logic. Must implement predict(),
|
22
|
-
generate(), stream().
|
15
|
+
This is the servicer that will handle the gRPC requests from either the dev server or runner loop.
|
23
16
|
"""
|
24
|
-
self.model = model
|
25
17
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
18
|
+
def __init__(self, model):
|
19
|
+
"""
|
20
|
+
Args:
|
21
|
+
model: The class that will handle the model logic. Must implement predict(),
|
22
|
+
generate(), stream().
|
23
|
+
"""
|
24
|
+
self.model = model
|
32
25
|
|
33
|
-
|
34
|
-
|
26
|
+
def PostModelOutputs(
|
27
|
+
self, request: service_pb2.PostModelOutputsRequest, context=None
|
28
|
+
) -> service_pb2.MultiOutputResponse:
|
29
|
+
"""
|
30
|
+
This is the method that will be called when the servicer is run. It takes in an input and
|
31
|
+
returns an output.
|
32
|
+
"""
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
except Exception as e:
|
39
|
-
if _RAISE_EXCEPTIONS:
|
40
|
-
raise
|
41
|
-
return service_pb2.MultiOutputResponse(status=status_pb2.Status(
|
42
|
-
code=status_code_pb2.MODEL_PREDICTION_FAILED,
|
43
|
-
description="Failed",
|
44
|
-
details="",
|
45
|
-
internal_details=str(e),
|
46
|
-
))
|
34
|
+
# Download any urls that are not already bytes.
|
35
|
+
ensure_urls_downloaded(request)
|
47
36
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
37
|
+
try:
|
38
|
+
return self.model.predict_wrapper(request)
|
39
|
+
except Exception as e:
|
40
|
+
if _RAISE_EXCEPTIONS:
|
41
|
+
raise
|
42
|
+
return service_pb2.MultiOutputResponse(
|
43
|
+
status=status_pb2.Status(
|
44
|
+
code=status_code_pb2.MODEL_PREDICTION_FAILED,
|
45
|
+
description="Failed",
|
46
|
+
details="",
|
47
|
+
internal_details=str(e),
|
48
|
+
)
|
49
|
+
)
|
56
50
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
internal_details=str(e),
|
67
|
-
))
|
51
|
+
def GenerateModelOutputs(
|
52
|
+
self, request: service_pb2.PostModelOutputsRequest, context=None
|
53
|
+
) -> Iterator[service_pb2.MultiOutputResponse]:
|
54
|
+
"""
|
55
|
+
This is the method that will be called when the servicer is run. It takes in an input and
|
56
|
+
returns an output.
|
57
|
+
"""
|
58
|
+
# Download any urls that are not already bytes.
|
59
|
+
ensure_urls_downloaded(request)
|
68
60
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
61
|
+
try:
|
62
|
+
yield from self.model.generate_wrapper(request)
|
63
|
+
except Exception as e:
|
64
|
+
if _RAISE_EXCEPTIONS:
|
65
|
+
raise
|
66
|
+
yield service_pb2.MultiOutputResponse(
|
67
|
+
status=status_pb2.Status(
|
68
|
+
code=status_code_pb2.MODEL_PREDICTION_FAILED,
|
69
|
+
description="Failed",
|
70
|
+
details="",
|
71
|
+
internal_details=str(e),
|
72
|
+
)
|
73
|
+
)
|
74
|
+
|
75
|
+
def StreamModelOutputs(
|
76
|
+
self, request: Iterator[service_pb2.PostModelOutputsRequest], context=None
|
77
|
+
) -> Iterator[service_pb2.MultiOutputResponse]:
|
78
|
+
"""
|
79
|
+
This is the method that will be called when the servicer is run. It takes in an input and
|
80
|
+
returns an output.
|
81
|
+
"""
|
82
|
+
# Duplicate the iterator
|
83
|
+
request, request_copy = tee(request)
|
78
84
|
|
79
|
-
|
80
|
-
|
81
|
-
|
85
|
+
# Download any urls that are not already bytes.
|
86
|
+
for req in request:
|
87
|
+
ensure_urls_downloaded(req)
|
82
88
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
89
|
+
try:
|
90
|
+
yield from self.model.stream_wrapper(request_copy)
|
91
|
+
except Exception as e:
|
92
|
+
if _RAISE_EXCEPTIONS:
|
93
|
+
raise
|
94
|
+
yield service_pb2.MultiOutputResponse(
|
95
|
+
status=status_pb2.Status(
|
96
|
+
code=status_code_pb2.MODEL_PREDICTION_FAILED,
|
97
|
+
description="Failed",
|
98
|
+
details="",
|
99
|
+
internal_details=str(e),
|
100
|
+
)
|
101
|
+
)
|