clarifai 9.11.1__py3-none-any.whl → 10.0.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.
Files changed (99) hide show
  1. clarifai/client/input.py +34 -1
  2. clarifai/client/workflow.py +6 -2
  3. clarifai/constants/rag.py +1 -0
  4. clarifai/models/model_serving/README.md +1 -1
  5. clarifai/models/model_serving/models/default_test.py +3 -0
  6. clarifai/rag/__init__.py +3 -0
  7. clarifai/rag/rag.py +261 -0
  8. clarifai/rag/utils.py +102 -0
  9. clarifai/versions.py +1 -1
  10. {clarifai-9.11.1.dist-info → clarifai-10.0.0.dist-info}/METADATA +16 -3
  11. clarifai-10.0.0.dist-info/RECORD +103 -0
  12. clarifai/models/model_serving/examples/README.md +0 -7
  13. clarifai/models/model_serving/examples/image_classification/README.md +0 -12
  14. clarifai/models/model_serving/examples/image_classification/age_vit/1/__init__.py +0 -0
  15. clarifai/models/model_serving/examples/image_classification/age_vit/1/inference.py +0 -64
  16. clarifai/models/model_serving/examples/image_classification/age_vit/1/model.py +0 -74
  17. clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/README.md +0 -11
  18. clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/config.json +0 -42
  19. clarifai/models/model_serving/examples/image_classification/age_vit/1/vit-age-classifier/preprocessor_config.json +0 -15
  20. clarifai/models/model_serving/examples/image_classification/age_vit/config.pbtxt +0 -23
  21. clarifai/models/model_serving/examples/image_classification/age_vit/labels.txt +0 -9
  22. clarifai/models/model_serving/examples/image_classification/age_vit/requirements.txt +0 -7
  23. clarifai/models/model_serving/examples/multimodal_embedder/README.md +0 -12
  24. clarifai/models/model_serving/examples/multimodal_embedder/clip/1/__init__.py +0 -0
  25. clarifai/models/model_serving/examples/multimodal_embedder/clip/1/inference.py +0 -66
  26. clarifai/models/model_serving/examples/multimodal_embedder/clip/1/model.py +0 -74
  27. clarifai/models/model_serving/examples/multimodal_embedder/clip/1/test.py +0 -64
  28. clarifai/models/model_serving/examples/multimodal_embedder/clip/config.pbtxt +0 -29
  29. clarifai/models/model_serving/examples/multimodal_embedder/clip/requirements.txt +0 -4
  30. clarifai/models/model_serving/examples/text_classification/README.md +0 -12
  31. clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/__init__.py +0 -0
  32. clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/inference.py +0 -62
  33. clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/model.py +0 -74
  34. clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/README.md +0 -12
  35. clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/config.json +0 -34
  36. clarifai/models/model_serving/examples/text_classification/xlm-roberta/1/twitter-xlm-roberta-base-sentiment/special_tokens_map.json +0 -1
  37. clarifai/models/model_serving/examples/text_classification/xlm-roberta/config.pbtxt +0 -21
  38. clarifai/models/model_serving/examples/text_classification/xlm-roberta/labels.txt +0 -3
  39. clarifai/models/model_serving/examples/text_classification/xlm-roberta/requirements.txt +0 -7
  40. clarifai/models/model_serving/examples/text_embedding/README.md +0 -12
  41. clarifai/models/model_serving/examples/text_embedding/instructor-xl/1/__init__.py +0 -0
  42. clarifai/models/model_serving/examples/text_embedding/instructor-xl/1/inference.py +0 -63
  43. clarifai/models/model_serving/examples/text_embedding/instructor-xl/1/model.py +0 -74
  44. clarifai/models/model_serving/examples/text_embedding/instructor-xl/1/test.py +0 -64
  45. clarifai/models/model_serving/examples/text_embedding/instructor-xl/config.pbtxt +0 -20
  46. clarifai/models/model_serving/examples/text_embedding/instructor-xl/requirements.txt +0 -9
  47. clarifai/models/model_serving/examples/text_to_image/README.md +0 -10
  48. clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/__init__.py +0 -0
  49. clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/inference.py +0 -58
  50. clarifai/models/model_serving/examples/text_to_image/sd-v1.5/1/model.py +0 -74
  51. clarifai/models/model_serving/examples/text_to_image/sd-v1.5/config.pbtxt +0 -22
  52. clarifai/models/model_serving/examples/text_to_image/sd-v1.5/requirements.txt +0 -6
  53. clarifai/models/model_serving/examples/text_to_text/README.md +0 -12
  54. clarifai/models/model_serving/examples/text_to_text/bart-summarize/1/__init__.py +0 -0
  55. clarifai/models/model_serving/examples/text_to_text/bart-summarize/1/inference.py +0 -59
  56. clarifai/models/model_serving/examples/text_to_text/bart-summarize/1/model.py +0 -74
  57. clarifai/models/model_serving/examples/text_to_text/bart-summarize/config.pbtxt +0 -20
  58. clarifai/models/model_serving/examples/text_to_text/bart-summarize/requirements.txt +0 -4
  59. clarifai/models/model_serving/examples/visual_detection/Readme.md +0 -61
  60. clarifai/models/model_serving/examples/visual_detection/faster-rcnn_torchserve/1/inference.py +0 -96
  61. clarifai/models/model_serving/examples/visual_detection/faster-rcnn_torchserve/1/model.py +0 -74
  62. clarifai/models/model_serving/examples/visual_detection/faster-rcnn_torchserve/1/model_store/hub/checkpoints/keep +0 -0
  63. clarifai/models/model_serving/examples/visual_detection/faster-rcnn_torchserve/1/test.py +0 -62
  64. clarifai/models/model_serving/examples/visual_detection/faster-rcnn_torchserve/config.pbtxt +0 -35
  65. clarifai/models/model_serving/examples/visual_detection/faster-rcnn_torchserve/labels.txt +0 -80
  66. clarifai/models/model_serving/examples/visual_detection/faster-rcnn_torchserve/requirements.txt +0 -3
  67. clarifai/models/model_serving/examples/visual_detection/yolof/1/config/yolof_r50_c5_8x8_1x_coco.py +0 -245
  68. clarifai/models/model_serving/examples/visual_detection/yolof/1/inference.py +0 -90
  69. clarifai/models/model_serving/examples/visual_detection/yolof/1/model.py +0 -74
  70. clarifai/models/model_serving/examples/visual_detection/yolof/1/test.py +0 -64
  71. clarifai/models/model_serving/examples/visual_detection/yolof/config.pbtxt +0 -36
  72. clarifai/models/model_serving/examples/visual_detection/yolof/labels.txt +0 -80
  73. clarifai/models/model_serving/examples/visual_detection/yolof/requirements.txt +0 -8
  74. clarifai/models/model_serving/examples/visual_embedding/README.md +0 -12
  75. clarifai/models/model_serving/examples/visual_embedding/vit-base/1/__init__.py +0 -0
  76. clarifai/models/model_serving/examples/visual_embedding/vit-base/1/inference.py +0 -56
  77. clarifai/models/model_serving/examples/visual_embedding/vit-base/1/model.py +0 -74
  78. clarifai/models/model_serving/examples/visual_embedding/vit-base/config.pbtxt +0 -22
  79. clarifai/models/model_serving/examples/visual_embedding/vit-base/requirements.txt +0 -5
  80. clarifai/models/model_serving/examples/visual_segmentation/README.md +0 -12
  81. clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/1/__init__.py +0 -0
  82. clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/1/inference.py +0 -62
  83. clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/1/model.py +0 -74
  84. clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/config.pbtxt +0 -24
  85. clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/labels.txt +0 -18
  86. clarifai/models/model_serving/examples/visual_segmentation/segformer-b2/requirements.txt +0 -5
  87. clarifai/models/model_serving/examples/vllm/Readme.md +0 -12
  88. clarifai/models/model_serving/examples/vllm/example/1/__init__.py +0 -0
  89. clarifai/models/model_serving/examples/vllm/example/1/inference.py +0 -56
  90. clarifai/models/model_serving/examples/vllm/example/1/model.py +0 -74
  91. clarifai/models/model_serving/examples/vllm/example/1/test.py +0 -64
  92. clarifai/models/model_serving/examples/vllm/example/1/weights/keep +0 -0
  93. clarifai/models/model_serving/examples/vllm/example/config.pbtxt +0 -20
  94. clarifai/models/model_serving/examples/vllm/example/requirements.txt +0 -5
  95. clarifai-9.11.1.dist-info/RECORD +0 -182
  96. {clarifai-9.11.1.dist-info → clarifai-10.0.0.dist-info}/LICENSE +0 -0
  97. {clarifai-9.11.1.dist-info → clarifai-10.0.0.dist-info}/WHEEL +0 -0
  98. {clarifai-9.11.1.dist-info → clarifai-10.0.0.dist-info}/entry_points.txt +0 -0
  99. {clarifai-9.11.1.dist-info → clarifai-10.0.0.dist-info}/top_level.txt +0 -0
@@ -1,74 +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 inference server Python Backend Model."""
14
-
15
- import os
16
- import sys
17
-
18
- try:
19
- import triton_python_backend_utils as pb_utils
20
- except ModuleNotFoundError:
21
- pass
22
- from google.protobuf import text_format
23
- from tritonclient.grpc.model_config_pb2 import ModelConfig
24
- from clarifai.models.model_serving.model_config.inference_parameter import parse_req_parameters
25
-
26
-
27
- class TritonPythonModel:
28
- """
29
- Triton Python BE Model.
30
- """
31
-
32
- def initialize(self, args):
33
- """
34
- Triton server init.
35
- """
36
- args["model_repository"] = args["model_repository"].replace("/1/model.py", "")
37
- sys.path.append(os.path.dirname(__file__))
38
- from inference import InferenceModel
39
-
40
- self.inference_obj = InferenceModel()
41
-
42
- # Read input_name from config file
43
- self.config_msg = ModelConfig()
44
- with open(os.path.join(args["model_repository"], "config.pbtxt"), "r") as f:
45
- cfg = f.read()
46
- text_format.Merge(cfg, self.config_msg)
47
- self.input_names = [inp.name for inp in self.config_msg.input]
48
-
49
- def execute(self, requests):
50
- """
51
- Serve model inference requests.
52
- """
53
- responses = []
54
-
55
- for request in requests:
56
- parameters = request.parameters()
57
- parameters = parse_req_parameters(parameters) if parameters else {}
58
-
59
- if len(self.input_names) == 1:
60
- in_batch = pb_utils.get_input_tensor_by_name(request, self.input_names[0])
61
- in_batch = in_batch.as_numpy()
62
- inference_response = self.inference_obj.get_predictions(in_batch, **parameters)
63
- else:
64
- multi_in_batch_dict = {}
65
- for input_name in self.input_names:
66
- in_batch = pb_utils.get_input_tensor_by_name(request, input_name)
67
- in_batch = in_batch.as_numpy() if in_batch is not None else []
68
- multi_in_batch_dict.update({input_name: in_batch})
69
-
70
- inference_response = self.inference_obj.get_predictions(multi_in_batch_dict, **parameters)
71
-
72
- responses.append(inference_response)
73
-
74
- return responses
@@ -1,12 +0,0 @@
1
- ---
2
- language: multilingual
3
- ---
4
-
5
-
6
- ## Twitter xlm-roberta-base for sentiment analysis
7
-
8
- This is a multilingual XLM-roBERTa-base model trained on ~198M tweets and finetuned for sentiment analysis. The sentiment fine-tuning was done on 8 languages (Ar, En, Fr, De, Hi, It, Sp, Pt) but it can be used for more languages (see paper for details).
9
-
10
- - Paper: [XLM-T: A Multilingual Language Model Toolkit for Twitter](https://arxiv.org/abs/2104.12250).
11
- - Official Github Repository: [XLM-T official repository](https://github.com/cardiffnlp/xlm-t).
12
- - Sentiment Classes: Negative, Neutral, Positive
@@ -1,34 +0,0 @@
1
- {
2
- "_name_or_path": "/home/jupyter/misc/tweeteval/TweetEval_models/xlm-twitter/local-twitter-xlm-roberta-base-sentiment/",
3
- "architectures": [
4
- "XLMRobertaForSequenceClassification"
5
- ],
6
- "attention_probs_dropout_prob": 0.1,
7
- "bos_token_id": 0,
8
- "eos_token_id": 2,
9
- "gradient_checkpointing": false,
10
- "hidden_act": "gelu",
11
- "hidden_dropout_prob": 0.1,
12
- "hidden_size": 768,
13
- "id2label": {
14
- "0": "negative",
15
- "1": "neutral",
16
- "2": "positive"
17
- },
18
- "initializer_range": 0.02,
19
- "intermediate_size": 3072,
20
- "label2id": {
21
- "negative": 0,
22
- "neutral": 1,
23
- "positive": 2
24
- },
25
- "layer_norm_eps": 1e-05,
26
- "max_position_embeddings": 514,
27
- "model_type": "xlm-roberta",
28
- "num_attention_heads": 12,
29
- "num_hidden_layers": 12,
30
- "output_past": true,
31
- "pad_token_id": 1,
32
- "type_vocab_size": 1,
33
- "vocab_size": 250002
34
- }
@@ -1 +0,0 @@
1
- {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": "<mask>"}
@@ -1,21 +0,0 @@
1
- name: "xlm-roberta"
2
- max_batch_size: 2
3
- input {
4
- name: "text"
5
- data_type: TYPE_STRING
6
- dims: 1
7
- }
8
- output {
9
- name: "softmax_predictions"
10
- data_type: TYPE_FP32
11
- dims: -1
12
- label_filename: "labels.txt"
13
- }
14
- instance_group {
15
- count: 1
16
- kind: KIND_GPU
17
- }
18
- dynamic_batching {
19
- max_queue_delay_microseconds: 500
20
- }
21
- backend: "python"
@@ -1,3 +0,0 @@
1
- Negative
2
- Neutral
3
- Positive
@@ -1,7 +0,0 @@
1
- clarifai>9.10.5
2
- tritonclient[all]
3
- torch==1.13.1
4
- transformers==4.30.2
5
- scipy==1.10.1
6
- sentencepiece==0.1.99
7
- protobuf<4.21.3
@@ -1,12 +0,0 @@
1
- ## Text Embedding Triton Model Examples
2
-
3
- These can be used on the fly with minimal or no changes to test deploy text embedding models to the Clarifai platform. See the required files section for each model below.
4
-
5
- * ### [Instructor-xl](https://huggingface.co/hkunlp/instructor-xl)
6
-
7
- Requirements to run tests locally:
8
-
9
- * Download/Clone the [huggingface model](https://huggingface.co/hkunlp/instructor-xl) into the **instructor-xl/1/** directory then start the triton server.
10
- ```
11
- huggingface-cli download hkunlp/instructor-xl --local-dir instructor-xl/1/checkpoint/sentence_transformers/hkunlp_instructor-xl --local-dir-use-symlinks False
12
- ```
@@ -1,63 +0,0 @@
1
- # This file contains boilerplate code to allow users write their model
2
- # inference code that will then interact with the Triton Inference Server
3
- # Python backend to serve end user requests.
4
- # The module name, module path, class name & get_predictions() method names MUST be maintained as is
5
- # but other methods may be added within the class as deemed fit provided
6
- # they are invoked within the main get_predictions() inference method
7
- # if they play a role in any step of model inference
8
- """User model inference script."""
9
-
10
- import os
11
- from pathlib import Path
12
-
13
- # Set up env for huggingface
14
- ROOT_PATH = os.path.join(os.path.dirname(__file__))
15
- PIPELINE_PATH = os.path.join(ROOT_PATH, 'checkpoint')
16
-
17
- os.environ["TRANSFORMERS_OFFLINE"] = "1" # noqa
18
- os.environ['TRANSFORMERS_CACHE'] = PIPELINE_PATH # noqa
19
- os.environ['TORCH_HOME'] = PIPELINE_PATH
20
-
21
- import torch # noqa
22
- from InstructorEmbedding import INSTRUCTOR # noqa
23
-
24
- from clarifai.models.model_serving.model_config import ( # noqa # pylint: disable=unused-import
25
- ModelTypes, get_model_config)
26
-
27
- config = get_model_config("text-embedder")
28
-
29
-
30
- class InferenceModel:
31
- """User model inference class."""
32
-
33
- def __init__(self) -> None:
34
- """
35
- Load inference time artifacts that are called frequently .e.g. models, tokenizers, etc.
36
- in this method so they are loaded only once for faster inference.
37
- """
38
- self.base_path: Path = os.path.dirname(__file__)
39
- ## sample model loading code:
40
- #self.checkpoint_path: Path = os.path.join(self.base_path, "your checkpoint filename/path")
41
- #self.model: Callable = <load_your_model_here from checkpoint or folder>
42
- self.device = "cuda:0" if torch.cuda.is_available() else "cpu"
43
- self.model = INSTRUCTOR('hkunlp/instructor-xl')
44
-
45
- @config.inference.wrap_func
46
- def get_predictions(self, input_data: list, **kwargs) -> list:
47
- """
48
- Main model inference method.
49
-
50
- Args:
51
- -----
52
- input_data: A list of input data item to predict on.
53
- Input data can be an image or text, etc depending on the model type.
54
-
55
- **kwargs: your inference parameters.
56
-
57
- Returns:
58
- --------
59
- List of one of the `clarifai.models.model_serving.models.output types` or `config.inference.return_type(your_output)`. Refer to the README/docs
60
- """
61
- batch_preds = self.model.encode(input_data, device=self.device)
62
-
63
- return [config.inference.return_type(each) for each in batch_preds]
@@ -1,74 +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 inference server Python Backend Model."""
14
-
15
- import os
16
- import sys
17
-
18
- try:
19
- import triton_python_backend_utils as pb_utils
20
- except ModuleNotFoundError:
21
- pass
22
- from google.protobuf import text_format
23
- from tritonclient.grpc.model_config_pb2 import ModelConfig
24
- from clarifai.models.model_serving.model_config.inference_parameter import parse_req_parameters
25
-
26
-
27
- class TritonPythonModel:
28
- """
29
- Triton Python BE Model.
30
- """
31
-
32
- def initialize(self, args):
33
- """
34
- Triton server init.
35
- """
36
- args["model_repository"] = args["model_repository"].replace("/1/model.py", "")
37
- sys.path.append(os.path.dirname(__file__))
38
- from inference import InferenceModel
39
-
40
- self.inference_obj = InferenceModel()
41
-
42
- # Read input_name from config file
43
- self.config_msg = ModelConfig()
44
- with open(os.path.join(args["model_repository"], "config.pbtxt"), "r") as f:
45
- cfg = f.read()
46
- text_format.Merge(cfg, self.config_msg)
47
- self.input_names = [inp.name for inp in self.config_msg.input]
48
-
49
- def execute(self, requests):
50
- """
51
- Serve model inference requests.
52
- """
53
- responses = []
54
-
55
- for request in requests:
56
- parameters = request.parameters()
57
- parameters = parse_req_parameters(parameters) if parameters else {}
58
-
59
- if len(self.input_names) == 1:
60
- in_batch = pb_utils.get_input_tensor_by_name(request, self.input_names[0])
61
- in_batch = in_batch.as_numpy()
62
- inference_response = self.inference_obj.get_predictions(in_batch, **parameters)
63
- else:
64
- multi_in_batch_dict = {}
65
- for input_name in self.input_names:
66
- in_batch = pb_utils.get_input_tensor_by_name(request, input_name)
67
- in_batch = in_batch.as_numpy() if in_batch is not None else []
68
- multi_in_batch_dict.update({input_name: in_batch})
69
-
70
- inference_response = self.inference_obj.get_predictions(multi_in_batch_dict, **parameters)
71
-
72
- responses.append(inference_response)
73
-
74
- return responses
@@ -1,64 +0,0 @@
1
- import logging
2
- import os
3
- import unittest
4
-
5
- from clarifai.models.model_serving.models.default_test import DefaultTestInferenceModel
6
-
7
-
8
- class CustomTestInferenceModel(DefaultTestInferenceModel):
9
- """
10
- Run this file to test your implementation of InferenceModel in inference.py with default tests of Triton configuration and its output values based on basic predefined inputs
11
- If you want to write custom testcase or just test output value.
12
- Please follow these instrucitons:
13
- 1. Name your test function with prefix "test" so that pytest can execute
14
- 2. In order to obtain output of InferenceModel, call `self.triton_get_predictions(input_data)`.
15
- 3. If your input is `image` and you have set custom size of it when building model repository,
16
- call `self.preprocess(image)` to obtain correct resized input
17
- 4. Run this test by calling
18
- ```bash
19
- pytest ./your_triton_folder/1/test.py
20
- #to see std output
21
- pytest --log-cli-level=INFO -s ./your_triton_folder/1/test.py
22
- ```
23
-
24
- ### Examples:
25
- + test text-to-image output
26
- ```
27
- def test_text_to_image_output(self):
28
- text = "Test text"
29
- output = self.triton_get_predictions(text)
30
- image = output.image # uint8 np.ndarray image
31
- #show or save
32
- ```
33
- + test visual-classifier output
34
- ```
35
- def test_visual_classifier(self):
36
- image = cv2.imread("your/local/image.jpg") # Keep in mind of format of image (BGR or RGB)
37
- output = self.triton_get_predictions(image)
38
- scores = output.predicted_scores # np.ndarray
39
- #process scores to get class id and its score
40
- logger.info(result)
41
- """
42
-
43
- # Insert your inference parameters json path here
44
- # or insert a dictionary of your_parameter_name and value, e.g dict(x=1.5, y="text", c=True)
45
- # or Leave it as "" if you don't have it.
46
- inference_parameters = ""
47
-
48
- ########### Initialization. Do not change it ###########
49
- __test__ = True
50
-
51
- def setUp(self) -> None:
52
- logging.info("Initializing...")
53
- model_type = "text-embedder" # your model type
54
- self.intitialize(
55
- model_type,
56
- repo_version_dir=os.path.dirname(__file__),
57
- is_instance_kind_gpu=True,
58
- inference_parameters=self.inference_parameters)
59
-
60
- ########################################################
61
-
62
-
63
- if __name__ == '__main__':
64
- unittest.main()
@@ -1,20 +0,0 @@
1
- name: "instructor-xl"
2
- max_batch_size: 1
3
- input {
4
- name: "text"
5
- data_type: TYPE_STRING
6
- dims: 1
7
- }
8
- output {
9
- name: "embeddings"
10
- data_type: TYPE_FP32
11
- dims: -1
12
- }
13
- instance_group {
14
- count: 1
15
- kind: KIND_GPU
16
- }
17
- dynamic_batching {
18
- max_queue_delay_microseconds: 500
19
- }
20
- backend: "python"
@@ -1,9 +0,0 @@
1
- clarifai>9.10.5
2
- tritonclient[all]
3
- torch==1.13.1
4
- accelerate==0.20.3
5
- transformers==4.30.1
6
- scipy==1.10.1
7
- einops==0.6.1
8
- InstructorEmbedding==1.0.1
9
- sentence_transformers>=2.2.0
@@ -1,10 +0,0 @@
1
- ## Text to Image Triton Model Examples
2
-
3
- These can be used on the fly with minimal or no changes to test deploy text to image models to the Clarifai platform. See the required files section for each model below.
4
-
5
- * ### [sd-v1.5 (Stable-Diffusion-v1.5)](./sd-v1.5/)
6
-
7
- * Download the [model checkpoint](https://huggingface.co/runwayml/stable-diffusion-v1-5/tree/main) and store it under `sd-v1.5/1/checkpoint`
8
- ```
9
- huggingface-cli download runwayml/stable-diffusion-v1-5 --local-dir sd-v1.5/1/checkpoint --local-dir-use-symlinks False
10
- ```
@@ -1,58 +0,0 @@
1
- # This file contains boilerplate code to allow users write their model
2
- # inference code that will then interact with the Triton Inference Server
3
- # Python backend to serve end user requests.
4
- # The module name, module path, class name & get_predictions() method names MUST be maintained as is
5
- # but other methods may be added within the class as deemed fit provided
6
- # they are invoked within the main get_predictions() inference method
7
- # if they play a role in any step of model inference
8
- """User model inference script."""
9
-
10
- import os
11
- from pathlib import Path
12
-
13
- import numpy as np
14
- import torch
15
- from diffusers import StableDiffusionPipeline
16
-
17
- from clarifai.models.model_serving.model_config import ModelTypes, get_model_config
18
- from clarifai.models.model_serving.models.output import ImageOutput
19
-
20
- config = get_model_config(ModelTypes.text_to_image)
21
-
22
-
23
- class InferenceModel:
24
- """User model inference class."""
25
-
26
- def __init__(self) -> None:
27
- """
28
- Load inference time artifacts that are called frequently .e.g. models, tokenizers, etc.
29
- in this method so they are loaded only once for faster inference.
30
- """
31
- self.base_path: Path = os.path.dirname(__file__)
32
- self.huggingface_model_path = os.path.join(self.base_path, "checkpoint")
33
- self.device = "cuda" if torch.cuda.is_available() else "cpu"
34
- self.pipeline = StableDiffusionPipeline.from_pretrained(
35
- self.huggingface_model_path, torch_dtype=torch.float16)
36
- self.pipeline = self.pipeline.to(self.device)
37
-
38
- @config.inference.wrap_func
39
- def get_predictions(self, input_data: list, **kwargs):
40
- """
41
- Main model inference method.
42
-
43
- Args:
44
- -----
45
- input_data: A single input data item to predict on.
46
- Input data can be an image or text, etc depending on the model type.
47
-
48
- Returns:
49
- --------
50
- One of the clarifai.models.model_serving.models.output types. Refer to the README/docs
51
- """
52
- outputs = []
53
- for inp in input_data:
54
- out_image = self.pipeline(inp).images[0]
55
- out_image = np.asarray(out_image)
56
- outputs.append(ImageOutput(image=out_image))
57
-
58
- return outputs
@@ -1,74 +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 inference server Python Backend Model."""
14
-
15
- import os
16
- import sys
17
-
18
- try:
19
- import triton_python_backend_utils as pb_utils
20
- except ModuleNotFoundError:
21
- pass
22
- from google.protobuf import text_format
23
- from tritonclient.grpc.model_config_pb2 import ModelConfig
24
- from clarifai.models.model_serving.model_config.inference_parameter import parse_req_parameters
25
-
26
-
27
- class TritonPythonModel:
28
- """
29
- Triton Python BE Model.
30
- """
31
-
32
- def initialize(self, args):
33
- """
34
- Triton server init.
35
- """
36
- args["model_repository"] = args["model_repository"].replace("/1/model.py", "")
37
- sys.path.append(os.path.dirname(__file__))
38
- from inference import InferenceModel
39
-
40
- self.inference_obj = InferenceModel()
41
-
42
- # Read input_name from config file
43
- self.config_msg = ModelConfig()
44
- with open(os.path.join(args["model_repository"], "config.pbtxt"), "r") as f:
45
- cfg = f.read()
46
- text_format.Merge(cfg, self.config_msg)
47
- self.input_names = [inp.name for inp in self.config_msg.input]
48
-
49
- def execute(self, requests):
50
- """
51
- Serve model inference requests.
52
- """
53
- responses = []
54
-
55
- for request in requests:
56
- parameters = request.parameters()
57
- parameters = parse_req_parameters(parameters) if parameters else {}
58
-
59
- if len(self.input_names) == 1:
60
- in_batch = pb_utils.get_input_tensor_by_name(request, self.input_names[0])
61
- in_batch = in_batch.as_numpy()
62
- inference_response = self.inference_obj.get_predictions(in_batch, **parameters)
63
- else:
64
- multi_in_batch_dict = {}
65
- for input_name in self.input_names:
66
- in_batch = pb_utils.get_input_tensor_by_name(request, input_name)
67
- in_batch = in_batch.as_numpy() if in_batch is not None else []
68
- multi_in_batch_dict.update({input_name: in_batch})
69
-
70
- inference_response = self.inference_obj.get_predictions(multi_in_batch_dict, **parameters)
71
-
72
- responses.append(inference_response)
73
-
74
- return responses
@@ -1,22 +0,0 @@
1
- name: "sd-v1.5"
2
- max_batch_size: 1
3
- input {
4
- name: "text"
5
- data_type: TYPE_STRING
6
- dims: 1
7
- }
8
- output {
9
- name: "image"
10
- data_type: TYPE_UINT8
11
- dims: -1
12
- dims: -1
13
- dims: 3
14
- }
15
- instance_group {
16
- count: 1
17
- kind: KIND_GPU
18
- }
19
- dynamic_batching {
20
- max_queue_delay_microseconds: 500
21
- }
22
- backend: "python"
@@ -1,6 +0,0 @@
1
- clarifai>9.10.5
2
- tritonclient[all]
3
- torch==1.13.1
4
- transformers==4.30.2
5
- Pillow==10.0.0
6
- diffusers==0.19.0
@@ -1,12 +0,0 @@
1
- ## Text-to-Text Triton Model Examples
2
-
3
- These can be used on the fly with minimal or no changes to test deploy all models that take a text input and yield a text output prediction e.g. text generation, summarization and translation models to the Clarifai platform. See the required files section for each model below.
4
-
5
- * ### [Bart-paper2slides-summarizer](https://huggingface.co/com3dian/Bart-large-paper2slides-summarizer)
6
-
7
- Requirements to run tests locally:
8
-
9
- * Download/Clone the [huggingface model](https://huggingface.co/com3dian/Bart-large-paper2slides-summarizer) and store it under the **bart-summarize/1/checkpoint** directory.
10
- ```
11
- huggingface-cli download com3dian/Bart-large-paper2slides-summarizer --local-dir bart-summarize/1/checkpoint --local-dir-use-symlinks False --exclude *.safetensors
12
- ```
@@ -1,59 +0,0 @@
1
- # This file contains boilerplate code to allow users write their model
2
- # inference code that will then interact with the Triton Inference Server
3
- # Python backend to serve end user requests.
4
- # The module name, module path, class name & get_predictions() method names MUST be maintained as is
5
- # but other methods may be added within the class as deemed fit provided
6
- # they are invoked within the main get_predictions() inference method
7
- # if they play a role in any step of model inference
8
- """User model inference script."""
9
-
10
- import os
11
- from pathlib import Path
12
-
13
- from transformers import pipeline
14
-
15
- from clarifai.models.model_serving.model_config import ModelTypes, get_model_config
16
- from clarifai.models.model_serving.models.output import TextOutput
17
-
18
- config = get_model_config(ModelTypes.text_to_text)
19
-
20
-
21
- class InferenceModel:
22
- """User model inference class."""
23
-
24
- def __init__(self) -> None:
25
- """
26
- Load inference time artifacts that are called frequently .e.g. models, tokenizers, etc.
27
- in this method so they are loaded only once for faster inference.
28
- """
29
- self.base_path: Path = os.path.dirname(__file__)
30
- self.huggingface_model_path = os.path.join(self.base_path, "checkpoint")
31
- self.pipeline = pipeline("summarization", model=self.huggingface_model_path)
32
-
33
- @config.inference.wrap_func
34
- def get_predictions(self, input_data: list, **kwargs) -> list:
35
- """
36
- Main model inference method.
37
-
38
- Args:
39
- -----
40
- input_data: A list of input data item to predict on.
41
- Input data can be an image or text, etc depending on the model type.
42
-
43
- **kwargs: your inference parameters.
44
-
45
- Returns:
46
- --------
47
- List of one of the `clarifai.models.model_serving.models.output types` or `config.inference.return_type(your_output)`. Refer to the README/docs
48
- """
49
- # convert to top_k to int
50
- outputs = []
51
- top_k = int(kwargs.get("top_k", 50))
52
- kwargs.pop("top_k", top_k)
53
-
54
- summaries = self.pipeline(input_data, **kwargs)
55
- for summary in summaries:
56
- generated_text = summary['summary_text']
57
- outputs.append(TextOutput(predicted_text=generated_text))
58
-
59
- return outputs