clarifai 9.8.1__py3-none-any.whl → 9.9.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/client/app.py +115 -14
- clarifai/client/base.py +11 -4
- clarifai/client/dataset.py +8 -3
- clarifai/client/input.py +34 -28
- clarifai/client/model.py +71 -2
- clarifai/client/module.py +4 -2
- clarifai/client/runner.py +161 -0
- clarifai/client/search.py +173 -0
- clarifai/client/user.py +110 -4
- clarifai/client/workflow.py +27 -2
- clarifai/constants/search.py +2 -0
- clarifai/datasets/upload/loaders/xview_detection.py +1 -1
- clarifai/models/model_serving/README.md +3 -3
- clarifai/models/model_serving/cli/deploy_cli.py +2 -3
- clarifai/models/model_serving/cli/repository.py +3 -5
- clarifai/models/model_serving/constants.py +1 -5
- clarifai/models/model_serving/docs/custom_config.md +5 -6
- clarifai/models/model_serving/docs/dependencies.md +5 -10
- clarifai/models/model_serving/examples/image_classification/age_vit/requirements.txt +1 -0
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/requirements.txt +1 -0
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/requirements.txt +1 -0
- clarifai/models/model_serving/examples/text_to_text/bart-summarize/requirements.txt +1 -0
- clarifai/models/model_serving/examples/visual_detection/yolov5x/requirements.txt +1 -1
- clarifai/models/model_serving/examples/visual_embedding/vit-base/requirements.txt +1 -0
- clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/requirements.txt +1 -0
- clarifai/models/model_serving/model_config/__init__.py +2 -0
- clarifai/models/model_serving/model_config/config.py +298 -0
- clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +18 -0
- clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +18 -0
- clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +18 -0
- clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +18 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +18 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +28 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +18 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +18 -0
- clarifai/models/model_serving/model_config/serializer.py +1 -1
- clarifai/models/model_serving/models/default_test.py +22 -21
- clarifai/models/model_serving/models/output.py +2 -2
- clarifai/models/model_serving/pb_model_repository.py +2 -5
- clarifai/runners/__init__.py +0 -0
- clarifai/runners/example.py +33 -0
- clarifai/schema/search.py +60 -0
- clarifai/utils/logging.py +53 -3
- clarifai/versions.py +1 -1
- clarifai/workflows/__init__.py +0 -0
- clarifai/workflows/export.py +68 -0
- clarifai/workflows/utils.py +59 -0
- clarifai/workflows/validate.py +67 -0
- {clarifai-9.8.1.dist-info → clarifai-9.9.0.dist-info}/METADATA +20 -2
- {clarifai-9.8.1.dist-info → clarifai-9.9.0.dist-info}/RECORD +102 -86
- clarifai_utils/client/app.py +115 -14
- clarifai_utils/client/base.py +11 -4
- clarifai_utils/client/dataset.py +8 -3
- clarifai_utils/client/input.py +34 -28
- clarifai_utils/client/model.py +71 -2
- clarifai_utils/client/module.py +4 -2
- clarifai_utils/client/runner.py +161 -0
- clarifai_utils/client/search.py +173 -0
- clarifai_utils/client/user.py +110 -4
- clarifai_utils/client/workflow.py +27 -2
- clarifai_utils/constants/search.py +2 -0
- clarifai_utils/datasets/upload/loaders/xview_detection.py +1 -1
- clarifai_utils/models/model_serving/README.md +3 -3
- clarifai_utils/models/model_serving/cli/deploy_cli.py +2 -3
- clarifai_utils/models/model_serving/cli/repository.py +3 -5
- clarifai_utils/models/model_serving/constants.py +1 -5
- clarifai_utils/models/model_serving/docs/custom_config.md +5 -6
- clarifai_utils/models/model_serving/docs/dependencies.md +5 -10
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/requirements.txt +1 -0
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/requirements.txt +1 -0
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/requirements.txt +1 -0
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/requirements.txt +1 -0
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/requirements.txt +1 -1
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/requirements.txt +1 -0
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/requirements.txt +1 -0
- clarifai_utils/models/model_serving/model_config/__init__.py +2 -0
- clarifai_utils/models/model_serving/model_config/config.py +298 -0
- clarifai_utils/models/model_serving/model_config/model_types_config/text-classifier.yaml +18 -0
- clarifai_utils/models/model_serving/model_config/model_types_config/text-embedder.yaml +18 -0
- clarifai_utils/models/model_serving/model_config/model_types_config/text-to-image.yaml +18 -0
- clarifai_utils/models/model_serving/model_config/model_types_config/text-to-text.yaml +18 -0
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-classifier.yaml +18 -0
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-detector.yaml +28 -0
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-embedder.yaml +18 -0
- clarifai_utils/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +18 -0
- clarifai_utils/models/model_serving/model_config/serializer.py +1 -1
- clarifai_utils/models/model_serving/models/default_test.py +22 -21
- clarifai_utils/models/model_serving/models/output.py +2 -2
- clarifai_utils/models/model_serving/pb_model_repository.py +2 -5
- clarifai_utils/runners/__init__.py +0 -0
- clarifai_utils/runners/example.py +33 -0
- clarifai_utils/schema/search.py +60 -0
- clarifai_utils/utils/logging.py +53 -3
- clarifai_utils/versions.py +1 -1
- clarifai_utils/workflows/__init__.py +0 -0
- clarifai_utils/workflows/export.py +68 -0
- clarifai_utils/workflows/utils.py +59 -0
- clarifai_utils/workflows/validate.py +67 -0
- clarifai/models/model_serving/envs/triton_conda-cp3.8-torch1.13.1-19f97078.yaml +0 -35
- clarifai/models/model_serving/envs/triton_conda-cp3.8-torch2.0.0-ce980f28.yaml +0 -51
- clarifai/models/model_serving/examples/image_classification/age_vit/triton_conda.yaml +0 -1
- clarifai/models/model_serving/examples/text_classification/xlm-roberta/triton_conda.yaml +0 -1
- clarifai/models/model_serving/examples/text_to_image/sd-v1.5/triton_conda.yaml +0 -1
- clarifai/models/model_serving/examples/text_to_text/bart-summarize/triton_conda.yaml +0 -1
- clarifai/models/model_serving/examples/visual_detection/yolov5x/triton_conda.yaml +0 -1
- clarifai/models/model_serving/examples/visual_embedding/vit-base/triton_conda.yaml +0 -1
- clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/triton_conda.yaml +0 -1
- clarifai/models/model_serving/model_config/deploy.py +0 -75
- clarifai/models/model_serving/model_config/triton_config.py +0 -226
- clarifai_utils/models/model_serving/envs/triton_conda-cp3.8-torch1.13.1-19f97078.yaml +0 -35
- clarifai_utils/models/model_serving/envs/triton_conda-cp3.8-torch2.0.0-ce980f28.yaml +0 -51
- clarifai_utils/models/model_serving/examples/image_classification/age_vit/triton_conda.yaml +0 -1
- clarifai_utils/models/model_serving/examples/text_classification/xlm-roberta/triton_conda.yaml +0 -1
- clarifai_utils/models/model_serving/examples/text_to_image/sd-v1.5/triton_conda.yaml +0 -1
- clarifai_utils/models/model_serving/examples/text_to_text/bart-summarize/triton_conda.yaml +0 -1
- clarifai_utils/models/model_serving/examples/visual_detection/yolov5x/triton_conda.yaml +0 -1
- clarifai_utils/models/model_serving/examples/visual_embedding/vit-base/triton_conda.yaml +0 -1
- clarifai_utils/models/model_serving/examples/visual_segmentation/segformer-b2/triton_conda.yaml +0 -1
- clarifai_utils/models/model_serving/model_config/deploy.py +0 -75
- clarifai_utils/models/model_serving/model_config/triton_config.py +0 -226
- {clarifai-9.8.1.dist-info → clarifai-9.9.0.dist-info}/LICENSE +0 -0
- {clarifai-9.8.1.dist-info → clarifai-9.9.0.dist-info}/WHEEL +0 -0
- {clarifai-9.8.1.dist-info → clarifai-9.9.0.dist-info}/entry_points.txt +0 -0
- {clarifai-9.8.1.dist-info → clarifai-9.9.0.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
from schema import And, Optional, Regex, Schema
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def get_schema() -> Schema:
|
|
5
|
+
"""Initialize the schema for rank and filter.
|
|
6
|
+
|
|
7
|
+
This schema validates:
|
|
8
|
+
|
|
9
|
+
- Rank and filter must be a list
|
|
10
|
+
- Each item in the list must be a dict
|
|
11
|
+
- The dict can contain these optional keys:
|
|
12
|
+
- 'image_url': Valid URL string
|
|
13
|
+
- 'text_raw': Non-empty string
|
|
14
|
+
- 'metadata': Dict
|
|
15
|
+
- 'image_bytes': Bytes
|
|
16
|
+
- 'geo_point': Dict with 'longitude', 'latitude' and 'geo_limit' as float, float and int respectively
|
|
17
|
+
- 'concepts': List where each item is a concept dict
|
|
18
|
+
- Concept dict requires at least one of:
|
|
19
|
+
- 'name': Non-empty string with dashes/underscores
|
|
20
|
+
- 'id': Non-empty string
|
|
21
|
+
- 'language': Non-empty string
|
|
22
|
+
- 'value': 0 or 1 integer
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
Schema: The schema for rank and filter.
|
|
26
|
+
"""
|
|
27
|
+
# Schema for a single concept
|
|
28
|
+
concept_schema = Schema({
|
|
29
|
+
Optional('value'):
|
|
30
|
+
And(int, lambda x: x in [0, 1]),
|
|
31
|
+
Optional('id'):
|
|
32
|
+
And(str, len),
|
|
33
|
+
Optional('language'):
|
|
34
|
+
And(str, len),
|
|
35
|
+
# Non-empty strings with internal dashes and underscores.
|
|
36
|
+
Optional('name'):
|
|
37
|
+
And(str, len, Regex(r'^[0-9A-Za-z]+([-_][0-9A-Za-z]+)*$'))
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
# Schema for a rank or filter item
|
|
41
|
+
rank_filter_item_schema = Schema({
|
|
42
|
+
Optional('image_url'):
|
|
43
|
+
And(str, Regex(r'^https?://')),
|
|
44
|
+
Optional('text_raw'):
|
|
45
|
+
And(str, len),
|
|
46
|
+
Optional('metadata'):
|
|
47
|
+
dict,
|
|
48
|
+
Optional('image_bytes'):
|
|
49
|
+
bytes,
|
|
50
|
+
Optional('geo_point'): {
|
|
51
|
+
'longitude': float,
|
|
52
|
+
'latitude': float,
|
|
53
|
+
'geo_limit': int
|
|
54
|
+
},
|
|
55
|
+
Optional("concepts"):
|
|
56
|
+
And(list, lambda x: all(concept_schema.is_valid(item) and len(item) > 0 for item in x)),
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
# Schema for rank and filter args
|
|
60
|
+
return Schema([rank_filter_item_schema])
|
clarifai_utils/utils/logging.py
CHANGED
|
@@ -1,16 +1,66 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
from
|
|
2
|
+
from collections import defaultdict
|
|
3
|
+
from typing import Dict, List, Optional
|
|
3
4
|
|
|
5
|
+
from rich import print as rprint
|
|
4
6
|
from rich.logging import RichHandler
|
|
5
7
|
from rich.table import Table
|
|
6
8
|
from rich.traceback import install
|
|
9
|
+
from rich.tree import Tree
|
|
7
10
|
|
|
8
11
|
install()
|
|
9
12
|
|
|
10
13
|
|
|
11
|
-
def
|
|
14
|
+
def display_workflow_tree(nodes_data: List[Dict]) -> None:
|
|
15
|
+
"""Displays a tree of the workflow nodes."""
|
|
16
|
+
# Create a mapping of node_id to the list of node_ids that are connected to it.
|
|
17
|
+
node_adj_mapping = defaultdict(list)
|
|
18
|
+
# Create a mapping of node_id to the node data info.
|
|
19
|
+
nodes_data_dict = {}
|
|
20
|
+
for node in nodes_data:
|
|
21
|
+
nodes_data_dict[node["id"]] = node
|
|
22
|
+
if node.get("node_inputs", "") == "":
|
|
23
|
+
node_adj_mapping["Input"].append(node["id"])
|
|
24
|
+
else:
|
|
25
|
+
for node_input in node["node_inputs"]:
|
|
26
|
+
node_adj_mapping[node_input["node_id"]].append(node["id"])
|
|
27
|
+
|
|
28
|
+
# Get all leaf nodes.
|
|
29
|
+
leaf_node_ids = set()
|
|
30
|
+
for node_id in list(nodes_data_dict.keys()):
|
|
31
|
+
if node_adj_mapping.get(node_id, "") == "":
|
|
32
|
+
leaf_node_ids.add(node_id)
|
|
33
|
+
|
|
34
|
+
def build_node_tree(node_id="Input"):
|
|
35
|
+
"""Recursively builds a rich tree of the workflow nodes."""
|
|
36
|
+
# Set the style of the current node.
|
|
37
|
+
style_str = "green" if node_id in leaf_node_ids else "white"
|
|
38
|
+
|
|
39
|
+
# Create a Tree object for the current node.
|
|
40
|
+
if node_id != "Input":
|
|
41
|
+
node_table = table_from_dict(
|
|
42
|
+
[nodes_data_dict[node_id]["model"]],
|
|
43
|
+
column_names=["id", "model_type_id", "app_id", "user_id"],
|
|
44
|
+
title="Node: " + node_id)
|
|
45
|
+
|
|
46
|
+
tree = Tree(node_table, style=style_str, guide_style="underline2 white")
|
|
47
|
+
else:
|
|
48
|
+
tree = Tree(f"[green] {node_id}", style=style_str, guide_style="underline2 white")
|
|
49
|
+
|
|
50
|
+
# Recursively add the child nodes of the current node to the tree.
|
|
51
|
+
for child in node_adj_mapping.get(node_id, []):
|
|
52
|
+
tree.add(build_node_tree(child))
|
|
53
|
+
|
|
54
|
+
# Return the tree.
|
|
55
|
+
return tree
|
|
56
|
+
|
|
57
|
+
tree = build_node_tree("Input")
|
|
58
|
+
rprint(tree)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def table_from_dict(data: List[Dict], column_names: List[str], title: str = "") -> Table:
|
|
12
62
|
"""Use this function for printing tables from a list of dicts."""
|
|
13
|
-
table = Table(title=title, show_header=True, header_style="
|
|
63
|
+
table = Table(title=title, show_lines=False, show_header=True, header_style="blue")
|
|
14
64
|
for column_name in column_names:
|
|
15
65
|
table.add_column(column_name)
|
|
16
66
|
for row in data:
|
clarifai_utils/versions.py
CHANGED
|
File without changes
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
from typing import Any, Dict
|
|
2
|
+
|
|
3
|
+
import yaml
|
|
4
|
+
from google.protobuf.json_format import MessageToDict
|
|
5
|
+
|
|
6
|
+
VALID_YAML_KEYS = ["workflow", "id", "nodes", "node_inputs", "node_id", "model"]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def clean_up_unused_keys(wf: dict):
|
|
10
|
+
"""Removes unused keys from dict before exporting to yaml. Supports nested dicts."""
|
|
11
|
+
new_wf = dict()
|
|
12
|
+
for key, val in wf.items():
|
|
13
|
+
if key not in VALID_YAML_KEYS:
|
|
14
|
+
continue
|
|
15
|
+
if key == "model":
|
|
16
|
+
new_wf["model"] = {
|
|
17
|
+
"model_id": wf["model"]["id"],
|
|
18
|
+
"model_version_id": wf["model"]["model_version"]["id"]
|
|
19
|
+
}
|
|
20
|
+
# If the model is not from clarifai main, add the app_id and user_id to the model dict.
|
|
21
|
+
if wf["model"]["user_id"] != "clarifai" and wf["model"]["app_id"] != "main":
|
|
22
|
+
new_wf["model"].update({
|
|
23
|
+
"app_id": wf["model"]["app_id"],
|
|
24
|
+
"user_id": wf["model"]["user_id"]
|
|
25
|
+
})
|
|
26
|
+
elif isinstance(val, dict):
|
|
27
|
+
new_wf[key] = clean_up_unused_keys(val)
|
|
28
|
+
elif isinstance(val, list):
|
|
29
|
+
new_list = []
|
|
30
|
+
for i in val:
|
|
31
|
+
new_list.append(clean_up_unused_keys(i))
|
|
32
|
+
new_wf[key] = new_list
|
|
33
|
+
else:
|
|
34
|
+
new_wf[key] = val
|
|
35
|
+
return new_wf
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class Exporter:
|
|
39
|
+
|
|
40
|
+
def __init__(self, workflow):
|
|
41
|
+
self.wf = workflow
|
|
42
|
+
|
|
43
|
+
def __enter__(self):
|
|
44
|
+
return self
|
|
45
|
+
|
|
46
|
+
def parse(self) -> Dict[str, Any]:
|
|
47
|
+
"""Reads a resources_pb2.Workflow object (e.g. from a GetWorkflow response)
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
dict: A dict representation of the workflow.
|
|
51
|
+
"""
|
|
52
|
+
if isinstance(self.wf, list):
|
|
53
|
+
self.wf = self.wf[0]
|
|
54
|
+
wf = {"workflow": MessageToDict(self.wf, preserving_proto_field_name=True)}
|
|
55
|
+
clean_wf = clean_up_unused_keys(wf)
|
|
56
|
+
self.wf_dict = clean_wf
|
|
57
|
+
return clean_wf
|
|
58
|
+
|
|
59
|
+
def export(self, out_path):
|
|
60
|
+
with open(out_path, 'w') as out_file:
|
|
61
|
+
yaml.dump(self.wf_dict["workflow"], out_file, default_flow_style=False)
|
|
62
|
+
|
|
63
|
+
def __exit__(self, *args):
|
|
64
|
+
self.close()
|
|
65
|
+
|
|
66
|
+
def close(self):
|
|
67
|
+
del self.wf
|
|
68
|
+
del self.wf_dict
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from typing import Dict, Optional, Set
|
|
2
|
+
|
|
3
|
+
from clarifai_grpc.grpc.api import resources_pb2
|
|
4
|
+
from google.protobuf import struct_pb2
|
|
5
|
+
from google.protobuf.json_format import MessageToDict
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_yaml_output_info_proto(yaml_model_output_info: Dict) -> Optional[resources_pb2.OutputInfo]:
|
|
9
|
+
"""Converts a yaml model output info to an api model output info."""
|
|
10
|
+
if not yaml_model_output_info:
|
|
11
|
+
return None
|
|
12
|
+
|
|
13
|
+
return resources_pb2.OutputInfo(
|
|
14
|
+
params=convert_yaml_params_to_api_params(yaml_model_output_info.get('params')))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def convert_yaml_params_to_api_params(yaml_params: Dict) -> Optional[struct_pb2.Struct]:
|
|
18
|
+
"""Converts a yaml model output info params to an api model output info params."""
|
|
19
|
+
if not yaml_params:
|
|
20
|
+
return None
|
|
21
|
+
|
|
22
|
+
s = struct_pb2.Struct()
|
|
23
|
+
s.update(yaml_params)
|
|
24
|
+
|
|
25
|
+
return s
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def is_same_yaml_model(api_model: resources_pb2.Model, yaml_model: Dict) -> bool:
|
|
29
|
+
"""Compares a model from the API with a model from a yaml file."""
|
|
30
|
+
api_model = MessageToDict(api_model, preserving_proto_field_name=True)
|
|
31
|
+
|
|
32
|
+
yaml_model_from_api = dict()
|
|
33
|
+
for k, _ in yaml_model.items():
|
|
34
|
+
if k == "output_info" and api_model["model_version"].get("output_info", "") != "":
|
|
35
|
+
yaml_model_from_api[k] = dict(params=api_model["model_version"]["output_info"].get("params"))
|
|
36
|
+
else:
|
|
37
|
+
yaml_model_from_api[k] = api_model.get(k)
|
|
38
|
+
yaml_model_from_api.update({"model_id": api_model.get("id")})
|
|
39
|
+
|
|
40
|
+
ignore_keys = {}
|
|
41
|
+
|
|
42
|
+
return is_dict_in_dict(yaml_model, yaml_model_from_api, ignore_keys)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def is_dict_in_dict(d1: Dict, d2: Dict, ignore_keys: Set = None) -> bool:
|
|
46
|
+
"""Compares two dicts recursively."""
|
|
47
|
+
for k, v in d1.items():
|
|
48
|
+
if ignore_keys and k in ignore_keys:
|
|
49
|
+
continue
|
|
50
|
+
if k not in d2:
|
|
51
|
+
return False
|
|
52
|
+
if isinstance(v, dict):
|
|
53
|
+
if not isinstance(d2[k], dict):
|
|
54
|
+
return False
|
|
55
|
+
return is_dict_in_dict(d1[k], d2[k], None)
|
|
56
|
+
elif v != d2[k]:
|
|
57
|
+
return False
|
|
58
|
+
|
|
59
|
+
return True
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from schema import And, Optional, Regex, Schema, SchemaError, Use
|
|
2
|
+
|
|
3
|
+
# Non-empty, up to 32-character ASCII strings with internal dashes and underscores.
|
|
4
|
+
_id_validator = And(str, lambda s: 0 < len(s) <= 48, Regex(r'^[0-9A-Za-z]+([-_][0-9A-Za-z]+)*$'))
|
|
5
|
+
|
|
6
|
+
# 32-character hex string, converted to lower-case.
|
|
7
|
+
_hex_id_validator = And(str, Use(str.lower), Regex(r'^[0-9a-f]{32}'))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _model_does_not_have_model_version_id_and_other_fields(m):
|
|
11
|
+
""" Validate that model does not have model_version_id and other model fields."""
|
|
12
|
+
if ('model_version_id' in m) and _model_has_other_fields(m):
|
|
13
|
+
raise SchemaError(f"model should not set model_version_id and other model fields: {m};"
|
|
14
|
+
f" please remove model_version_id or other model fields.")
|
|
15
|
+
return True
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _model_has_other_fields(m):
|
|
19
|
+
return any(k not in ['model_id', 'model_version_id'] for k in m.keys())
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _workflow_nodes_have_valid_dependencies(nodes):
|
|
23
|
+
"""Validate that all inputs to a node are declared before it."""
|
|
24
|
+
node_ids = set()
|
|
25
|
+
for node in nodes:
|
|
26
|
+
for node_input in node.get("node_inputs", []):
|
|
27
|
+
if node_input["node_id"] not in node_ids:
|
|
28
|
+
raise SchemaError(f"missing input '{node_input['node_id']}' for node '{node['id']}'")
|
|
29
|
+
node_ids.add(node["id"])
|
|
30
|
+
|
|
31
|
+
return True
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
_data_schema = Schema({
|
|
35
|
+
"workflow": {
|
|
36
|
+
"id":
|
|
37
|
+
_id_validator,
|
|
38
|
+
"nodes":
|
|
39
|
+
And(
|
|
40
|
+
len,
|
|
41
|
+
[{
|
|
42
|
+
"id":
|
|
43
|
+
And(str, len), # Node IDs are not validated as IDs by the API.
|
|
44
|
+
"model":
|
|
45
|
+
And({
|
|
46
|
+
"model_id": _id_validator,
|
|
47
|
+
Optional("app_id"): _id_validator,
|
|
48
|
+
Optional("user_id"): _id_validator,
|
|
49
|
+
Optional("model_version_id"): _hex_id_validator,
|
|
50
|
+
Optional("model_type_id"): _id_validator,
|
|
51
|
+
Optional("description"): str,
|
|
52
|
+
Optional("output_info"): {
|
|
53
|
+
Optional("params"): dict,
|
|
54
|
+
},
|
|
55
|
+
}, _model_does_not_have_model_version_id_and_other_fields),
|
|
56
|
+
Optional("node_inputs"):
|
|
57
|
+
And(len, [{
|
|
58
|
+
"node_id": And(str, len),
|
|
59
|
+
}]),
|
|
60
|
+
}],
|
|
61
|
+
_workflow_nodes_have_valid_dependencies),
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def validate(data):
|
|
67
|
+
return _data_schema.validate(data)
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch1.13.1-19f97078
|
|
2
|
-
channels:
|
|
3
|
-
- conda-forge
|
|
4
|
-
dependencies:
|
|
5
|
-
- _libgcc_mutex=0.1=conda_forge
|
|
6
|
-
- _openmp_mutex=4.5=2_gnu
|
|
7
|
-
- bzip2=1.0.8=h7f98852_4
|
|
8
|
-
- ca-certificates=2022.12.7=ha878542_0
|
|
9
|
-
- ld_impl_linux-64=2.40=h41732ed_0
|
|
10
|
-
- libffi=3.4.2=h7f98852_5
|
|
11
|
-
- libgcc-ng=12.2.0=h65d4601_19
|
|
12
|
-
- libgomp=12.2.0=h65d4601_19
|
|
13
|
-
- libnsl=2.0.0=h7f98852_0
|
|
14
|
-
- libsqlite=3.40.0=h753d276_0
|
|
15
|
-
- libuuid=2.32.1=h7f98852_1000
|
|
16
|
-
- libzlib=1.2.13=h166bdaf_4
|
|
17
|
-
- ncurses=6.3=h27087fc_1
|
|
18
|
-
- openssl=3.0.8=h0b41bf4_0
|
|
19
|
-
- pip=23.0.1=pyhd8ed1ab_0
|
|
20
|
-
- python=3.8.16=he550d4f_1_cpython
|
|
21
|
-
- readline=8.1.2=h0f457ee_0
|
|
22
|
-
- setuptools=67.4.0=pyhd8ed1ab_0
|
|
23
|
-
- tk=8.6.12=h27826a3_0
|
|
24
|
-
- wheel=0.38.4=pyhd8ed1ab_0
|
|
25
|
-
- xz=5.2.6=h166bdaf_0
|
|
26
|
-
- pip:
|
|
27
|
-
- numpy==1.24.2
|
|
28
|
-
- nvidia-cublas-cu11==11.10.3.66
|
|
29
|
-
- nvidia-cuda-nvrtc-cu11==11.7.99
|
|
30
|
-
- nvidia-cuda-runtime-cu11==11.7.99
|
|
31
|
-
- nvidia-cudnn-cu11==8.5.0.96
|
|
32
|
-
- opencv-python==4.7.0.72
|
|
33
|
-
- pillow==9.4.0
|
|
34
|
-
- torch==1.13.1
|
|
35
|
-
- typing-extensions==4.5.0
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch2.0.0-ce980f28
|
|
2
|
-
channels:
|
|
3
|
-
- conda-forge
|
|
4
|
-
dependencies:
|
|
5
|
-
- _libgcc_mutex=0.1=conda_forge
|
|
6
|
-
- _openmp_mutex=4.5=2_gnu
|
|
7
|
-
- bzip2=1.0.8=h7f98852_4
|
|
8
|
-
- ca-certificates=2023.5.7=hbcca054_0
|
|
9
|
-
- ld_impl_linux-64=2.40=h41732ed_0
|
|
10
|
-
- libffi=3.4.2=h7f98852_5
|
|
11
|
-
- libgcc-ng=13.1.0=he5830b7_0
|
|
12
|
-
- libgomp=13.1.0=he5830b7_0
|
|
13
|
-
- libnsl=2.0.0=h7f98852_0
|
|
14
|
-
- libsqlite=3.42.0=h2797004_0
|
|
15
|
-
- libuuid=2.38.1=h0b41bf4_0
|
|
16
|
-
- libzlib=1.2.13=hd590300_5
|
|
17
|
-
- ncurses=6.4=hcb278e6_0
|
|
18
|
-
- openssl=3.1.1=hd590300_1
|
|
19
|
-
- pip=23.1.2=pyhd8ed1ab_0
|
|
20
|
-
- python=3.8.17=he550d4f_0_cpython
|
|
21
|
-
- readline=8.2=h8228510_1
|
|
22
|
-
- setuptools=68.0.0=pyhd8ed1ab_0
|
|
23
|
-
- tk=8.6.12=h27826a3_0
|
|
24
|
-
- wheel=0.40.0=pyhd8ed1ab_0
|
|
25
|
-
- xz=5.2.6=h166bdaf_0
|
|
26
|
-
- pip:
|
|
27
|
-
- cmake==3.26.4
|
|
28
|
-
- filelock==3.12.2
|
|
29
|
-
- jinja2==3.1.2
|
|
30
|
-
- lit==16.0.6
|
|
31
|
-
- markupsafe==2.1.3
|
|
32
|
-
- mpmath==1.3.0
|
|
33
|
-
- networkx==3.1
|
|
34
|
-
- numpy==1.24.2
|
|
35
|
-
- nvidia-cublas-cu11==11.10.3.66
|
|
36
|
-
- nvidia-cuda-cupti-cu11==11.7.101
|
|
37
|
-
- nvidia-cuda-nvrtc-cu11==11.7.99
|
|
38
|
-
- nvidia-cuda-runtime-cu11==11.7.99
|
|
39
|
-
- nvidia-cudnn-cu11==8.5.0.96
|
|
40
|
-
- nvidia-cufft-cu11==10.9.0.58
|
|
41
|
-
- nvidia-curand-cu11==10.2.10.91
|
|
42
|
-
- nvidia-cusolver-cu11==11.4.0.1
|
|
43
|
-
- nvidia-cusparse-cu11==11.7.4.91
|
|
44
|
-
- nvidia-nccl-cu11==2.14.3
|
|
45
|
-
- nvidia-nvtx-cu11==11.7.91
|
|
46
|
-
- opencv-python==4.7.0.72
|
|
47
|
-
- pillow==9.4.0
|
|
48
|
-
- sympy==1.12
|
|
49
|
-
- torch==2.0.0
|
|
50
|
-
- triton==2.0.0
|
|
51
|
-
- typing-extensions==4.5.0
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch1.13.1-19f97078
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch1.13.1-19f97078
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch1.13.1-19f97078
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch1.13.1-19f97078
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch1.13.1-19f97078
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch1.13.1-19f97078
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
name: triton_conda-cp3.8-torch1.13.1-19f97078
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Copyright 2023 Clarifai, Inc.
|
|
2
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
# you may not use this file except in compliance with the License.
|
|
4
|
-
# You may obtain a copy of the License at
|
|
5
|
-
#
|
|
6
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
#
|
|
8
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
# See the License for the specific language governing permissions and
|
|
12
|
-
# limitations under the License.
|
|
13
|
-
"""Triton Model Config classes."""
|
|
14
|
-
|
|
15
|
-
from dataclasses import dataclass, field
|
|
16
|
-
from typing import List
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@dataclass
|
|
20
|
-
class ClarifaiFieldsMap:
|
|
21
|
-
"""
|
|
22
|
-
Triton Model Config base.
|
|
23
|
-
Params:
|
|
24
|
-
-------
|
|
25
|
-
model_type
|
|
26
|
-
|
|
27
|
-
Returns:
|
|
28
|
-
--------
|
|
29
|
-
ClarifaiFieldsMap
|
|
30
|
-
"""
|
|
31
|
-
model_type: str
|
|
32
|
-
input_fields_map: List = field(default_factory=list)
|
|
33
|
-
output_fields_map: List = field(default_factory=list)
|
|
34
|
-
|
|
35
|
-
def __post_init__(self):
|
|
36
|
-
"""
|
|
37
|
-
Set mapping of clarifai in/output vs triton in/output
|
|
38
|
-
"""
|
|
39
|
-
text_input_fields = {"text": "text"}
|
|
40
|
-
image_input_fields = {"image": "image"}
|
|
41
|
-
|
|
42
|
-
embedding_output_fields = {"embeddings": "embeddings"}
|
|
43
|
-
|
|
44
|
-
if self.model_type == "visual-detector":
|
|
45
|
-
self.input_fields_map = image_input_fields
|
|
46
|
-
self.output_fields_map = {
|
|
47
|
-
"regions[...].region_info.bounding_box": "predicted_bboxes",
|
|
48
|
-
"regions[...].data.concepts[...].id": "predicted_labels",
|
|
49
|
-
"regions[...].data.concepts[...].value": "predicted_scores"
|
|
50
|
-
}
|
|
51
|
-
elif self.model_type == "visual-classifier":
|
|
52
|
-
self.input_fields_map = image_input_fields
|
|
53
|
-
self.output_fields_map = {"concepts": "softmax_predictions"}
|
|
54
|
-
elif self.model_type == "text-classifier":
|
|
55
|
-
self.input_fields_map = text_input_fields
|
|
56
|
-
self.output_fields_map = {"concepts": "softmax_predictions"}
|
|
57
|
-
elif self.model_type == "text-embedder":
|
|
58
|
-
self.input_fields_map = text_input_fields
|
|
59
|
-
self.output_fields_map = embedding_output_fields
|
|
60
|
-
elif self.model_type == "text-to-text":
|
|
61
|
-
self.input_fields_map = text_input_fields
|
|
62
|
-
# input and output fields are the same for text-to-text
|
|
63
|
-
self.output_fields_map = text_input_fields
|
|
64
|
-
elif self.model_type == "text-to-image":
|
|
65
|
-
self.input_fields_map = text_input_fields
|
|
66
|
-
# image output fields match image_input fields
|
|
67
|
-
self.output_fields_map = image_input_fields
|
|
68
|
-
elif self.model_type == "visual-embedder":
|
|
69
|
-
self.input_fields_map = image_input_fields
|
|
70
|
-
self.output_fields_map = embedding_output_fields
|
|
71
|
-
elif self.model_type == "visual-segmenter":
|
|
72
|
-
self.input_fields_map = image_input_fields
|
|
73
|
-
self.output_fields_map = {
|
|
74
|
-
"regions[...].region_info.mask,regions[...].data.concepts": "predicted_mask"
|
|
75
|
-
}
|