clarifai 11.2.3rc1__py3-none-any.whl → 11.2.3rc3__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/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/__pycache__/errors.cpython-310.pyc +0 -0
- clarifai/__pycache__/versions.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-310.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__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/cli/base.py +81 -228
- clarifai/cli/compute_cluster.py +17 -25
- clarifai/cli/deployment.py +41 -67
- clarifai/cli/model.py +39 -26
- clarifai/cli/nodepool.py +40 -59
- clarifai/client/__pycache__/__init__.cpython-310.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-39.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/deployment.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__/nodepool.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/app.py +1 -1
- 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/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 +88 -0
- clarifai/client/cli/model_cli.py +29 -0
- clarifai/client/model.py +159 -393
- clarifai/client/model_client.py +502 -0
- clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/{model.cpython-312.pyc → model.cpython-310.pyc} +0 -0
- clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.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-39.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__/__init__.cpython-39.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__/multimodal.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-39.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-39.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/runners/__init__.py +2 -7
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/runners/dockerfile_template/Dockerfile.cpu.template +31 -0
- clarifai/runners/dockerfile_template/Dockerfile.cuda.template +42 -0
- clarifai/runners/dockerfile_template/Dockerfile.nim +71 -0
- clarifai/runners/models/__pycache__/__init__.cpython-310.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-39.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.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_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/model_builder.py +138 -51
- clarifai/runners/models/model_class.py +441 -28
- clarifai/runners/models/model_class_refract.py +80 -0
- clarifai/runners/models/model_run_locally.py +25 -89
- clarifai/runners/models/model_runner.py +8 -0
- clarifai/runners/models/model_servicer.py +11 -2
- clarifai/runners/models/model_upload.py +607 -0
- clarifai/runners/models/temp.py +25 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-310.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__/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-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-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__/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-38.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
- clarifai/runners/utils/code_script.py +217 -0
- clarifai/runners/utils/const.py +8 -9
- clarifai/runners/utils/data_handler.py +271 -210
- clarifai/runners/utils/data_handler_refract.py +213 -0
- clarifai/runners/utils/data_types.py +473 -0
- clarifai/runners/utils/data_utils.py +165 -0
- clarifai/runners/utils/loader.py +6 -36
- clarifai/runners/utils/logger.py +0 -0
- clarifai/runners/utils/method_signatures.py +518 -0
- clarifai/runners/utils/serializers.py +222 -0
- 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__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
- clarifai/utils/__pycache__/constants.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/cli.py +33 -132
- clarifai/utils/constants.py +0 -4
- clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
- clarifai/utils/misc.py +0 -2
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-39.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.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/METADATA +14 -3
- clarifai-11.2.3rc3.dist-info/RECORD +238 -0
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/WHEEL +1 -1
- clarifai/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/__pycache__/errors.cpython-312.pyc +0 -0
- clarifai/__pycache__/versions.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/base.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/compute_cluster.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-312.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/compute_cluster.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/deployment.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/model_client.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/nodepool.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-312.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-312.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-312.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-312.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/base.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/input.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-312.pyc +0 -0
- clarifai/constants/__pycache__/workflow.cpython-312.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/multimodal.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-312.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-312.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-312.pyc +0 -0
- clarifai/modules/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/modules/__pycache__/css.cpython-312.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/runners/__pycache__/server.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_builder.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-312.pyc +0 -0
- clarifai/runners/models/__pycache__/model_servicer.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_types.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/method_signatures.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/serializers.cpython-312.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-312.pyc +0 -0
- clarifai/schema/__pycache__/search.cpython-312.pyc +0 -0
- clarifai/urls/__pycache__/helper.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/cli.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/config.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/constants.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/logging.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/misc.cpython-312.pyc +0 -0
- clarifai/utils/__pycache__/model_train.cpython-312.pyc +0 -0
- clarifai/utils/config.py +0 -105
- clarifai/utils/config.py~ +0 -145
- clarifai/utils/evaluation/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/helpers.cpython-312.pyc +0 -0
- clarifai/utils/evaluation/__pycache__/main.cpython-312.pyc +0 -0
- clarifai/workflows/__pycache__/__init__.cpython-312.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-312.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-312.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-312.pyc +0 -0
- clarifai-11.2.3rc1.dist-info/RECORD +0 -185
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/LICENSE +0 -0
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/entry_points.txt +0 -0
- {clarifai-11.2.3rc1.dist-info → clarifai-11.2.3rc3.dist-info}/top_level.txt +0 -0
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,217 @@
|
|
1
|
+
import json
|
2
|
+
from typing import List
|
3
|
+
from clarifai_grpc.grpc.api import resources_pb2
|
4
|
+
from clarifai.runners.utils import data_types
|
5
|
+
|
6
|
+
|
7
|
+
def generate_client_script(method_signatures: List[resources_pb2.MethodSignature], user_id, app_id,
|
8
|
+
model_id) -> str:
|
9
|
+
_CLIENT_TEMPLATE = """\
|
10
|
+
from clarifai.runners.utils import data_types
|
11
|
+
import os
|
12
|
+
from clarifai.client import Model
|
13
|
+
|
14
|
+
model = Model("www.clarifai.com/{user_id}/{app_id}/{model_id}",
|
15
|
+
deployment_id = os.environ['CLARIFAI_DEPLOYMENT_ID'], # Only needed for dedicated deployed models
|
16
|
+
)
|
17
|
+
"""
|
18
|
+
# Generate client template
|
19
|
+
client_template = _CLIENT_TEMPLATE.format(user_id=user_id, app_id=app_id, model_id=model_id)
|
20
|
+
|
21
|
+
# Generate method signatures
|
22
|
+
method_signatures_str = []
|
23
|
+
for method_signature in method_signatures:
|
24
|
+
method_name = method_signature.name
|
25
|
+
if method_signature.method_type in [
|
26
|
+
resources_pb2.RunnerMethodType.UNARY_UNARY,
|
27
|
+
resources_pb2.RunnerMethodType.UNARY_STREAMING,
|
28
|
+
]:
|
29
|
+
|
30
|
+
client_script_str = f'response = model.{method_name}('
|
31
|
+
annotations = _get_annotations_source(method_signature)
|
32
|
+
for param_name, (param_type, default_value) in annotations.items():
|
33
|
+
if param_name == "return":
|
34
|
+
continue
|
35
|
+
if default_value is None:
|
36
|
+
default_value = _set_default_value(param_type)
|
37
|
+
if param_type == "str":
|
38
|
+
default_value = repr(default_value)
|
39
|
+
|
40
|
+
client_script_str += f"{param_name}={default_value}, "
|
41
|
+
client_script_str = client_script_str.rstrip(", ") + ")"
|
42
|
+
if method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_UNARY:
|
43
|
+
client_script_str += "\nprint(response)"
|
44
|
+
elif method_signature.method_type == resources_pb2.RunnerMethodType.UNARY_STREAMING:
|
45
|
+
client_script_str += "\nfor res in response:\n print(res)"
|
46
|
+
client_script_str += "\n"
|
47
|
+
method_signatures_str.append(client_script_str)
|
48
|
+
|
49
|
+
method_signatures_str = "\n".join(method_signatures_str)
|
50
|
+
# Combine all parts
|
51
|
+
script_lines = []
|
52
|
+
script_lines.append("\n# Clarifai Model Client Script")
|
53
|
+
script_lines.append(
|
54
|
+
"# Set the environment variables `CLARIFAI_DEPLOYMENT_ID` and `CLARIFAI_PAT` to run this script."
|
55
|
+
)
|
56
|
+
script_lines.append("# Example usage:")
|
57
|
+
script_lines.append(client_template)
|
58
|
+
script_lines.append("# Example model prediction from different model methods: \n")
|
59
|
+
script_lines.append(method_signatures_str)
|
60
|
+
script_lines.append("")
|
61
|
+
script = "\n".join(script_lines)
|
62
|
+
return script
|
63
|
+
|
64
|
+
|
65
|
+
# get annotations source with default values
|
66
|
+
def _get_annotations_source(method_signature: resources_pb2.MethodSignature) -> dict:
|
67
|
+
annotations = {}
|
68
|
+
for input_field in method_signature.input_fields:
|
69
|
+
param_name = input_field.name
|
70
|
+
param_type = _get_base_type(input_field)
|
71
|
+
if input_field.iterator:
|
72
|
+
param_type = f"Iterator[{param_type}]"
|
73
|
+
default_value = None
|
74
|
+
if input_field.default:
|
75
|
+
default_value = _parse_default_value(input_field)
|
76
|
+
|
77
|
+
annotations[param_name] = (param_type, default_value)
|
78
|
+
if not method_signature.output_fields:
|
79
|
+
raise ValueError("MethodSignature must have at least one output field")
|
80
|
+
for output_field in method_signature.output_fields:
|
81
|
+
param_name = output_field.name
|
82
|
+
param_type = _get_base_type(output_field)
|
83
|
+
if output_field.iterator:
|
84
|
+
param_type = f"Iterator[{param_type}]"
|
85
|
+
annotations[param_name] = (param_type, None)
|
86
|
+
return annotations
|
87
|
+
|
88
|
+
|
89
|
+
def _get_base_type(field: resources_pb2.ModelTypeField) -> str:
|
90
|
+
data_type = field.type
|
91
|
+
if data_type == resources_pb2.ModelTypeField.DataType.NAMED_FIELDS:
|
92
|
+
annotations = {}
|
93
|
+
for type_arg in field.type_args:
|
94
|
+
field_name = type_arg.name
|
95
|
+
field_type = _get_base_type(type_arg)
|
96
|
+
annotations[field_name] = field_type
|
97
|
+
class_name = f"NamedFields[{', '.join(f'{k}: {v}' for k, v in annotations.items())}]"
|
98
|
+
return class_name
|
99
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.TUPLE:
|
100
|
+
type_args_str = [_get_base_type(ta) for ta in field.type_args]
|
101
|
+
return f"Tuple[{', '.join(type_args_str)}]"
|
102
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.LIST:
|
103
|
+
if len(field.type_args) != 1:
|
104
|
+
raise ValueError("List type must have exactly one type argument")
|
105
|
+
element_type = _get_base_type(field.type_args[0])
|
106
|
+
return f"List[{element_type}]"
|
107
|
+
else:
|
108
|
+
type_map = {
|
109
|
+
resources_pb2.ModelTypeField.DataType.STR: "str",
|
110
|
+
resources_pb2.ModelTypeField.DataType.BYTES: "bytes",
|
111
|
+
resources_pb2.ModelTypeField.DataType.INT: "int",
|
112
|
+
resources_pb2.ModelTypeField.DataType.FLOAT: "float",
|
113
|
+
resources_pb2.ModelTypeField.DataType.BOOL: "bool",
|
114
|
+
resources_pb2.ModelTypeField.DataType.NDARRAY: "np.ndarray",
|
115
|
+
resources_pb2.ModelTypeField.DataType.JSON_DATA: "data_types.JSON",
|
116
|
+
resources_pb2.ModelTypeField.DataType.TEXT: "data_types.Text",
|
117
|
+
resources_pb2.ModelTypeField.DataType.IMAGE: "data_types.Image",
|
118
|
+
resources_pb2.ModelTypeField.DataType.CONCEPT: "data_types.Concept",
|
119
|
+
resources_pb2.ModelTypeField.DataType.REGION: "data_types.Region",
|
120
|
+
resources_pb2.ModelTypeField.DataType.FRAME: "data_types.Frame",
|
121
|
+
resources_pb2.ModelTypeField.DataType.AUDIO: "data_types.Audio",
|
122
|
+
resources_pb2.ModelTypeField.DataType.VIDEO: "data_types.Video",
|
123
|
+
}
|
124
|
+
return type_map.get(data_type, "Any")
|
125
|
+
|
126
|
+
|
127
|
+
def _map_default_value(field_type):
|
128
|
+
"""
|
129
|
+
Map the default value of a field type to a string representation.
|
130
|
+
"""
|
131
|
+
default_value = None
|
132
|
+
|
133
|
+
if field_type == "str":
|
134
|
+
default_value = 'What is the future of AI?'
|
135
|
+
elif field_type == "bytes":
|
136
|
+
default_value = b""
|
137
|
+
elif field_type == "int":
|
138
|
+
default_value = 0
|
139
|
+
elif field_type == "float":
|
140
|
+
default_value = 0.0
|
141
|
+
elif field_type == "bool":
|
142
|
+
default_value = False
|
143
|
+
elif field_type == "data_types.Image":
|
144
|
+
default_value = data_types.Image.from_url("https://samples.clarifai.com/metro-north.jpg")
|
145
|
+
elif field_type == "data_types.Text":
|
146
|
+
default_value = data_types.Text("What's the future of AI?")
|
147
|
+
elif field_type == "data_types.Audio":
|
148
|
+
default_value = data_types.Audio.from_url("https://samples.clarifai.com/audio.mp3")
|
149
|
+
elif field_type == "data_types.Video":
|
150
|
+
default_value = data_types.Video.from_url("https://samples.clarifai.com/video.mp4")
|
151
|
+
elif field_type == "data_types.Concept":
|
152
|
+
default_value = data_types.Concept(id="concept_id", name="dog", value=0.95)
|
153
|
+
elif field_type == "data_types.Region":
|
154
|
+
default_value = data_types.Region(box=[0.1, 0.1, 0.5, 0.5],)
|
155
|
+
elif field_type == "data_types.Frame":
|
156
|
+
default_value = data_types.Frame.from_url("https://samples.clarifai.com/video.mp4", 0)
|
157
|
+
elif field_type == "data_types.NDArray":
|
158
|
+
default_value = data_types.NDArray([1, 2, 3])
|
159
|
+
else:
|
160
|
+
default_value = None
|
161
|
+
return default_value
|
162
|
+
|
163
|
+
|
164
|
+
def _set_default_value(field_type):
|
165
|
+
"""
|
166
|
+
Set the default value of a field if it is not set.
|
167
|
+
"""
|
168
|
+
default_value = None
|
169
|
+
default_value = _map_default_value(field_type)
|
170
|
+
if field_type.startswith("List["):
|
171
|
+
element_type = field_type[5:-1]
|
172
|
+
element_type_default_value = _map_default_value(element_type)
|
173
|
+
if element_type_default_value is not None:
|
174
|
+
default_value = f"[{element_type_default_value}]"
|
175
|
+
elif field_type.startswith("Tuple["):
|
176
|
+
element_types = field_type[6:-1].split(", ")
|
177
|
+
element_type_defaults = [_map_default_value(et) for et in element_types]
|
178
|
+
default_value = f"({', '.join([str(et) for et in element_type_defaults])})"
|
179
|
+
elif field_type.startswith("NamedFields["):
|
180
|
+
element_types = field_type[12:-1].split(", ")
|
181
|
+
element_type_defaults = [_map_default_value(et) for et in element_types]
|
182
|
+
default_value = f"{{{', '.join([str(et) for et in element_type_defaults])}}}"
|
183
|
+
|
184
|
+
return default_value
|
185
|
+
|
186
|
+
|
187
|
+
def _parse_default_value(field: resources_pb2.ModelTypeField):
|
188
|
+
if not field.default:
|
189
|
+
return None
|
190
|
+
default_str = field.default
|
191
|
+
data_type = field.type
|
192
|
+
|
193
|
+
try:
|
194
|
+
if data_type == resources_pb2.ModelTypeField.DataType.INT:
|
195
|
+
return str(int(default_str))
|
196
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.FLOAT:
|
197
|
+
return str(float(default_str))
|
198
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.BOOL:
|
199
|
+
return 'True' if default_str.lower() == 'true' else 'False'
|
200
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.STR:
|
201
|
+
return repr(default_str)
|
202
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.BYTES:
|
203
|
+
return f"b{repr(default_str.encode('utf-8'))}"
|
204
|
+
elif data_type == resources_pb2.ModelTypeField.DataType.JSON_DATA:
|
205
|
+
parsed = json.loads(default_str)
|
206
|
+
return repr(parsed)
|
207
|
+
elif data_type in (
|
208
|
+
resources_pb2.ModelTypeField.DataType.LIST,
|
209
|
+
resources_pb2.ModelTypeField.DataType.TUPLE,
|
210
|
+
resources_pb2.ModelTypeField.DataType.NAMED_FIELDS,
|
211
|
+
):
|
212
|
+
parsed = json.loads(default_str)
|
213
|
+
return repr(parsed)
|
214
|
+
else:
|
215
|
+
return repr(default_str)
|
216
|
+
except (ValueError, json.JSONDecodeError):
|
217
|
+
return repr(default_str)
|
clarifai/runners/utils/const.py
CHANGED
@@ -2,10 +2,10 @@ import os
|
|
2
2
|
|
3
3
|
registry = os.environ.get('CLARIFAI_BASE_IMAGE_REGISTRY', 'public.ecr.aws/clarifai-models')
|
4
4
|
|
5
|
-
GIT_SHA = "
|
5
|
+
GIT_SHA = "df565436eea93efb3e8d1eb558a0a46df29523ec"
|
6
6
|
|
7
7
|
PYTHON_BASE_IMAGE = registry + '/python-base:{python_version}-' + GIT_SHA
|
8
|
-
TORCH_BASE_IMAGE = registry + '/torch:{torch_version}-py{python_version}-{
|
8
|
+
TORCH_BASE_IMAGE = registry + '/torch:{torch_version}-py{python_version}-cuda{cuda_version}-' + GIT_SHA
|
9
9
|
|
10
10
|
# List of available python base images
|
11
11
|
AVAILABLE_PYTHON_IMAGES = ['3.11', '3.12']
|
@@ -21,13 +21,12 @@ DEFAULT_RUNTIME_DOWNLOAD_PATH = os.path.join(os.sep, "tmp", ".cache")
|
|
21
21
|
# List of available torch images
|
22
22
|
# Keep sorted by most recent cuda version.
|
23
23
|
AVAILABLE_TORCH_IMAGES = [
|
24
|
-
'2.4.1-py3.11-
|
25
|
-
'2.5.1-py3.11-
|
26
|
-
'2.4.1-py3.12-
|
27
|
-
'2.5.1-py3.12-
|
28
|
-
'2.
|
29
|
-
'2.
|
30
|
-
'2.7.0-py3.12-rocm6.3',
|
24
|
+
'2.4.1-py3.11-cuda124',
|
25
|
+
'2.5.1-py3.11-cuda124',
|
26
|
+
'2.4.1-py3.12-cuda124',
|
27
|
+
'2.5.1-py3.12-cuda124',
|
28
|
+
# '2.4.1-py3.13-cuda124',
|
29
|
+
# '2.5.1-py3.13-cuda124',
|
31
30
|
]
|
32
31
|
CONCEPTS_REQUIRED_MODEL_TYPE = [
|
33
32
|
'visual-classifier', 'visual-detector', 'visual-segmenter', 'text-classifier'
|