clarifai 11.0.5__py3-none-any.whl → 11.0.6rc2__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__/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__/compute_cluster.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
- clarifai/cli/model.py +15 -2
- clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/runner.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
- clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
- clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
- clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
- clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
- clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/README.md +158 -0
- clarifai/models/model_serving/__init__.py +14 -0
- clarifai/models/model_serving/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/__pycache__/constants.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__init__.py +12 -0
- clarifai/models/model_serving/cli/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/_utils.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/build.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/__pycache__/create.cpython-310.pyc +0 -0
- clarifai/models/model_serving/cli/_utils.py +53 -0
- clarifai/models/model_serving/cli/base.py +14 -0
- clarifai/models/model_serving/cli/build.py +79 -0
- clarifai/models/model_serving/cli/clarifai_clis.py +33 -0
- clarifai/models/model_serving/cli/create.py +171 -0
- clarifai/models/model_serving/cli/example_cli.py +34 -0
- clarifai/models/model_serving/cli/login.py +26 -0
- clarifai/models/model_serving/cli/upload.py +183 -0
- clarifai/models/model_serving/constants.py +21 -0
- clarifai/models/model_serving/docs/cli.md +161 -0
- clarifai/models/model_serving/docs/concepts.md +229 -0
- clarifai/models/model_serving/docs/dependencies.md +11 -0
- clarifai/models/model_serving/docs/inference_parameters.md +139 -0
- clarifai/models/model_serving/docs/model_types.md +19 -0
- clarifai/models/model_serving/model_config/__init__.py +16 -0
- clarifai/models/model_serving/model_config/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/base.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/config.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/inference_parameter.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/__pycache__/output.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/base.py +369 -0
- clarifai/models/model_serving/model_config/config.py +312 -0
- clarifai/models/model_serving/model_config/inference_parameter.py +129 -0
- clarifai/models/model_serving/model_config/model_types_config/multimodal-embedder.yaml +25 -0
- clarifai/models/model_serving/model_config/model_types_config/text-classifier.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/text-embedder.yaml +20 -0
- clarifai/models/model_serving/model_config/model_types_config/text-to-image.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/text-to-text.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-classifier.yaml +22 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-detector.yaml +32 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-embedder.yaml +19 -0
- clarifai/models/model_serving/model_config/model_types_config/visual-segmenter.yaml +19 -0
- clarifai/models/model_serving/model_config/output.py +133 -0
- clarifai/models/model_serving/model_config/triton/__init__.py +14 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/serializer.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/triton_config.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/__pycache__/wrappers.cpython-310.pyc +0 -0
- clarifai/models/model_serving/model_config/triton/serializer.py +136 -0
- clarifai/models/model_serving/model_config/triton/triton_config.py +182 -0
- clarifai/models/model_serving/model_config/triton/wrappers.py +281 -0
- clarifai/models/model_serving/repo_build/__init__.py +14 -0
- clarifai/models/model_serving/repo_build/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/models/model_serving/repo_build/__pycache__/build.cpython-310.pyc +0 -0
- clarifai/models/model_serving/repo_build/build.py +198 -0
- clarifai/models/model_serving/repo_build/static_files/__pycache__/base_test.cpython-310-pytest-7.2.0.pyc +0 -0
- clarifai/models/model_serving/repo_build/static_files/_requirements.txt +2 -0
- clarifai/models/model_serving/repo_build/static_files/base_test.py +169 -0
- clarifai/models/model_serving/repo_build/static_files/inference.py +26 -0
- clarifai/models/model_serving/repo_build/static_files/sample_clarifai_config.yaml +25 -0
- clarifai/models/model_serving/repo_build/static_files/test.py +40 -0
- clarifai/models/model_serving/repo_build/static_files/triton/model.py +75 -0
- clarifai/models/model_serving/utils.py +31 -0
- clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
- clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/__pycache__/server.cpython-310.pyc +0 -0
- clarifai/runners/deepgram_live_transcribe.py +98 -0
- clarifai/runners/deepgram_live_transcribe.py~ +98 -0
- clarifai/runners/deepgram_runner.py +131 -0
- clarifai/runners/deepgram_runner.py~ +130 -0
- clarifai/runners/dockerfile_template/Dockerfile.cpu.template +31 -0
- clarifai/runners/dockerfile_template/Dockerfile.cuda.template +79 -0
- clarifai/runners/dockerfile_template/Dockerfile.template +53 -29
- clarifai/runners/example_llama2.py~ +72 -0
- clarifai/runners/matt_example.py +89 -0
- clarifai/runners/matt_example.py~ +87 -0
- clarifai/runners/matt_llm_example.py +129 -0
- clarifai/runners/matt_llm_example.py~ +128 -0
- clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_servicer.cpython-310.pyc +0 -0
- clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
- clarifai/runners/models/model_upload.py +7 -4
- clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
- clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
- clarifai/runners/utils/const.py +7 -6
- clarifai/runners/utils/loader.py +1 -0
- clarifai/runners/utils/logging.py +6 -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__/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/logging.py +1 -1
- clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
- clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
- {clarifai-11.0.5.dist-info → clarifai-11.0.6rc2.dist-info}/METADATA +16 -27
- clarifai-11.0.6rc2.dist-info/RECORD +242 -0
- {clarifai-11.0.5.dist-info → clarifai-11.0.6rc2.dist-info}/WHEEL +1 -1
- clarifai-11.0.5.dist-info/RECORD +0 -100
- {clarifai-11.0.5.dist-info → clarifai-11.0.6rc2.dist-info}/LICENSE +0 -0
- {clarifai-11.0.5.dist-info → clarifai-11.0.6rc2.dist-info}/entry_points.txt +0 -0
- {clarifai-11.0.5.dist-info → clarifai-11.0.6rc2.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,87 @@
|
|
1
|
+
from clarifai_grpc.grpc.api import resources_pb2, service_pb2
|
2
|
+
from collections.abc import Iterator
|
3
|
+
from google.protobuf import json_format
|
4
|
+
|
5
|
+
from clarifai.client.runner import Runner
|
6
|
+
|
7
|
+
|
8
|
+
class MyRunner(Runner):
|
9
|
+
"""A custom runner that adds "Hello World" to the end of the text and replaces the domain of the
|
10
|
+
image URL as an example.
|
11
|
+
"""
|
12
|
+
|
13
|
+
def run_input(self, input: resources_pb2.Input, output_info: resources_pb2.OutputInfo,
|
14
|
+
**kwargs) -> resources_pb2.Output:
|
15
|
+
"""This is the method that will be called when the runner is run. It takes in an input and
|
16
|
+
returns an output.
|
17
|
+
"""
|
18
|
+
|
19
|
+
output = resources_pb2.Output()
|
20
|
+
|
21
|
+
data = input.data
|
22
|
+
|
23
|
+
# Optional use of output_info
|
24
|
+
params_dict = {}
|
25
|
+
if "params" in output_info:
|
26
|
+
params_dict = output_info["params"]
|
27
|
+
|
28
|
+
if data.text.raw != "":
|
29
|
+
output.data.text.raw = data.text.raw + "Hello World" + params_dict.get(
|
30
|
+
"hello", "") + kwargs.get("extra", "")
|
31
|
+
if data.image.url != "":
|
32
|
+
output.data.text.raw = data.image.url.replace("samples.clarifai.com",
|
33
|
+
"newdomain.com" + params_dict.get("domain",))
|
34
|
+
return output
|
35
|
+
|
36
|
+
def generate(self, request: service_pb2.PostModelOutputsRequest
|
37
|
+
) -> Iterator[service_pb2.MultiOutputResponse]:
|
38
|
+
"""Example yielding a whole batch of streamed stuff back.
|
39
|
+
"""
|
40
|
+
|
41
|
+
model = request.model
|
42
|
+
output_info = None
|
43
|
+
if request.model.model_version.id != "":
|
44
|
+
output_info = json_format.MessageToDict(
|
45
|
+
model.model_version.output_info, preserving_proto_field_name=True)
|
46
|
+
|
47
|
+
for i in range(10): # fake something iterating generating 10 times.
|
48
|
+
|
49
|
+
outputs = []
|
50
|
+
for input in request.inputs:
|
51
|
+
# output = self.run_input(input, output_info, extra=f" {i}")
|
52
|
+
output = resources_pb2.Output()
|
53
|
+
output.data.text.raw = f"Generate Hello World {i}"
|
54
|
+
outputs.append(output)
|
55
|
+
resp = service_pb2.MultiOutputResponse(outputs=outputs,)
|
56
|
+
yield resp
|
57
|
+
|
58
|
+
def stream(self, request: service_pb2.PostModelOutputsRequest
|
59
|
+
) -> Iterator[service_pb2.MultiOutputResponse]:
|
60
|
+
"""Example yielding a whole batch of streamed stuff back.
|
61
|
+
"""
|
62
|
+
|
63
|
+
model = request.model
|
64
|
+
output_info = None
|
65
|
+
if request.model.model_version.id != "":
|
66
|
+
output_info = json_format.MessageToDict(
|
67
|
+
model.model_version.output_info, preserving_proto_field_name=True)
|
68
|
+
|
69
|
+
for i in range(10): # fake something iterating generating 10 times.
|
70
|
+
|
71
|
+
outputs = []
|
72
|
+
for input in request.inputs:
|
73
|
+
# output = self.run_input(input, output_info, extra=f" {i}")
|
74
|
+
output = resources_pb2.Output()
|
75
|
+
output.data.text.raw = input.data.text.raw + f"Stream Hello World {i}"
|
76
|
+
outputs.append(output)
|
77
|
+
resp = service_pb2.MultiOutputResponse(outputs=outputs,)
|
78
|
+
yield resp
|
79
|
+
|
80
|
+
|
81
|
+
if __name__ == '__main__':
|
82
|
+
# Make sure you set these env vars before running the example.
|
83
|
+
# CLARIFAI_PAT
|
84
|
+
# CLARIFAI_USER_ID
|
85
|
+
|
86
|
+
# You need to first create a runner in the Clarifai API and then use the ID here.
|
87
|
+
MyRunner(runner_id="matt-test-runner", base_url="http://q6:32013", num_parallel_polls=1).start()
|
@@ -0,0 +1,129 @@
|
|
1
|
+
from clarifai_grpc.grpc.api import resources_pb2, service_pb2
|
2
|
+
from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
|
3
|
+
from collections.abc import Iterator
|
4
|
+
from google.protobuf import json_format
|
5
|
+
|
6
|
+
from clarifai.client.runner import Runner
|
7
|
+
import time
|
8
|
+
from threading import Thread
|
9
|
+
|
10
|
+
import grpc
|
11
|
+
import requests
|
12
|
+
|
13
|
+
from transformers import (AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer)
|
14
|
+
|
15
|
+
model_name_or_path = "TheBloke/Llama-2-7B-chat-GPTQ"
|
16
|
+
model_basename = "model"
|
17
|
+
use_triton = False
|
18
|
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
|
19
|
+
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, device_map='auto')
|
20
|
+
streamer = TextIteratorStreamer(tokenizer)
|
21
|
+
print("Model loaded")
|
22
|
+
|
23
|
+
|
24
|
+
class MyRunner(Runner):
|
25
|
+
"""A custom runner that adds "Hello World" to the end of the text and replaces the domain of the
|
26
|
+
image URL as an example.
|
27
|
+
"""
|
28
|
+
|
29
|
+
def run_input(self, input: resources_pb2.Input, output_info: resources_pb2.OutputInfo,
|
30
|
+
**kwargs) -> resources_pb2.Output:
|
31
|
+
"""This is the method that will be called when the runner is run. It takes in an input and
|
32
|
+
returns an output.
|
33
|
+
"""
|
34
|
+
|
35
|
+
output = resources_pb2.Output()
|
36
|
+
|
37
|
+
data = input.data
|
38
|
+
|
39
|
+
# Optional use of output_info
|
40
|
+
params_dict = {}
|
41
|
+
if "params" in output_info:
|
42
|
+
params_dict = output_info["params"]
|
43
|
+
|
44
|
+
if data.text.raw != "":
|
45
|
+
output.data.text.raw = data.text.raw + "Hello World" + params_dict.get(
|
46
|
+
"hello", "") + kwargs.get("extra", "")
|
47
|
+
if data.image.url != "":
|
48
|
+
output.data.text.raw = data.image.url.replace("samples.clarifai.com",
|
49
|
+
"newdomain.com" + params_dict.get("domain",))
|
50
|
+
return output
|
51
|
+
|
52
|
+
def generate(self, request: service_pb2.PostModelOutputsRequest
|
53
|
+
) -> Iterator[service_pb2.MultiOutputResponse]:
|
54
|
+
"""Example yielding a whole batch of streamed stuff back.
|
55
|
+
"""
|
56
|
+
|
57
|
+
output_info = None
|
58
|
+
if request.model.model_version.id != "":
|
59
|
+
output_info = json_format.MessageToDict(
|
60
|
+
request.model.model_version.output_info, preserving_proto_field_name=True)
|
61
|
+
|
62
|
+
for inp in request.inputs:
|
63
|
+
data = inp.data
|
64
|
+
print('start')
|
65
|
+
if data.text.raw != "":
|
66
|
+
input_text = data.text.raw
|
67
|
+
elif data.text.url != "":
|
68
|
+
input_text = str(requests.get(data.text.url).text)
|
69
|
+
else:
|
70
|
+
raise Exception("Need to include data.text.raw or data.text.url in your inputs.")
|
71
|
+
|
72
|
+
st = time.time()
|
73
|
+
max_tokens = 1024
|
74
|
+
# # Method 1
|
75
|
+
inputs = tokenizer(input_text, return_tensors='pt') #.input_ids.cuda()
|
76
|
+
generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=max_tokens)
|
77
|
+
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
78
|
+
thread.start()
|
79
|
+
times = []
|
80
|
+
st = time.time()
|
81
|
+
total_start = st
|
82
|
+
for new_text in streamer:
|
83
|
+
duration = time.time() - st
|
84
|
+
st = time.time()
|
85
|
+
print(f"Duration: {duration}")
|
86
|
+
times.append(duration)
|
87
|
+
# for new_text in ["hello", "world", "i'm", "streaming"]:
|
88
|
+
|
89
|
+
# out = model.generate(inputs=input_ids, temperature=0.7, max_new_tokens=max_tokens)
|
90
|
+
# out_text = tokenizer.decode(out[0], skip_special_tokens=True)
|
91
|
+
# output.data.text.raw = out_text.replace(input_text, '')
|
92
|
+
|
93
|
+
# # # Method 2
|
94
|
+
# print('before')
|
95
|
+
# pipe = pipeline(
|
96
|
+
# "text-generation",
|
97
|
+
# model=model,
|
98
|
+
# tokenizer=tokenizer,
|
99
|
+
# streamer=streamer,
|
100
|
+
# max_new_tokens=max_tokens,
|
101
|
+
# temperature=0.7,
|
102
|
+
# top_p=0.95,
|
103
|
+
# repetition_penalty=1.15,
|
104
|
+
# return_full_text=False)
|
105
|
+
# print('pipe')
|
106
|
+
# a = pipe(input_text)
|
107
|
+
# print(a)
|
108
|
+
print("Posting: ", new_text)
|
109
|
+
output = resources_pb2.Output()
|
110
|
+
output.data.text.raw = new_text
|
111
|
+
result = service_pb2.MultiOutputResponse(
|
112
|
+
status=status_pb2.Status(
|
113
|
+
code=status_code_pb2.SUCCESS,
|
114
|
+
description="Success",
|
115
|
+
),
|
116
|
+
outputs=[output],
|
117
|
+
)
|
118
|
+
yield result
|
119
|
+
print(f"Total time: {time.time() - total_start}")
|
120
|
+
print(f"Average time: {sum(times) / len(times)}")
|
121
|
+
|
122
|
+
|
123
|
+
if __name__ == '__main__':
|
124
|
+
# Make sure you set these env vars before running the example.
|
125
|
+
# CLARIFAI_PAT
|
126
|
+
# CLARIFAI_USER_ID
|
127
|
+
|
128
|
+
# You need to first create a runner in the Clarifai API and then use the ID here.
|
129
|
+
MyRunner(runner_id="matt-test-runner", base_url="http://q6:32013", num_parallel_polls=1).start()
|
@@ -0,0 +1,128 @@
|
|
1
|
+
from clarifai_grpc.grpc.api import resources_pb2, service_pb2
|
2
|
+
from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
|
3
|
+
from collections.abc import Iterator
|
4
|
+
from google.protobuf import json_format
|
5
|
+
|
6
|
+
from clarifai.client.runner import Runner
|
7
|
+
import time
|
8
|
+
from threading import Thread
|
9
|
+
|
10
|
+
import grpc
|
11
|
+
import requests
|
12
|
+
|
13
|
+
from transformers import (AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer)
|
14
|
+
|
15
|
+
model_name_or_path = "TheBloke/Llama-2-7B-chat-GPTQ"
|
16
|
+
model_basename = "model"
|
17
|
+
use_triton = False
|
18
|
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, use_fast=True)
|
19
|
+
model = AutoModelForCausalLM.from_pretrained(model_name_or_path, device_map='auto')
|
20
|
+
streamer = TextIteratorStreamer(tokenizer)
|
21
|
+
print("Model loaded")
|
22
|
+
|
23
|
+
|
24
|
+
class MyRunner(Runner):
|
25
|
+
"""A custom runner that adds "Hello World" to the end of the text and replaces the domain of the
|
26
|
+
image URL as an example.
|
27
|
+
"""
|
28
|
+
|
29
|
+
def run_input(self, input: resources_pb2.Input, output_info: resources_pb2.OutputInfo,
|
30
|
+
**kwargs) -> resources_pb2.Output:
|
31
|
+
"""This is the method that will be called when the runner is run. It takes in an input and
|
32
|
+
returns an output.
|
33
|
+
"""
|
34
|
+
|
35
|
+
output = resources_pb2.Output()
|
36
|
+
|
37
|
+
data = input.data
|
38
|
+
|
39
|
+
# Optional use of output_info
|
40
|
+
params_dict = {}
|
41
|
+
if "params" in output_info:
|
42
|
+
params_dict = output_info["params"]
|
43
|
+
|
44
|
+
if data.text.raw != "":
|
45
|
+
output.data.text.raw = data.text.raw + "Hello World" + params_dict.get(
|
46
|
+
"hello", "") + kwargs.get("extra", "")
|
47
|
+
if data.image.url != "":
|
48
|
+
output.data.text.raw = data.image.url.replace("samples.clarifai.com",
|
49
|
+
"newdomain.com" + params_dict.get("domain",))
|
50
|
+
return output
|
51
|
+
|
52
|
+
def generate(self, request: service_pb2.PostModelOutputsRequest
|
53
|
+
) -> Iterator[service_pb2.MultiOutputResponse]:
|
54
|
+
"""Example yielding a whole batch of streamed stuff back.
|
55
|
+
"""
|
56
|
+
|
57
|
+
output_info = None
|
58
|
+
if request.model.model_version.id != "":
|
59
|
+
output_info = json_format.MessageToDict(
|
60
|
+
request.model.model_version.output_info, preserving_proto_field_name=True)
|
61
|
+
|
62
|
+
for inp in request.inputs:
|
63
|
+
data = inp.data
|
64
|
+
print('start')
|
65
|
+
if data.text.raw != "":
|
66
|
+
input_text = data.text.raw
|
67
|
+
elif data.text.url != "":
|
68
|
+
input_text = str(requests.get(data.text.url).text)
|
69
|
+
else:
|
70
|
+
raise Exception("Need to include data.text.raw or data.text.url in your inputs.")
|
71
|
+
|
72
|
+
st = time.time()
|
73
|
+
max_tokens = 1024
|
74
|
+
# # Method 1
|
75
|
+
inputs = tokenizer(input_text, return_tensors='pt') #.input_ids.cuda()
|
76
|
+
generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=max_tokens)
|
77
|
+
thread = Thread(target=model.generate, kwargs=generation_kwargs)
|
78
|
+
thread.start()
|
79
|
+
times = []
|
80
|
+
st = time.time()
|
81
|
+
for new_text in streamer:
|
82
|
+
duration = time.time() - st
|
83
|
+
st = time.time()
|
84
|
+
print(f"Duration: {duration}")
|
85
|
+
times.append(duration)
|
86
|
+
# for new_text in ["hello", "world", "i'm", "streaming"]:
|
87
|
+
|
88
|
+
# out = model.generate(inputs=input_ids, temperature=0.7, max_new_tokens=max_tokens)
|
89
|
+
# out_text = tokenizer.decode(out[0], skip_special_tokens=True)
|
90
|
+
# output.data.text.raw = out_text.replace(input_text, '')
|
91
|
+
|
92
|
+
# # # Method 2
|
93
|
+
# print('before')
|
94
|
+
# pipe = pipeline(
|
95
|
+
# "text-generation",
|
96
|
+
# model=model,
|
97
|
+
# tokenizer=tokenizer,
|
98
|
+
# streamer=streamer,
|
99
|
+
# max_new_tokens=max_tokens,
|
100
|
+
# temperature=0.7,
|
101
|
+
# top_p=0.95,
|
102
|
+
# repetition_penalty=1.15,
|
103
|
+
# return_full_text=False)
|
104
|
+
# print('pipe')
|
105
|
+
# a = pipe(input_text)
|
106
|
+
# print(a)
|
107
|
+
print("Posting: ", new_text)
|
108
|
+
output = resources_pb2.Output()
|
109
|
+
output.data.text.raw = new_text
|
110
|
+
result = service_pb2.MultiOutputResponse(
|
111
|
+
status=status_pb2.Status(
|
112
|
+
code=status_code_pb2.SUCCESS,
|
113
|
+
description="Success",
|
114
|
+
),
|
115
|
+
outputs=[output],
|
116
|
+
)
|
117
|
+
yield result
|
118
|
+
print(f"Total time: {time.time() - st}")
|
119
|
+
print(f"Average time: {sum(times) / len(times)}")
|
120
|
+
|
121
|
+
|
122
|
+
if __name__ == '__main__':
|
123
|
+
# Make sure you set these env vars before running the example.
|
124
|
+
# CLARIFAI_PAT
|
125
|
+
# CLARIFAI_USER_ID
|
126
|
+
|
127
|
+
# You need to first create a runner in the Clarifai API and then use the ID here.
|
128
|
+
MyRunner(runner_id="matt-test-runner", base_url="http://q6:32013", num_parallel_polls=1).start()
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -278,14 +278,15 @@ class ModelUploader:
|
|
278
278
|
)
|
279
279
|
python_version = DEFAULT_PYTHON_VERSION
|
280
280
|
|
281
|
-
|
281
|
+
download_image = PYTHON_BASE_IMAGE.format(python_version=python_version)
|
282
282
|
|
283
283
|
# Parse the requirements.txt file to determine the base image
|
284
284
|
dependencies = self._parse_requirements()
|
285
285
|
if 'torch' in dependencies and dependencies['torch']:
|
286
286
|
torch_version = dependencies['torch']
|
287
287
|
|
288
|
-
|
288
|
+
# Sort in reverse so that newer cuda versions come first and are preferred.
|
289
|
+
for image in sorted(AVAILABLE_TORCH_IMAGES, reverse=True):
|
289
290
|
if torch_version in image and f'py{python_version}' in image:
|
290
291
|
cuda_version = image.split('-')[-1].replace('cuda', '')
|
291
292
|
base_image = TORCH_BASE_IMAGE.format(
|
@@ -295,11 +296,13 @@ class ModelUploader:
|
|
295
296
|
)
|
296
297
|
logger.info(f"Using Torch version {torch_version} base image to build the Docker image")
|
297
298
|
break
|
298
|
-
|
299
|
+
else: # if not torch then use the download image for the base image too
|
300
|
+
base_image = download_image
|
299
301
|
# Replace placeholders with actual values
|
300
302
|
dockerfile_content = dockerfile_template.safe_substitute(
|
301
303
|
name='main',
|
302
|
-
|
304
|
+
DOWNLOAD_IMAGE=download_image, # for downloading
|
305
|
+
BASE_IMAGE=base_image, # for runtime
|
303
306
|
)
|
304
307
|
|
305
308
|
# Write Dockerfile
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
clarifai/runners/utils/const.py
CHANGED
@@ -11,23 +11,24 @@ AVAILABLE_PYTHON_IMAGES = ['3.11', '3.12', '3.13']
|
|
11
11
|
DEFAULT_PYTHON_VERSION = 3.12
|
12
12
|
|
13
13
|
# List of available torch images
|
14
|
+
# Keep sorted by most recent cuda version.
|
14
15
|
AVAILABLE_TORCH_IMAGES = [
|
15
16
|
'2.2.2-py3.11-cuda121',
|
16
17
|
'2.3.1-py3.11-cuda121',
|
17
|
-
'2.4.0-py3.11-cuda121',
|
18
18
|
'2.4.0-py3.11-cuda124',
|
19
|
-
'2.4.
|
19
|
+
'2.4.0-py3.11-cuda121',
|
20
20
|
'2.4.1-py3.11-cuda124',
|
21
|
-
'2.
|
21
|
+
'2.4.1-py3.11-cuda121',
|
22
22
|
'2.5.1-py3.11-cuda124',
|
23
|
+
'2.5.1-py3.11-cuda121',
|
23
24
|
'2.2.2-py3.12-cuda121',
|
24
25
|
'2.3.1-py3.12-cuda121',
|
25
|
-
'2.4.0-py3.12-cuda121',
|
26
26
|
'2.4.0-py3.12-cuda124',
|
27
|
-
'2.4.
|
27
|
+
'2.4.0-py3.12-cuda121',
|
28
28
|
'2.4.1-py3.12-cuda124',
|
29
|
-
'2.
|
29
|
+
'2.4.1-py3.12-cuda121',
|
30
30
|
'2.5.1-py3.12-cuda124',
|
31
|
+
'2.5.1-py3.12-cuda121',
|
31
32
|
# '2.2.2-py3.13-cuda121',
|
32
33
|
# '2.3.1-py3.13-cuda121',
|
33
34
|
# '2.4.0-py3.13-cuda121',
|
clarifai/runners/utils/loader.py
CHANGED
@@ -44,6 +44,7 @@ class HuggingFaceLoader:
|
|
44
44
|
from huggingface_hub import snapshot_download
|
45
45
|
except ImportError:
|
46
46
|
raise ImportError(self.HF_DOWNLOAD_TEXT)
|
47
|
+
os.environ['HF_HUB_ENABLE_HF_TRANSFER'] = '1'
|
47
48
|
if os.path.exists(checkpoint_path) and self.validate_download(checkpoint_path):
|
48
49
|
logger.info("Checkpoints already exist")
|
49
50
|
return True
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
clarifai/utils/logging.py
CHANGED
@@ -143,7 +143,7 @@ def _configure_logger(name: str, logger_level: Union[int, str] = logging.NOTSET)
|
|
143
143
|
else:
|
144
144
|
# Add the new rich handler and formatter
|
145
145
|
handler = RichHandler(
|
146
|
-
rich_tracebacks=True, log_time_format="%Y-%m-%d %H:%M:%S", console=Console(width=255))
|
146
|
+
rich_tracebacks=True, log_time_format="%Y-%m-%d %H:%M:%S.%f", console=Console(width=255))
|
147
147
|
formatter = logging.Formatter('%(name)s: %(message)s')
|
148
148
|
handler.setFormatter(formatter)
|
149
149
|
logger.addHandler(handler)
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.1
|
2
2
|
Name: clarifai
|
3
|
-
Version: 11.0.
|
3
|
+
Version: 11.0.6rc2
|
4
4
|
Summary: Clarifai Python SDK
|
5
5
|
Home-page: https://github.com/Clarifai/clarifai-python
|
6
6
|
Author: Clarifai
|
@@ -20,32 +20,21 @@ Classifier: Operating System :: OS Independent
|
|
20
20
|
Requires-Python: >=3.8
|
21
21
|
Description-Content-Type: text/markdown
|
22
22
|
License-File: LICENSE
|
23
|
-
Requires-Dist: clarifai-grpc>=11.0.0
|
24
|
-
Requires-Dist: clarifai-protocol>=0.0.14
|
25
|
-
Requires-Dist: numpy>=1.22.0
|
26
|
-
Requires-Dist: tqdm>=4.65.0
|
27
|
-
Requires-Dist: tritonclient>=2.34.0
|
28
|
-
Requires-Dist: rich>=13.4.2
|
29
|
-
Requires-Dist: PyYAML>=6.0.1
|
30
|
-
Requires-Dist: schema==0.7.5
|
31
|
-
Requires-Dist: Pillow>=9.5.0
|
32
|
-
Requires-Dist: inquirerpy==0.3.4
|
33
|
-
Requires-Dist: tabulate>=0.9.0
|
34
|
-
Requires-Dist: fsspec==2024.6.1
|
35
|
-
Requires-Dist: click==8.1.7
|
23
|
+
Requires-Dist: clarifai-grpc >=11.0.0
|
24
|
+
Requires-Dist: clarifai-protocol >=0.0.14
|
25
|
+
Requires-Dist: numpy >=1.22.0
|
26
|
+
Requires-Dist: tqdm >=4.65.0
|
27
|
+
Requires-Dist: tritonclient >=2.34.0
|
28
|
+
Requires-Dist: rich >=13.4.2
|
29
|
+
Requires-Dist: PyYAML >=6.0.1
|
30
|
+
Requires-Dist: schema ==0.7.5
|
31
|
+
Requires-Dist: Pillow >=9.5.0
|
32
|
+
Requires-Dist: inquirerpy ==0.3.4
|
33
|
+
Requires-Dist: tabulate >=0.9.0
|
34
|
+
Requires-Dist: fsspec ==2024.6.1
|
35
|
+
Requires-Dist: click ==8.1.7
|
36
36
|
Provides-Extra: all
|
37
|
-
Requires-Dist: pycocotools==2.0.6; extra ==
|
38
|
-
Dynamic: author
|
39
|
-
Dynamic: author-email
|
40
|
-
Dynamic: classifier
|
41
|
-
Dynamic: description
|
42
|
-
Dynamic: description-content-type
|
43
|
-
Dynamic: home-page
|
44
|
-
Dynamic: license
|
45
|
-
Dynamic: provides-extra
|
46
|
-
Dynamic: requires-dist
|
47
|
-
Dynamic: requires-python
|
48
|
-
Dynamic: summary
|
37
|
+
Requires-Dist: pycocotools ==2.0.6 ; extra == 'all'
|
49
38
|
|
50
39
|
<h1 align="center">
|
51
40
|
<a href="https://www.clarifai.com/"><img alt="Clarifai" title="Clarifai" src="https://github.com/user-attachments/assets/623b883b-7fe5-4b95-bbfa-8691f5779af4"></a>
|