clarifai 11.1.7rc1__py3-none-any.whl → 11.1.7rc2__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 (183) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
  3. clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
  4. clarifai/__pycache__/errors.cpython-310.pyc +0 -0
  5. clarifai/__pycache__/versions.cpython-310.pyc +0 -0
  6. clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  7. clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
  8. clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  9. clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  10. clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
  11. clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
  12. clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  13. clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
  14. clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
  15. clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
  16. clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
  17. clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
  18. clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
  19. clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  20. clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
  21. clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
  22. clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
  23. clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
  24. clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
  25. clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
  26. clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
  27. clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
  28. clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
  29. clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
  30. clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
  31. clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
  32. clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
  33. clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
  34. clarifai/client/cli/__init__.py +0 -0
  35. clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  36. clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  37. clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  38. clarifai/client/cli/base_cli.py +88 -0
  39. clarifai/client/cli/model_cli.py +29 -0
  40. clarifai/client/model.py +0 -1
  41. clarifai/client/model_client.py +22 -24
  42. clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
  43. clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
  44. clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
  45. clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
  46. clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
  47. clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
  48. clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
  49. clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
  50. clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
  51. clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
  52. clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
  53. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
  54. clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
  55. clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
  56. clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
  57. clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
  58. clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
  59. clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
  60. clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
  61. clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
  62. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
  63. clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
  64. clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
  65. clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
  66. clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
  67. clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
  68. clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
  69. clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
  70. clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
  71. clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
  72. clarifai/runners/dockerfile_template/Dockerfile.cpu.template +31 -0
  73. clarifai/runners/dockerfile_template/Dockerfile.cuda.template +42 -0
  74. clarifai/runners/dockerfile_template/Dockerfile.nim +71 -0
  75. clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
  76. clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
  77. clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
  78. clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
  79. clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
  80. clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
  81. clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
  82. clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
  83. clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
  84. clarifai/runners/models/model_builder.py +12 -1
  85. clarifai/runners/models/model_class.py +18 -12
  86. clarifai/runners/models/model_class_refract.py +80 -0
  87. clarifai/runners/models/model_upload.py +607 -0
  88. clarifai/runners/models/temp.py +25 -0
  89. clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  90. clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
  91. clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  92. clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
  93. clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
  94. clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
  95. clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
  96. clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
  97. clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
  98. clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
  99. clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
  100. clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
  101. clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
  102. clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
  103. clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
  104. clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
  105. clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
  106. clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
  107. clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
  108. clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
  109. clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
  110. clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
  111. clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
  112. clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
  113. clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
  114. clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
  115. clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
  116. clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
  117. clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
  118. clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
  119. clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
  120. clarifai/runners/utils/data_handler.py +271 -210
  121. clarifai/runners/utils/data_handler_refract.py +213 -0
  122. clarifai/runners/utils/logger.py +0 -0
  123. clarifai/runners/utils/method_signatures.py +100 -128
  124. clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
  125. clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
  126. clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  127. clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  128. clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
  129. clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
  130. clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
  131. clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
  132. clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
  133. clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
  134. clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
  135. clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
  136. clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
  137. clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
  138. clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
  139. clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
  140. {clarifai-11.1.7rc1.dist-info → clarifai-11.1.7rc2.dist-info}/METADATA +15 -15
  141. clarifai-11.1.7rc2.dist-info/RECORD +237 -0
  142. {clarifai-11.1.7rc1.dist-info → clarifai-11.1.7rc2.dist-info}/WHEEL +1 -1
  143. clarifai/cli/__main__.py~ +0 -4
  144. clarifai/cli/__pycache__/__main__.cpython-310.pyc +0 -0
  145. clarifai/client/#model_client.py# +0 -430
  146. clarifai/client/__pycache__/runner.cpython-310.pyc +0 -0
  147. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-310.pyc +0 -0
  148. clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-310.pyc +0 -0
  149. clarifai/models/__pycache__/__init__.cpython-310.pyc +0 -0
  150. clarifai/models/model_serving/__pycache__/__init__.cpython-310.pyc +0 -0
  151. clarifai/models/model_serving/__pycache__/constants.cpython-310.pyc +0 -0
  152. clarifai/models/model_serving/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  153. clarifai/models/model_serving/cli/__pycache__/_utils.cpython-310.pyc +0 -0
  154. clarifai/models/model_serving/cli/__pycache__/base.cpython-310.pyc +0 -0
  155. clarifai/models/model_serving/cli/__pycache__/build.cpython-310.pyc +0 -0
  156. clarifai/models/model_serving/cli/__pycache__/create.cpython-310.pyc +0 -0
  157. clarifai/models/model_serving/model_config/__pycache__/__init__.cpython-310.pyc +0 -0
  158. clarifai/models/model_serving/model_config/__pycache__/base.cpython-310.pyc +0 -0
  159. clarifai/models/model_serving/model_config/__pycache__/config.cpython-310.pyc +0 -0
  160. clarifai/models/model_serving/model_config/__pycache__/inference_parameter.cpython-310.pyc +0 -0
  161. clarifai/models/model_serving/model_config/__pycache__/output.cpython-310.pyc +0 -0
  162. clarifai/models/model_serving/model_config/triton/__pycache__/__init__.cpython-310.pyc +0 -0
  163. clarifai/models/model_serving/model_config/triton/__pycache__/serializer.cpython-310.pyc +0 -0
  164. clarifai/models/model_serving/model_config/triton/__pycache__/triton_config.cpython-310.pyc +0 -0
  165. clarifai/models/model_serving/model_config/triton/__pycache__/wrappers.cpython-310.pyc +0 -0
  166. clarifai/models/model_serving/repo_build/__pycache__/__init__.cpython-310.pyc +0 -0
  167. clarifai/models/model_serving/repo_build/__pycache__/build.cpython-310.pyc +0 -0
  168. clarifai/models/model_serving/repo_build/static_files/__pycache__/base_test.cpython-310-pytest-7.2.0.pyc +0 -0
  169. clarifai/runners/__pycache__/server.cpython-310.pyc +0 -0
  170. clarifai/runners/dockerfile_template/Dockerfile.debug +0 -11
  171. clarifai/runners/dockerfile_template/Dockerfile.debug~ +0 -9
  172. clarifai/runners/models/__pycache__/model_builder.cpython-310.pyc +0 -0
  173. clarifai/runners/models/__pycache__/model_servicer.cpython-310.pyc +0 -0
  174. clarifai/runners/utils/__pycache__/data_types.cpython-310.pyc +0 -0
  175. clarifai/runners/utils/__pycache__/method_signatures.cpython-310.pyc +0 -0
  176. clarifai/runners/utils/__pycache__/serializers.cpython-310.pyc +0 -0
  177. clarifai/utils/evaluation/__pycache__/__init__.cpython-310.pyc +0 -0
  178. clarifai/utils/evaluation/__pycache__/helpers.cpython-310.pyc +0 -0
  179. clarifai/utils/evaluation/__pycache__/main.cpython-310.pyc +0 -0
  180. clarifai-11.1.7rc1.dist-info/RECORD +0 -205
  181. {clarifai-11.1.7rc1.dist-info → clarifai-11.1.7rc2.dist-info}/LICENSE +0 -0
  182. {clarifai-11.1.7rc1.dist-info → clarifai-11.1.7rc2.dist-info}/entry_points.txt +0 -0
  183. {clarifai-11.1.7rc1.dist-info → clarifai-11.1.7rc2.dist-info}/top_level.txt +0 -0
clarifai/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "11.1.7rc1"
1
+ __version__ = "11.1.7rc2"
Binary file
File without changes
@@ -0,0 +1,88 @@
1
+ import click
2
+ import os
3
+ import yaml
4
+
5
+ @click.group()
6
+ @click.pass_context
7
+ def cli(ctx):
8
+ """Clarifai CLI"""
9
+ ctx.ensure_object(dict)
10
+ config_path = 'config.yaml'
11
+ if os.path.exists(config_path):
12
+ ctx.obj = _from_yaml(config_path)
13
+ print("Loaded config from file.")
14
+ print(f"Config: {ctx.obj}")
15
+ else:
16
+ ctx.obj = {}
17
+
18
+ def _from_yaml(filename: str):
19
+ try:
20
+ with open(filename, 'r') as f:
21
+ return yaml.safe_load(f)
22
+ except yaml.YAMLError as e:
23
+ click.echo(f"Error reading YAML file: {e}", err=True)
24
+ return {}
25
+
26
+ def _dump_yaml(data, filename: str):
27
+ try:
28
+ with open(filename, 'w') as f:
29
+ yaml.dump(data, f)
30
+ except Exception as e:
31
+ click.echo(f"Error writing YAML file: {e}", err=True)
32
+
33
+ def _set_base_url(env):
34
+ environments = {'prod': 'https://api.clarifai.com', 'staging': 'https://api-staging.clarifai.com', 'dev': 'https://api-dev.clarifai.com'}
35
+ return environments.get(env, 'https://api.clarifai.com')
36
+
37
+
38
+ @cli.command()
39
+ @click.option('--config', type=click.Path(), required=False, help='Path to the config file')
40
+ @click.option('-e', '--env', required=False, help='Environment', type=click.Choice(['prod', 'staging', 'dev']))
41
+ @click.option('--user_id', required=False, help='User ID')
42
+ @click.pass_context
43
+ def login(ctx, config, env, user_id):
44
+ """Login command to set PAT and other configurations."""
45
+
46
+ if config and os.path.exists(config):
47
+ ctx.obj = _from_yaml(config)
48
+
49
+ if 'pat' in ctx.obj:
50
+ os.environ["CLARIFAI_PAT"] = ctx.obj['pat']
51
+ click.echo("Loaded PAT from config file.")
52
+ elif 'CLARIFAI_PAT' in os.environ:
53
+ ctx.obj['pat'] = os.environ["CLARIFAI_PAT"]
54
+ click.echo("Loaded PAT from environment variable.")
55
+ else:
56
+ _pat = click.prompt("Get your PAT from https://clarifai.com/settings/security and pass it here", type=str)
57
+ os.environ["CLARIFAI_PAT"] = _pat
58
+ ctx.obj['pat'] = _pat
59
+ click.echo("PAT saved successfully.")
60
+
61
+ if user_id:
62
+ ctx.obj['user_id'] = user_id
63
+ os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
64
+ elif 'user_id' in ctx.obj or 'CLARIFAI_USER_ID' in os.environ:
65
+ ctx.obj['user_id'] = ctx.obj.get('user_id', os.environ["CLARIFAI_USER_ID"])
66
+ os.environ["CLARIFAI_USER_ID"] = ctx.obj['user_id']
67
+
68
+ if env:
69
+ ctx.obj['env'] = env
70
+ ctx.obj['base_url'] = _set_base_url(env)
71
+ os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
72
+ elif 'env' in ctx.obj:
73
+ ctx.obj['env'] = ctx.obj.get('env', "prod")
74
+ ctx.obj['base_url'] = _set_base_url(ctx.obj['env'])
75
+ os.environ["CLARIFAI_API_BASE"] = ctx.obj['base_url']
76
+ elif 'CLARIFAI_API_BASE' in os.environ:
77
+ ctx.obj['base_url'] = os.environ["CLARIFAI_API_BASE"]
78
+
79
+ _dump_yaml(ctx.obj, 'config.yaml')
80
+
81
+ click.echo("Login successful.")
82
+
83
+ # Import the model CLI commands to register them
84
+ from clarifai.client.cli.model_cli import model # Ensure this is the correct import path
85
+
86
+
87
+ if __name__ == '__main__':
88
+ cli()
@@ -0,0 +1,29 @@
1
+ import click
2
+ from clarifai.client.cli.base_cli import cli
3
+
4
+ @cli.group()
5
+ def model():
6
+ """Manage models: upload, test locally"""
7
+ pass
8
+
9
+ @model.command()
10
+ @click.argument('model_path', type=click.Path(exists=True))
11
+ @click.option('--download_checkpoints', is_flag=True, help='Flag to download checkpoints before uploading and including them in the tar file that is uploaded. Defaults to False, which will attempt to download them at docker build time.', )
12
+ @click.option('--skip_dockerfile', is_flag =True, help='Flag to skip generating a dockerfile so that you can manually edit an already created dockerfile.', )
13
+ def upload(model_path, download_checkpoints, skip_dockerfile):
14
+ """Upload a model to Clarifai."""
15
+ from clarifai.runners.models import model_upload
16
+
17
+ model_upload.main(model_path, download_checkpoints, skip_dockerfile)
18
+
19
+ @model.command()
20
+ @click.argument('model_path', type=click.Path(exists=True))
21
+ def test_locally(model_path):
22
+ """Test model locally."""
23
+ try:
24
+ from clarifai.runners.models import run_test_locally
25
+ run_test_locally.main(model_path)
26
+ click.echo(f"Model tested locally from {model_path}.")
27
+ except Exception as e:
28
+ click.echo(f"Failed to test model locally: {e}", err=True)
29
+
clarifai/client/model.py CHANGED
@@ -84,7 +84,6 @@ class Model(Lister, BaseClient):
84
84
  compute_cluster_id=compute_cluster_id,
85
85
  nodepool_id=nodepool_id,
86
86
  deployment_id=deployment_id,
87
- user_id=self.user_id, # FIXME the deployment's user_id can be different than the model's.
88
87
  )
89
88
  BaseClient.__init__(
90
89
  self,
@@ -1,5 +1,3 @@
1
- import inspect
2
- import json
3
1
  import time
4
2
  from typing import Any, Dict, Iterator, List
5
3
 
@@ -98,18 +96,19 @@ class ModelClient:
98
96
  '''
99
97
  for method_name, method_signature in self._method_signatures.items():
100
98
  # define the function in this client instance
101
- if method_signature.method_type == 'predict':
99
+ if resources_pb2.RunnerMethodType.Name(method_signature.method_type) == 'UNARY_UNARY':
102
100
  call_func = self._predict
103
- elif method_signature.method_type == 'generate':
101
+ elif resources_pb2.RunnerMethodType.Name(method_signature.method_type) == 'UNARY_STREAMING':
104
102
  call_func = self._generate
105
- elif method_signature.method_type == 'stream':
103
+ elif resources_pb2.RunnerMethodType.Name(
104
+ method_signature.method_type) == 'STREAMING_STREAMING':
106
105
  call_func = self._stream
107
106
  else:
108
107
  raise ValueError(f"Unknown method type {method_signature.method_type}")
109
108
 
110
109
  # method argnames, in order, collapsing nested keys to corresponding user function args
111
110
  method_argnames = []
112
- for var in method_signature.inputs:
111
+ for var in method_signature.input_fields:
113
112
  outer = var.name.split('.', 1)[0]
114
113
  if outer in method_argnames:
115
114
  continue
@@ -136,18 +135,17 @@ class ModelClient:
136
135
  # set names, annotations and docstrings
137
136
  f.__name__ = method_name
138
137
  f.__qualname__ = f'{self.__class__.__name__}.{method_name}'
139
- f.__doc__ = method_signature.docstring
140
- input_annotations = json.loads(method_signature.annotations_json)
141
- return_annotation = input_annotations.pop('return', None)
142
- sig = inspect.signature(f).replace(
143
- parameters=[
144
- inspect.Parameter(k, inspect.Parameter.POSITIONAL_OR_KEYWORD, annotation=v)
145
- for k, v in input_annotations.items()
146
- ],
147
- return_annotation=return_annotation,
148
- )
149
- f.__signature__ = sig
150
- f.__doc__ = method_signature.docstring
138
+ # input_annotations = json.loads(method_signature.annotations_json)
139
+ # return_annotation = input_annotations.pop('return', None)
140
+ # sig = inspect.signature(f).replace(
141
+ # parameters=[
142
+ # inspect.Parameter(k, inspect.Parameter.POSITIONAL_OR_KEYWORD, annotation=v)
143
+ # for k, v in input_annotations.items()
144
+ # ],
145
+ # return_annotation=return_annotation,
146
+ # )
147
+ # f.__signature__ = sig
148
+ f.__doc__ = method_signature.description
151
149
  setattr(self, method_name, f)
152
150
 
153
151
  def _define_compatability_functions(self):
@@ -177,8 +175,8 @@ class ModelClient:
177
175
  inputs, # TODO set up functions according to fetched signatures?
178
176
  method_name: str = 'predict',
179
177
  ) -> Any:
180
- input_signature = self._method_signatures[method_name].inputs
181
- output_signature = self._method_signatures[method_name].outputs
178
+ input_signature = self._method_signatures[method_name].input_fields
179
+ output_signature = self._method_signatures[method_name].output_fields
182
180
 
183
181
  batch_input = True
184
182
  if isinstance(inputs, dict):
@@ -260,8 +258,8 @@ class ModelClient:
260
258
  inputs, # TODO set up functions according to fetched signatures?
261
259
  method_name: str = 'generate',
262
260
  ) -> Any:
263
- input_signature = self._method_signatures[method_name].inputs
264
- output_signature = self._method_signatures[method_name].outputs
261
+ input_signature = self._method_signatures[method_name].input_fields
262
+ output_signature = self._method_signatures[method_name].output_fields
265
263
 
266
264
  batch_input = True
267
265
  if isinstance(inputs, dict):
@@ -350,8 +348,8 @@ class ModelClient:
350
348
  inputs,
351
349
  method_name: str = 'stream',
352
350
  ) -> Any:
353
- input_signature = self._method_signatures[method_name].inputs
354
- output_signature = self._method_signatures[method_name].outputs
351
+ input_signature = self._method_signatures[method_name].input_fields
352
+ output_signature = self._method_signatures[method_name].output_fields
355
353
 
356
354
  if isinstance(inputs, list):
357
355
  assert len(inputs) == 1, 'streaming methods do not support batched calls'
@@ -0,0 +1,31 @@
1
+ ARG BASE_IMAGE=${BASE_IMAGE}
2
+ FROM ${BASE_IMAGE} as build
3
+
4
+ # Set the working directory to /app
5
+ WORKDIR /app
6
+
7
+ COPY requirements.txt .
8
+ # Install requirements and cleanup before leaving this line.
9
+ # Note(zeiler): this could be in a future template as {{model_python_deps}}
10
+ RUN pip install --no-cache-dir -r requirements.txt
11
+
12
+ # Install Clarifai SDK
13
+ RUN pip install --no-cache-dir clarifai
14
+
15
+ # These will be set by the templaing system.
16
+ ENV CLARIFAI_PAT=${CLARIFAI_PAT}
17
+ ENV CLARIFAI_USER_ID=${CLARIFAI_USER_ID}
18
+ ENV CLARIFAI_RUNNER_ID=${CLARIFAI_RUNNER_ID}
19
+ ENV CLARIFAI_NODEPOOL_ID=${CLARIFAI_NODEPOOL_ID}
20
+ ENV CLARIFAI_COMPUTE_CLUSTER_ID=${CLARIFAI_COMPUTE_CLUSTER_ID}
21
+ ENV CLARIFAI_API_BASE=${CLARIFAI_API_BASE}
22
+
23
+ # Copy the current folder into /app/model_dir that the SDK will expect.
24
+ COPY . /app/model_dir/${name}
25
+
26
+ # Add the model directory to the python path.
27
+ ENV PYTHONPATH "${PYTHONPATH}:/app/model_dir/${name}"
28
+
29
+ # Finally run the clarifai entrypoint to start the runner loop and local dev server.
30
+ # Note(zeiler): we may want to make this a clarifai CLI call.
31
+ CMD ["-m", "clarifai.runners.server", "--model_path", "/app/model_dir/${name}"]
@@ -0,0 +1,42 @@
1
+ ARG TARGET_PLATFORM=linux/amd64
2
+ FROM --platform=$TARGET_PLATFORM ${BASE_IMAGE} as build
3
+
4
+ ENV DEBIAN_FRONTEND=noninteractive
5
+
6
+ #############################
7
+ # User specific requirements
8
+ #############################
9
+ COPY requirements.txt .
10
+
11
+ # Install requirements and cleanup before leaving this line.
12
+ # Note(zeiler): this could be in a future template as {{model_python_deps}}
13
+ RUN pip install --no-cache-dir -r requirements.txt
14
+
15
+ # Install Clarifai SDK
16
+ RUN pip install --no-cache-dir clarifai
17
+
18
+ # These will be set by the templaing system.
19
+ ENV CLARIFAI_PAT=${CLARIFAI_PAT}
20
+ ENV CLARIFAI_USER_ID=${CLARIFAI_USER_ID}
21
+ ENV CLARIFAI_RUNNER_ID=${CLARIFAI_RUNNER_ID}
22
+ ENV CLARIFAI_NODEPOOL_ID=${CLARIFAI_NODEPOOL_ID}
23
+ ENV CLARIFAI_COMPUTE_CLUSTER_ID=${CLARIFAI_COMPUTE_CLUSTER_ID}
24
+ ENV CLARIFAI_API_BASE=${CLARIFAI_API_BASE}
25
+
26
+ # Set the NUMBA cache dir to /tmp
27
+ ENV NUMBA_CACHE_DIR=/tmp/numba_cache
28
+ ENV HOME=/tmp
29
+
30
+ # Set the working directory to /app
31
+ WORKDIR /app
32
+
33
+ # Copy the current folder into /app/model_dir that the SDK will expect.
34
+ # Note(zeiler): would be nice to exclude checkpoints in case they were pre-downloaded.
35
+ COPY . /app/model_dir/${name}
36
+
37
+ # Add the model directory to the python path.
38
+ ENV PYTHONPATH=${PYTHONPATH}:/app/model_dir/${name}
39
+
40
+ # Finally run the clarifai entrypoint to start the runner loop and local dev server.
41
+ # Note(zeiler): we may want to make this a clarifai CLI call.
42
+ CMD ["-m", "clarifai.runners.server", "--model_path", "/app/model_dir/${name}"]
@@ -0,0 +1,71 @@
1
+ FROM nvcr.io/nim/meta/llama-3.1-8b-instruct:1.1.2 as build
2
+
3
+ FROM gcr.io/distroless/python3-debian12:debug
4
+
5
+
6
+ COPY --from=build /bin/bash /bin/rbash
7
+ COPY --from=build /bin/sh /bin/sh
8
+ COPY --from=build /bin/rsh /bin/rsh
9
+
10
+ # we have to overwrite the python3 binary that the distroless image uses
11
+ COPY --from=build /opt/nim/llm/.venv/bin/python3.10 /usr/bin/python3
12
+ COPY --from=build /opt/nim/llm/.venv/bin/python3.10 /usr/local/bin/python3.10
13
+
14
+ # also copy in all the lib files for it.
15
+ COPY --from=build /lib /lib
16
+ COPY --from=build /lib64 /lib64
17
+ COPY --from=build /usr/lib/ /usr/lib/
18
+ COPY --from=build /usr/local/lib/ /usr/local/lib/
19
+ # ldconfig is needed to update the shared library cache so system libraries (like CUDA) can be found
20
+ COPY --from=build /usr/sbin/ldconfig /sbin/ldconfig
21
+ COPY --from=build /usr/sbin/ldconfig.real /sbin/ldconfig.real
22
+ COPY --from=build /etc/ld.so.conf /etc/ld.so.conf
23
+ COPY --from=build /etc/ld.so.cache /etc/ld.so.cache
24
+ COPY --from=build /etc/ld.so.conf.d/ /etc/ld.so.conf.d/
25
+
26
+ # COPY NIM files
27
+ COPY --from=build /opt /opt
28
+ COPY --from=build /etc/nim /etc/nim
29
+
30
+ # Set environment variables to use the nim libraries and python
31
+ ENV PYTHONPATH=${PYTHONPATH}:/opt/nim/llm/.venv/lib/python3.10/site-packages:/opt/nim/llm
32
+ ENV PATH="/opt/nim/llm/.venv/bin:/opt/hpcx/ucc/bin:/opt/hpcx/ucx/bin:/opt/hpcx/ompi/bin:$PATH"
33
+
34
+ ENV LD_LIBRARY_PATH="/opt/hpcx/ucc/lib/ucc:/opt/hpcx/ucc/lib:/opt/hpcx/ucx/lib/ucx:/opt/hpcx/ucx/lib:/opt/hpcx/ompi/lib:/opt/hpcx/ompi/lib/openmpi:/opt/nim/llm/.venv/lib/python3.10/site-packages/tensorrt_llm/libs:/opt/nim/llm/.venv/lib/python3.10/site-packages/nvidia/cublas/lib:/opt/nim/llm/.venv/lib/python3.10/site-packages/tensorrt_libs:/opt/nim/llm/.venv/lib/python3.10/site-packages/nvidia/nccl/lib:$LD_LIBRARY_PATH"
35
+
36
+ ENV LIBRARY_PATH=/opt/hpcx/ucc/lib:/opt/hpcx/ucx/lib:/opt/hpcx/ompi/lib:$LIBRARY_PATH
37
+
38
+ ENV CPATH=/opt/hpcx/ompi/include:/opt/hpcx/ucc/include:/opt/hpcx/ucx/include:$CPATH
39
+ ENV LLM_PROJECT_DIR=/opt/nim/llm
40
+
41
+ # Set environment variables for MPI
42
+ ENV OMPI_HOME=/opt/hpcx/ompi
43
+ ENV HPCX_MPI_DIR=/opt/hpcx/ompi
44
+ ENV MPIf_HOME=/opt/hpcx/ompi
45
+ ENV OPAL_PREFIX=/opt/hpcx/ompi
46
+
47
+ # Set environment variables for UCC
48
+ ENV UCC_DIR=/opt/hpcx/ucc/lib/cmake/ucc
49
+ ENV UCC_HOME=/opt/hpcx/ucc
50
+ ENV HPCX_UCC_DIR=/opt/hpcx/ucc
51
+ ENV USE_UCC=1
52
+ ENV USE_SYSTEM_UCC=1
53
+
54
+ # Set environment variables for HPC-X
55
+ ENV HPCX_DIR=/opt/hpcx
56
+ ENV HPCX_UCX_DIR=/opt/hpcx/ucx
57
+ ENV HPCX_MPI_DIR=/opt/hpcx/ompi
58
+
59
+ # Set environment variables for UCX
60
+ ENV UCX_DIR=/opt/hpcx/ucx/lib/cmake/ucx
61
+ ENV UCX_HOME=/opt/hpcx/ucx
62
+
63
+ ENV HOME=/opt/nim/llm
64
+
65
+ # ln is needed to create symbolic links (needed by nvidia-container-runtime)
66
+ COPY --from=build /usr/bin/ln /usr/bin/ln
67
+
68
+ # Run ldconfig in the build stage to update the library cache else CUDA libraries won't be found
69
+ RUN ldconfig -v
70
+
71
+ SHELL ["/bin/rbash", "-c"]
@@ -267,9 +267,18 @@ class ModelBuilder:
267
267
  """
268
268
  model_class = self.load_model_class()
269
269
  method_info = model_class._get_method_info()
270
- signatures = {name: m.signature for name, m in method_info.items()}
270
+ signatures = {name: m.signature for name, m in method_info.values()}
271
271
  return signatures_to_yaml(signatures)
272
272
 
273
+ def get_method_signatures(self):
274
+ """
275
+ Returns the method signatures for the model class.
276
+ """
277
+ model_class = self.load_model_class()
278
+ method_info = model_class._get_method_info()
279
+ signatures = [method.signature for method in method_info.values()]
280
+ return signatures
281
+
273
282
  @property
274
283
  def client(self):
275
284
  if self._client is None:
@@ -553,6 +562,8 @@ class ModelBuilder:
553
562
  pretrained_model_config=resources_pb2.PretrainedModelConfig(),
554
563
  inference_compute_info=self.inference_compute_info,
555
564
  )
565
+ # TODO: update this to `model_signatures` field when it's available in the API
566
+ model_version_proto.model_signature.extend(self.get_method_signatures())
556
567
 
557
568
  model_type_id = self.config.get('model').get('model_type_id')
558
569
  if model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE: