clarifai 11.3.0rc2__py3-none-any.whl → 11.4.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 (300) hide show
  1. clarifai/__init__.py +1 -1
  2. clarifai/cli/__main__.py +1 -1
  3. clarifai/cli/base.py +144 -136
  4. clarifai/cli/compute_cluster.py +45 -31
  5. clarifai/cli/deployment.py +93 -76
  6. clarifai/cli/model.py +578 -180
  7. clarifai/cli/nodepool.py +100 -82
  8. clarifai/client/__init__.py +12 -2
  9. clarifai/client/app.py +973 -911
  10. clarifai/client/auth/helper.py +345 -342
  11. clarifai/client/auth/register.py +7 -7
  12. clarifai/client/auth/stub.py +107 -106
  13. clarifai/client/base.py +185 -178
  14. clarifai/client/compute_cluster.py +214 -180
  15. clarifai/client/dataset.py +793 -698
  16. clarifai/client/deployment.py +55 -50
  17. clarifai/client/input.py +1223 -1088
  18. clarifai/client/lister.py +47 -45
  19. clarifai/client/model.py +1939 -1717
  20. clarifai/client/model_client.py +525 -502
  21. clarifai/client/module.py +82 -73
  22. clarifai/client/nodepool.py +358 -213
  23. clarifai/client/runner.py +58 -0
  24. clarifai/client/search.py +342 -309
  25. clarifai/client/user.py +419 -414
  26. clarifai/client/workflow.py +294 -274
  27. clarifai/constants/dataset.py +11 -17
  28. clarifai/constants/model.py +8 -2
  29. clarifai/datasets/export/inputs_annotations.py +233 -217
  30. clarifai/datasets/upload/base.py +63 -51
  31. clarifai/datasets/upload/features.py +43 -38
  32. clarifai/datasets/upload/image.py +237 -207
  33. clarifai/datasets/upload/loaders/coco_captions.py +34 -32
  34. clarifai/datasets/upload/loaders/coco_detection.py +72 -65
  35. clarifai/datasets/upload/loaders/imagenet_classification.py +57 -53
  36. clarifai/datasets/upload/loaders/xview_detection.py +274 -132
  37. clarifai/datasets/upload/multimodal.py +55 -46
  38. clarifai/datasets/upload/text.py +55 -47
  39. clarifai/datasets/upload/utils.py +250 -234
  40. clarifai/errors.py +51 -50
  41. clarifai/models/api.py +260 -238
  42. clarifai/modules/css.py +50 -50
  43. clarifai/modules/pages.py +33 -33
  44. clarifai/rag/rag.py +312 -288
  45. clarifai/rag/utils.py +91 -84
  46. clarifai/runners/models/model_builder.py +906 -802
  47. clarifai/runners/models/model_class.py +370 -331
  48. clarifai/runners/models/model_run_locally.py +459 -419
  49. clarifai/runners/models/model_runner.py +170 -162
  50. clarifai/runners/models/model_servicer.py +78 -70
  51. clarifai/runners/server.py +111 -101
  52. clarifai/runners/utils/code_script.py +225 -187
  53. clarifai/runners/utils/const.py +4 -1
  54. clarifai/runners/utils/data_types/__init__.py +12 -0
  55. clarifai/runners/utils/data_types/data_types.py +598 -0
  56. clarifai/runners/utils/data_utils.py +387 -440
  57. clarifai/runners/utils/loader.py +247 -227
  58. clarifai/runners/utils/method_signatures.py +411 -386
  59. clarifai/runners/utils/openai_convertor.py +108 -109
  60. clarifai/runners/utils/serializers.py +175 -179
  61. clarifai/runners/utils/url_fetcher.py +35 -35
  62. clarifai/schema/search.py +56 -63
  63. clarifai/urls/helper.py +125 -102
  64. clarifai/utils/cli.py +129 -123
  65. clarifai/utils/config.py +127 -87
  66. clarifai/utils/constants.py +49 -0
  67. clarifai/utils/evaluation/helpers.py +503 -466
  68. clarifai/utils/evaluation/main.py +431 -393
  69. clarifai/utils/evaluation/testset_annotation_parser.py +154 -144
  70. clarifai/utils/logging.py +324 -306
  71. clarifai/utils/misc.py +60 -56
  72. clarifai/utils/model_train.py +165 -146
  73. clarifai/utils/protobuf.py +126 -103
  74. clarifai/versions.py +3 -1
  75. clarifai/workflows/export.py +48 -50
  76. clarifai/workflows/utils.py +39 -36
  77. clarifai/workflows/validate.py +55 -43
  78. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/METADATA +16 -6
  79. clarifai-11.4.0.dist-info/RECORD +109 -0
  80. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/WHEEL +1 -1
  81. clarifai/__pycache__/__init__.cpython-310.pyc +0 -0
  82. clarifai/__pycache__/__init__.cpython-311.pyc +0 -0
  83. clarifai/__pycache__/__init__.cpython-39.pyc +0 -0
  84. clarifai/__pycache__/errors.cpython-310.pyc +0 -0
  85. clarifai/__pycache__/errors.cpython-311.pyc +0 -0
  86. clarifai/__pycache__/versions.cpython-310.pyc +0 -0
  87. clarifai/__pycache__/versions.cpython-311.pyc +0 -0
  88. clarifai/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  89. clarifai/cli/__pycache__/__init__.cpython-311.pyc +0 -0
  90. clarifai/cli/__pycache__/base.cpython-310.pyc +0 -0
  91. clarifai/cli/__pycache__/base.cpython-311.pyc +0 -0
  92. clarifai/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  93. clarifai/cli/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  94. clarifai/cli/__pycache__/compute_cluster.cpython-311.pyc +0 -0
  95. clarifai/cli/__pycache__/deployment.cpython-310.pyc +0 -0
  96. clarifai/cli/__pycache__/deployment.cpython-311.pyc +0 -0
  97. clarifai/cli/__pycache__/model.cpython-310.pyc +0 -0
  98. clarifai/cli/__pycache__/model.cpython-311.pyc +0 -0
  99. clarifai/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  100. clarifai/cli/__pycache__/nodepool.cpython-310.pyc +0 -0
  101. clarifai/cli/__pycache__/nodepool.cpython-311.pyc +0 -0
  102. clarifai/client/__pycache__/__init__.cpython-310.pyc +0 -0
  103. clarifai/client/__pycache__/__init__.cpython-311.pyc +0 -0
  104. clarifai/client/__pycache__/__init__.cpython-39.pyc +0 -0
  105. clarifai/client/__pycache__/app.cpython-310.pyc +0 -0
  106. clarifai/client/__pycache__/app.cpython-311.pyc +0 -0
  107. clarifai/client/__pycache__/app.cpython-39.pyc +0 -0
  108. clarifai/client/__pycache__/base.cpython-310.pyc +0 -0
  109. clarifai/client/__pycache__/base.cpython-311.pyc +0 -0
  110. clarifai/client/__pycache__/compute_cluster.cpython-310.pyc +0 -0
  111. clarifai/client/__pycache__/compute_cluster.cpython-311.pyc +0 -0
  112. clarifai/client/__pycache__/dataset.cpython-310.pyc +0 -0
  113. clarifai/client/__pycache__/dataset.cpython-311.pyc +0 -0
  114. clarifai/client/__pycache__/deployment.cpython-310.pyc +0 -0
  115. clarifai/client/__pycache__/deployment.cpython-311.pyc +0 -0
  116. clarifai/client/__pycache__/input.cpython-310.pyc +0 -0
  117. clarifai/client/__pycache__/input.cpython-311.pyc +0 -0
  118. clarifai/client/__pycache__/lister.cpython-310.pyc +0 -0
  119. clarifai/client/__pycache__/lister.cpython-311.pyc +0 -0
  120. clarifai/client/__pycache__/model.cpython-310.pyc +0 -0
  121. clarifai/client/__pycache__/model.cpython-311.pyc +0 -0
  122. clarifai/client/__pycache__/module.cpython-310.pyc +0 -0
  123. clarifai/client/__pycache__/module.cpython-311.pyc +0 -0
  124. clarifai/client/__pycache__/nodepool.cpython-310.pyc +0 -0
  125. clarifai/client/__pycache__/nodepool.cpython-311.pyc +0 -0
  126. clarifai/client/__pycache__/search.cpython-310.pyc +0 -0
  127. clarifai/client/__pycache__/search.cpython-311.pyc +0 -0
  128. clarifai/client/__pycache__/user.cpython-310.pyc +0 -0
  129. clarifai/client/__pycache__/user.cpython-311.pyc +0 -0
  130. clarifai/client/__pycache__/workflow.cpython-310.pyc +0 -0
  131. clarifai/client/__pycache__/workflow.cpython-311.pyc +0 -0
  132. clarifai/client/auth/__pycache__/__init__.cpython-310.pyc +0 -0
  133. clarifai/client/auth/__pycache__/__init__.cpython-311.pyc +0 -0
  134. clarifai/client/auth/__pycache__/helper.cpython-310.pyc +0 -0
  135. clarifai/client/auth/__pycache__/helper.cpython-311.pyc +0 -0
  136. clarifai/client/auth/__pycache__/register.cpython-310.pyc +0 -0
  137. clarifai/client/auth/__pycache__/register.cpython-311.pyc +0 -0
  138. clarifai/client/auth/__pycache__/stub.cpython-310.pyc +0 -0
  139. clarifai/client/auth/__pycache__/stub.cpython-311.pyc +0 -0
  140. clarifai/client/cli/__init__.py +0 -0
  141. clarifai/client/cli/__pycache__/__init__.cpython-310.pyc +0 -0
  142. clarifai/client/cli/__pycache__/base_cli.cpython-310.pyc +0 -0
  143. clarifai/client/cli/__pycache__/model_cli.cpython-310.pyc +0 -0
  144. clarifai/client/cli/base_cli.py +0 -88
  145. clarifai/client/cli/model_cli.py +0 -29
  146. clarifai/constants/__pycache__/base.cpython-310.pyc +0 -0
  147. clarifai/constants/__pycache__/base.cpython-311.pyc +0 -0
  148. clarifai/constants/__pycache__/dataset.cpython-310.pyc +0 -0
  149. clarifai/constants/__pycache__/dataset.cpython-311.pyc +0 -0
  150. clarifai/constants/__pycache__/input.cpython-310.pyc +0 -0
  151. clarifai/constants/__pycache__/input.cpython-311.pyc +0 -0
  152. clarifai/constants/__pycache__/model.cpython-310.pyc +0 -0
  153. clarifai/constants/__pycache__/model.cpython-311.pyc +0 -0
  154. clarifai/constants/__pycache__/rag.cpython-310.pyc +0 -0
  155. clarifai/constants/__pycache__/rag.cpython-311.pyc +0 -0
  156. clarifai/constants/__pycache__/search.cpython-310.pyc +0 -0
  157. clarifai/constants/__pycache__/search.cpython-311.pyc +0 -0
  158. clarifai/constants/__pycache__/workflow.cpython-310.pyc +0 -0
  159. clarifai/constants/__pycache__/workflow.cpython-311.pyc +0 -0
  160. clarifai/datasets/__pycache__/__init__.cpython-310.pyc +0 -0
  161. clarifai/datasets/__pycache__/__init__.cpython-311.pyc +0 -0
  162. clarifai/datasets/__pycache__/__init__.cpython-39.pyc +0 -0
  163. clarifai/datasets/export/__pycache__/__init__.cpython-310.pyc +0 -0
  164. clarifai/datasets/export/__pycache__/__init__.cpython-311.pyc +0 -0
  165. clarifai/datasets/export/__pycache__/__init__.cpython-39.pyc +0 -0
  166. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-310.pyc +0 -0
  167. clarifai/datasets/export/__pycache__/inputs_annotations.cpython-311.pyc +0 -0
  168. clarifai/datasets/upload/__pycache__/__init__.cpython-310.pyc +0 -0
  169. clarifai/datasets/upload/__pycache__/__init__.cpython-311.pyc +0 -0
  170. clarifai/datasets/upload/__pycache__/__init__.cpython-39.pyc +0 -0
  171. clarifai/datasets/upload/__pycache__/base.cpython-310.pyc +0 -0
  172. clarifai/datasets/upload/__pycache__/base.cpython-311.pyc +0 -0
  173. clarifai/datasets/upload/__pycache__/features.cpython-310.pyc +0 -0
  174. clarifai/datasets/upload/__pycache__/features.cpython-311.pyc +0 -0
  175. clarifai/datasets/upload/__pycache__/image.cpython-310.pyc +0 -0
  176. clarifai/datasets/upload/__pycache__/image.cpython-311.pyc +0 -0
  177. clarifai/datasets/upload/__pycache__/multimodal.cpython-310.pyc +0 -0
  178. clarifai/datasets/upload/__pycache__/multimodal.cpython-311.pyc +0 -0
  179. clarifai/datasets/upload/__pycache__/text.cpython-310.pyc +0 -0
  180. clarifai/datasets/upload/__pycache__/text.cpython-311.pyc +0 -0
  181. clarifai/datasets/upload/__pycache__/utils.cpython-310.pyc +0 -0
  182. clarifai/datasets/upload/__pycache__/utils.cpython-311.pyc +0 -0
  183. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-311.pyc +0 -0
  184. clarifai/datasets/upload/loaders/__pycache__/__init__.cpython-39.pyc +0 -0
  185. clarifai/datasets/upload/loaders/__pycache__/coco_detection.cpython-311.pyc +0 -0
  186. clarifai/datasets/upload/loaders/__pycache__/imagenet_classification.cpython-311.pyc +0 -0
  187. clarifai/models/__pycache__/__init__.cpython-39.pyc +0 -0
  188. clarifai/modules/__pycache__/__init__.cpython-39.pyc +0 -0
  189. clarifai/rag/__pycache__/__init__.cpython-310.pyc +0 -0
  190. clarifai/rag/__pycache__/__init__.cpython-311.pyc +0 -0
  191. clarifai/rag/__pycache__/__init__.cpython-39.pyc +0 -0
  192. clarifai/rag/__pycache__/rag.cpython-310.pyc +0 -0
  193. clarifai/rag/__pycache__/rag.cpython-311.pyc +0 -0
  194. clarifai/rag/__pycache__/rag.cpython-39.pyc +0 -0
  195. clarifai/rag/__pycache__/utils.cpython-310.pyc +0 -0
  196. clarifai/rag/__pycache__/utils.cpython-311.pyc +0 -0
  197. clarifai/runners/__pycache__/__init__.cpython-310.pyc +0 -0
  198. clarifai/runners/__pycache__/__init__.cpython-311.pyc +0 -0
  199. clarifai/runners/__pycache__/__init__.cpython-39.pyc +0 -0
  200. clarifai/runners/dockerfile_template/Dockerfile.cpu.template +0 -31
  201. clarifai/runners/dockerfile_template/Dockerfile.cuda.template +0 -42
  202. clarifai/runners/dockerfile_template/Dockerfile.nim +0 -71
  203. clarifai/runners/models/__pycache__/__init__.cpython-310.pyc +0 -0
  204. clarifai/runners/models/__pycache__/__init__.cpython-311.pyc +0 -0
  205. clarifai/runners/models/__pycache__/__init__.cpython-39.pyc +0 -0
  206. clarifai/runners/models/__pycache__/base_typed_model.cpython-310.pyc +0 -0
  207. clarifai/runners/models/__pycache__/base_typed_model.cpython-311.pyc +0 -0
  208. clarifai/runners/models/__pycache__/base_typed_model.cpython-39.pyc +0 -0
  209. clarifai/runners/models/__pycache__/model_builder.cpython-311.pyc +0 -0
  210. clarifai/runners/models/__pycache__/model_class.cpython-310.pyc +0 -0
  211. clarifai/runners/models/__pycache__/model_class.cpython-311.pyc +0 -0
  212. clarifai/runners/models/__pycache__/model_run_locally.cpython-310-pytest-7.1.2.pyc +0 -0
  213. clarifai/runners/models/__pycache__/model_run_locally.cpython-310.pyc +0 -0
  214. clarifai/runners/models/__pycache__/model_run_locally.cpython-311.pyc +0 -0
  215. clarifai/runners/models/__pycache__/model_runner.cpython-310.pyc +0 -0
  216. clarifai/runners/models/__pycache__/model_runner.cpython-311.pyc +0 -0
  217. clarifai/runners/models/__pycache__/model_upload.cpython-310.pyc +0 -0
  218. clarifai/runners/models/base_typed_model.py +0 -238
  219. clarifai/runners/models/model_class_refract.py +0 -80
  220. clarifai/runners/models/model_upload.py +0 -607
  221. clarifai/runners/models/temp.py +0 -25
  222. clarifai/runners/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  223. clarifai/runners/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  224. clarifai/runners/utils/__pycache__/__init__.cpython-38.pyc +0 -0
  225. clarifai/runners/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  226. clarifai/runners/utils/__pycache__/buffered_stream.cpython-310.pyc +0 -0
  227. clarifai/runners/utils/__pycache__/buffered_stream.cpython-38.pyc +0 -0
  228. clarifai/runners/utils/__pycache__/buffered_stream.cpython-39.pyc +0 -0
  229. clarifai/runners/utils/__pycache__/const.cpython-310.pyc +0 -0
  230. clarifai/runners/utils/__pycache__/const.cpython-311.pyc +0 -0
  231. clarifai/runners/utils/__pycache__/constants.cpython-310.pyc +0 -0
  232. clarifai/runners/utils/__pycache__/constants.cpython-38.pyc +0 -0
  233. clarifai/runners/utils/__pycache__/constants.cpython-39.pyc +0 -0
  234. clarifai/runners/utils/__pycache__/data_handler.cpython-310.pyc +0 -0
  235. clarifai/runners/utils/__pycache__/data_handler.cpython-311.pyc +0 -0
  236. clarifai/runners/utils/__pycache__/data_handler.cpython-38.pyc +0 -0
  237. clarifai/runners/utils/__pycache__/data_handler.cpython-39.pyc +0 -0
  238. clarifai/runners/utils/__pycache__/data_utils.cpython-310.pyc +0 -0
  239. clarifai/runners/utils/__pycache__/data_utils.cpython-311.pyc +0 -0
  240. clarifai/runners/utils/__pycache__/data_utils.cpython-38.pyc +0 -0
  241. clarifai/runners/utils/__pycache__/data_utils.cpython-39.pyc +0 -0
  242. clarifai/runners/utils/__pycache__/grpc_server.cpython-310.pyc +0 -0
  243. clarifai/runners/utils/__pycache__/grpc_server.cpython-38.pyc +0 -0
  244. clarifai/runners/utils/__pycache__/grpc_server.cpython-39.pyc +0 -0
  245. clarifai/runners/utils/__pycache__/health.cpython-310.pyc +0 -0
  246. clarifai/runners/utils/__pycache__/health.cpython-38.pyc +0 -0
  247. clarifai/runners/utils/__pycache__/health.cpython-39.pyc +0 -0
  248. clarifai/runners/utils/__pycache__/loader.cpython-310.pyc +0 -0
  249. clarifai/runners/utils/__pycache__/loader.cpython-311.pyc +0 -0
  250. clarifai/runners/utils/__pycache__/logging.cpython-310.pyc +0 -0
  251. clarifai/runners/utils/__pycache__/logging.cpython-38.pyc +0 -0
  252. clarifai/runners/utils/__pycache__/logging.cpython-39.pyc +0 -0
  253. clarifai/runners/utils/__pycache__/stream_source.cpython-310.pyc +0 -0
  254. clarifai/runners/utils/__pycache__/stream_source.cpython-39.pyc +0 -0
  255. clarifai/runners/utils/__pycache__/url_fetcher.cpython-310.pyc +0 -0
  256. clarifai/runners/utils/__pycache__/url_fetcher.cpython-311.pyc +0 -0
  257. clarifai/runners/utils/__pycache__/url_fetcher.cpython-38.pyc +0 -0
  258. clarifai/runners/utils/__pycache__/url_fetcher.cpython-39.pyc +0 -0
  259. clarifai/runners/utils/data_handler.py +0 -231
  260. clarifai/runners/utils/data_handler_refract.py +0 -213
  261. clarifai/runners/utils/data_types.py +0 -469
  262. clarifai/runners/utils/logger.py +0 -0
  263. clarifai/runners/utils/openai_format.py +0 -87
  264. clarifai/schema/__pycache__/search.cpython-310.pyc +0 -0
  265. clarifai/schema/__pycache__/search.cpython-311.pyc +0 -0
  266. clarifai/urls/__pycache__/helper.cpython-310.pyc +0 -0
  267. clarifai/urls/__pycache__/helper.cpython-311.pyc +0 -0
  268. clarifai/utils/__pycache__/__init__.cpython-310.pyc +0 -0
  269. clarifai/utils/__pycache__/__init__.cpython-311.pyc +0 -0
  270. clarifai/utils/__pycache__/__init__.cpython-39.pyc +0 -0
  271. clarifai/utils/__pycache__/cli.cpython-310.pyc +0 -0
  272. clarifai/utils/__pycache__/cli.cpython-311.pyc +0 -0
  273. clarifai/utils/__pycache__/config.cpython-311.pyc +0 -0
  274. clarifai/utils/__pycache__/constants.cpython-310.pyc +0 -0
  275. clarifai/utils/__pycache__/constants.cpython-311.pyc +0 -0
  276. clarifai/utils/__pycache__/logging.cpython-310.pyc +0 -0
  277. clarifai/utils/__pycache__/logging.cpython-311.pyc +0 -0
  278. clarifai/utils/__pycache__/misc.cpython-310.pyc +0 -0
  279. clarifai/utils/__pycache__/misc.cpython-311.pyc +0 -0
  280. clarifai/utils/__pycache__/model_train.cpython-310.pyc +0 -0
  281. clarifai/utils/__pycache__/model_train.cpython-311.pyc +0 -0
  282. clarifai/utils/__pycache__/protobuf.cpython-311.pyc +0 -0
  283. clarifai/utils/evaluation/__pycache__/__init__.cpython-311.pyc +0 -0
  284. clarifai/utils/evaluation/__pycache__/__init__.cpython-39.pyc +0 -0
  285. clarifai/utils/evaluation/__pycache__/helpers.cpython-311.pyc +0 -0
  286. clarifai/utils/evaluation/__pycache__/main.cpython-311.pyc +0 -0
  287. clarifai/utils/evaluation/__pycache__/main.cpython-39.pyc +0 -0
  288. clarifai/workflows/__pycache__/__init__.cpython-310.pyc +0 -0
  289. clarifai/workflows/__pycache__/__init__.cpython-311.pyc +0 -0
  290. clarifai/workflows/__pycache__/__init__.cpython-39.pyc +0 -0
  291. clarifai/workflows/__pycache__/export.cpython-310.pyc +0 -0
  292. clarifai/workflows/__pycache__/export.cpython-311.pyc +0 -0
  293. clarifai/workflows/__pycache__/utils.cpython-310.pyc +0 -0
  294. clarifai/workflows/__pycache__/utils.cpython-311.pyc +0 -0
  295. clarifai/workflows/__pycache__/validate.cpython-310.pyc +0 -0
  296. clarifai/workflows/__pycache__/validate.cpython-311.pyc +0 -0
  297. clarifai-11.3.0rc2.dist-info/RECORD +0 -322
  298. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/entry_points.txt +0 -0
  299. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info/licenses}/LICENSE +0 -0
  300. {clarifai-11.3.0rc2.dist-info → clarifai-11.4.0.dist-info}/top_level.txt +0 -0
@@ -2,180 +2,188 @@ from typing import Iterator
2
2
 
3
3
  from clarifai_grpc.grpc.api import service_pb2
4
4
  from clarifai_grpc.grpc.api.status import status_code_pb2, status_pb2
5
-
6
5
  from clarifai_protocol import BaseRunner
7
6
  from clarifai_protocol.utils.health import HealthProbeRequestHandler
8
- from ..utils.url_fetcher import ensure_urls_downloaded
9
7
 
8
+ from ..utils.url_fetcher import ensure_urls_downloaded
10
9
  from .model_class import ModelClass
11
10
 
12
11
 
13
12
  class ModelRunner(BaseRunner, HealthProbeRequestHandler):
14
- """
15
- This is a subclass of the runner class which will handle only the work items relevant to models.
16
- """
17
-
18
- def __init__(
19
- self,
20
- model: ModelClass,
21
- runner_id: str,
22
- nodepool_id: str,
23
- compute_cluster_id: str,
24
- user_id: str = None,
25
- check_runner_exists: bool = True,
26
- base_url: str = "https://api.clarifai.com",
27
- pat: str = None,
28
- token: str = None,
29
- num_parallel_polls: int = 4,
30
- **kwargs,
31
- ) -> None:
32
- super().__init__(
33
- runner_id,
34
- nodepool_id,
35
- compute_cluster_id,
36
- user_id,
37
- check_runner_exists,
38
- base_url,
39
- pat,
40
- token,
41
- num_parallel_polls,
42
- **kwargs,
43
- )
44
- self.model = model
45
-
46
- # After model load successfully set the health probe to ready and startup
47
- HealthProbeRequestHandler.is_ready = True
48
- HealthProbeRequestHandler.is_startup = True
49
-
50
- def get_runner_item_output_for_status(self,
51
- status: status_pb2.Status) -> service_pb2.RunnerItemOutput:
52
13
  """
53
- Set the error message in the RunnerItemOutput message subfield, used during exception handling
54
- where we may only have a status to return.
55
-
56
- Args:
57
- status: status_pb2.Status - the status to return
58
-
59
- Returns:
60
- service_pb2.RunnerItemOutput - the RunnerItemOutput message with the status set
61
- """
62
- rio = service_pb2.RunnerItemOutput(
63
- multi_output_response=service_pb2.MultiOutputResponse(status=status))
64
- return rio
65
-
66
- def runner_item_predict(self,
67
- runner_item: service_pb2.RunnerItem) -> service_pb2.RunnerItemOutput:
14
+ This is a subclass of the runner class which will handle only the work items relevant to models.
68
15
  """
69
- Run the model on the given request. You shouldn't need to override this method, see run_input
70
- for the implementation to process each input in the request.
71
16
 
72
- Args:
73
- request: service_pb2.PostModelOutputsRequest - the request to run the model on
74
-
75
- Returns:
76
- service_pb2.MultiOutputResponse - the response from the model's run_input implementation.
77
- """
78
-
79
- if not runner_item.HasField('post_model_outputs_request'):
80
- raise Exception("Unexpected work item type: {}".format(runner_item))
81
- request = runner_item.post_model_outputs_request
82
- ensure_urls_downloaded(request)
83
-
84
- resp = self.model.predict_wrapper(request)
85
- if resp.status.code != status_code_pb2.SUCCESS:
86
- return service_pb2.RunnerItemOutput(multi_output_response=resp)
87
- successes = [o.status.code == status_code_pb2.SUCCESS for o in resp.outputs]
88
- if all(successes):
89
- status = status_pb2.Status(
90
- code=status_code_pb2.SUCCESS,
91
- description="Success",
92
- )
93
- elif any(successes):
94
- status = status_pb2.Status(
95
- code=status_code_pb2.MIXED_STATUS,
96
- description="Mixed Status",
97
- )
98
- else:
99
- status = status_pb2.Status(
100
- code=status_code_pb2.FAILURE,
101
- description="Failed",
102
- )
103
-
104
- resp.status.CopyFrom(status)
105
- return service_pb2.RunnerItemOutput(multi_output_response=resp)
106
-
107
- def runner_item_generate(
108
- self, runner_item: service_pb2.RunnerItem) -> Iterator[service_pb2.RunnerItemOutput]:
109
- # Call the generate() method the underlying model implements.
110
-
111
- if not runner_item.HasField('post_model_outputs_request'):
112
- raise Exception("Unexpected work item type: {}".format(runner_item))
113
- request = runner_item.post_model_outputs_request
114
- ensure_urls_downloaded(request)
115
-
116
- for resp in self.model.generate_wrapper(request):
117
- if resp.status.code != status_code_pb2.SUCCESS:
118
- yield service_pb2.RunnerItemOutput(multi_output_response=resp)
119
- continue
120
- successes = []
121
- for output in resp.outputs:
122
- if not output.HasField('status') or not output.status.code:
123
- raise Exception("Output must have a status code, please check the model implementation.")
124
- successes.append(output.status.code == status_code_pb2.SUCCESS)
125
- if all(successes):
126
- status = status_pb2.Status(
127
- code=status_code_pb2.SUCCESS,
128
- description="Success",
129
- )
130
- elif any(successes):
131
- status = status_pb2.Status(
132
- code=status_code_pb2.MIXED_STATUS,
133
- description="Mixed Status",
134
- )
135
- else:
136
- status = status_pb2.Status(
137
- code=status_code_pb2.FAILURE,
138
- description="Failed",
139
- )
140
- resp.status.CopyFrom(status)
141
-
142
- yield service_pb2.RunnerItemOutput(multi_output_response=resp)
143
-
144
- def runner_item_stream(self, runner_item_iterator: Iterator[service_pb2.RunnerItem]
145
- ) -> Iterator[service_pb2.RunnerItemOutput]:
146
- # Call the generate() method the underlying model implements.
147
- for resp in self.model.stream_wrapper(pmo_iterator(runner_item_iterator)):
148
- if resp.status.code != status_code_pb2.SUCCESS:
149
- yield service_pb2.RunnerItemOutput(multi_output_response=resp)
150
- continue
151
- successes = []
152
- for output in resp.outputs:
153
- if not output.HasField('status') or not output.status.code:
154
- raise Exception("Output must have a status code, please check the model implementation.")
155
- successes.append(output.status.code == status_code_pb2.SUCCESS)
156
- if all(successes):
157
- status = status_pb2.Status(
158
- code=status_code_pb2.SUCCESS,
159
- description="Success",
160
- )
161
- elif any(successes):
162
- status = status_pb2.Status(
163
- code=status_code_pb2.MIXED_STATUS,
164
- description="Mixed Status",
17
+ def __init__(
18
+ self,
19
+ model: ModelClass,
20
+ runner_id: str,
21
+ nodepool_id: str,
22
+ compute_cluster_id: str,
23
+ user_id: str = None,
24
+ check_runner_exists: bool = True,
25
+ base_url: str = "https://api.clarifai.com",
26
+ pat: str = None,
27
+ token: str = None,
28
+ num_parallel_polls: int = 4,
29
+ **kwargs,
30
+ ) -> None:
31
+ super().__init__(
32
+ runner_id,
33
+ nodepool_id,
34
+ compute_cluster_id,
35
+ user_id,
36
+ check_runner_exists,
37
+ base_url,
38
+ pat,
39
+ token,
40
+ num_parallel_polls,
41
+ **kwargs,
165
42
  )
166
- else:
167
- status = status_pb2.Status(
168
- code=status_code_pb2.FAILURE,
169
- description="Failed",
43
+ self.model = model
44
+
45
+ # After model load successfully set the health probe to ready and startup
46
+ HealthProbeRequestHandler.is_ready = True
47
+ HealthProbeRequestHandler.is_startup = True
48
+
49
+ def get_runner_item_output_for_status(
50
+ self, status: status_pb2.Status
51
+ ) -> service_pb2.RunnerItemOutput:
52
+ """
53
+ Set the error message in the RunnerItemOutput message subfield, used during exception handling
54
+ where we may only have a status to return.
55
+
56
+ Args:
57
+ status: status_pb2.Status - the status to return
58
+
59
+ Returns:
60
+ service_pb2.RunnerItemOutput - the RunnerItemOutput message with the status set
61
+ """
62
+ rio = service_pb2.RunnerItemOutput(
63
+ multi_output_response=service_pb2.MultiOutputResponse(status=status)
170
64
  )
171
- resp.status.CopyFrom(status)
172
-
173
- yield service_pb2.RunnerItemOutput(multi_output_response=resp)
65
+ return rio
66
+
67
+ def runner_item_predict(
68
+ self, runner_item: service_pb2.RunnerItem
69
+ ) -> service_pb2.RunnerItemOutput:
70
+ """
71
+ Run the model on the given request. You shouldn't need to override this method, see run_input
72
+ for the implementation to process each input in the request.
73
+
74
+ Args:
75
+ request: service_pb2.PostModelOutputsRequest - the request to run the model on
76
+
77
+ Returns:
78
+ service_pb2.MultiOutputResponse - the response from the model's run_input implementation.
79
+ """
80
+
81
+ if not runner_item.HasField('post_model_outputs_request'):
82
+ raise Exception("Unexpected work item type: {}".format(runner_item))
83
+ request = runner_item.post_model_outputs_request
84
+ ensure_urls_downloaded(request)
85
+
86
+ resp = self.model.predict_wrapper(request)
87
+ if resp.status.code != status_code_pb2.SUCCESS:
88
+ return service_pb2.RunnerItemOutput(multi_output_response=resp)
89
+ successes = [o.status.code == status_code_pb2.SUCCESS for o in resp.outputs]
90
+ if all(successes):
91
+ status = status_pb2.Status(
92
+ code=status_code_pb2.SUCCESS,
93
+ description="Success",
94
+ )
95
+ elif any(successes):
96
+ status = status_pb2.Status(
97
+ code=status_code_pb2.MIXED_STATUS,
98
+ description="Mixed Status",
99
+ )
100
+ else:
101
+ status = status_pb2.Status(
102
+ code=status_code_pb2.FAILURE,
103
+ description="Failed",
104
+ )
105
+
106
+ resp.status.CopyFrom(status)
107
+ return service_pb2.RunnerItemOutput(multi_output_response=resp)
108
+
109
+ def runner_item_generate(
110
+ self, runner_item: service_pb2.RunnerItem
111
+ ) -> Iterator[service_pb2.RunnerItemOutput]:
112
+ # Call the generate() method the underlying model implements.
113
+
114
+ if not runner_item.HasField('post_model_outputs_request'):
115
+ raise Exception("Unexpected work item type: {}".format(runner_item))
116
+ request = runner_item.post_model_outputs_request
117
+ ensure_urls_downloaded(request)
118
+
119
+ for resp in self.model.generate_wrapper(request):
120
+ if resp.status.code != status_code_pb2.SUCCESS:
121
+ yield service_pb2.RunnerItemOutput(multi_output_response=resp)
122
+ continue
123
+ successes = []
124
+ for output in resp.outputs:
125
+ if not output.HasField('status') or not output.status.code:
126
+ raise Exception(
127
+ "Output must have a status code, please check the model implementation."
128
+ )
129
+ successes.append(output.status.code == status_code_pb2.SUCCESS)
130
+ if all(successes):
131
+ status = status_pb2.Status(
132
+ code=status_code_pb2.SUCCESS,
133
+ description="Success",
134
+ )
135
+ elif any(successes):
136
+ status = status_pb2.Status(
137
+ code=status_code_pb2.MIXED_STATUS,
138
+ description="Mixed Status",
139
+ )
140
+ else:
141
+ status = status_pb2.Status(
142
+ code=status_code_pb2.FAILURE,
143
+ description="Failed",
144
+ )
145
+ resp.status.CopyFrom(status)
146
+
147
+ yield service_pb2.RunnerItemOutput(multi_output_response=resp)
148
+
149
+ def runner_item_stream(
150
+ self, runner_item_iterator: Iterator[service_pb2.RunnerItem]
151
+ ) -> Iterator[service_pb2.RunnerItemOutput]:
152
+ # Call the generate() method the underlying model implements.
153
+ for resp in self.model.stream_wrapper(pmo_iterator(runner_item_iterator)):
154
+ if resp.status.code != status_code_pb2.SUCCESS:
155
+ yield service_pb2.RunnerItemOutput(multi_output_response=resp)
156
+ continue
157
+ successes = []
158
+ for output in resp.outputs:
159
+ if not output.HasField('status') or not output.status.code:
160
+ raise Exception(
161
+ "Output must have a status code, please check the model implementation."
162
+ )
163
+ successes.append(output.status.code == status_code_pb2.SUCCESS)
164
+ if all(successes):
165
+ status = status_pb2.Status(
166
+ code=status_code_pb2.SUCCESS,
167
+ description="Success",
168
+ )
169
+ elif any(successes):
170
+ status = status_pb2.Status(
171
+ code=status_code_pb2.MIXED_STATUS,
172
+ description="Mixed Status",
173
+ )
174
+ else:
175
+ status = status_pb2.Status(
176
+ code=status_code_pb2.FAILURE,
177
+ description="Failed",
178
+ )
179
+ resp.status.CopyFrom(status)
180
+
181
+ yield service_pb2.RunnerItemOutput(multi_output_response=resp)
174
182
 
175
183
 
176
184
  def pmo_iterator(runner_item_iterator):
177
- for runner_item in runner_item_iterator:
178
- if not runner_item.HasField('post_model_outputs_request'):
179
- raise Exception("Unexpected work item type: {}".format(runner_item))
180
- ensure_urls_downloaded(runner_item.post_model_outputs_request)
181
- yield runner_item.post_model_outputs_request
185
+ for runner_item in runner_item_iterator:
186
+ if not runner_item.HasField('post_model_outputs_request'):
187
+ raise Exception("Unexpected work item type: {}".format(runner_item))
188
+ ensure_urls_downloaded(runner_item.post_model_outputs_request)
189
+ yield runner_item.post_model_outputs_request
@@ -11,83 +11,91 @@ _RAISE_EXCEPTIONS = os.getenv("RAISE_EXCEPTIONS", "false").lower() in ("true", "
11
11
 
12
12
 
13
13
  class ModelServicer(service_pb2_grpc.V2Servicer):
14
- """
15
- This is the servicer that will handle the gRPC requests from either the dev server or runner loop.
16
- """
17
-
18
- def __init__(self, model):
19
14
  """
20
- Args:
21
- model: The class that will handle the model logic. Must implement predict(),
22
- generate(), stream().
15
+ This is the servicer that will handle the gRPC requests from either the dev server or runner loop.
23
16
  """
24
- self.model = model
25
17
 
26
- def PostModelOutputs(self, request: service_pb2.PostModelOutputsRequest,
27
- context=None) -> service_pb2.MultiOutputResponse:
28
- """
29
- This is the method that will be called when the servicer is run. It takes in an input and
30
- returns an output.
31
- """
18
+ def __init__(self, model):
19
+ """
20
+ Args:
21
+ model: The class that will handle the model logic. Must implement predict(),
22
+ generate(), stream().
23
+ """
24
+ self.model = model
32
25
 
33
- # Download any urls that are not already bytes.
34
- ensure_urls_downloaded(request)
26
+ def PostModelOutputs(
27
+ self, request: service_pb2.PostModelOutputsRequest, context=None
28
+ ) -> service_pb2.MultiOutputResponse:
29
+ """
30
+ This is the method that will be called when the servicer is run. It takes in an input and
31
+ returns an output.
32
+ """
35
33
 
36
- try:
37
- return self.model.predict_wrapper(request)
38
- except Exception as e:
39
- if _RAISE_EXCEPTIONS:
40
- raise
41
- return service_pb2.MultiOutputResponse(status=status_pb2.Status(
42
- code=status_code_pb2.MODEL_PREDICTION_FAILED,
43
- description="Failed",
44
- details="",
45
- internal_details=str(e),
46
- ))
34
+ # Download any urls that are not already bytes.
35
+ ensure_urls_downloaded(request)
47
36
 
48
- def GenerateModelOutputs(self, request: service_pb2.PostModelOutputsRequest,
49
- context=None) -> Iterator[service_pb2.MultiOutputResponse]:
50
- """
51
- This is the method that will be called when the servicer is run. It takes in an input and
52
- returns an output.
53
- """
54
- # Download any urls that are not already bytes.
55
- ensure_urls_downloaded(request)
37
+ try:
38
+ return self.model.predict_wrapper(request)
39
+ except Exception as e:
40
+ if _RAISE_EXCEPTIONS:
41
+ raise
42
+ return service_pb2.MultiOutputResponse(
43
+ status=status_pb2.Status(
44
+ code=status_code_pb2.MODEL_PREDICTION_FAILED,
45
+ description="Failed",
46
+ details="",
47
+ internal_details=str(e),
48
+ )
49
+ )
56
50
 
57
- try:
58
- yield from self.model.generate_wrapper(request)
59
- except Exception as e:
60
- if _RAISE_EXCEPTIONS:
61
- raise
62
- yield service_pb2.MultiOutputResponse(status=status_pb2.Status(
63
- code=status_code_pb2.MODEL_PREDICTION_FAILED,
64
- description="Failed",
65
- details="",
66
- internal_details=str(e),
67
- ))
51
+ def GenerateModelOutputs(
52
+ self, request: service_pb2.PostModelOutputsRequest, context=None
53
+ ) -> Iterator[service_pb2.MultiOutputResponse]:
54
+ """
55
+ This is the method that will be called when the servicer is run. It takes in an input and
56
+ returns an output.
57
+ """
58
+ # Download any urls that are not already bytes.
59
+ ensure_urls_downloaded(request)
68
60
 
69
- def StreamModelOutputs(self,
70
- request: Iterator[service_pb2.PostModelOutputsRequest],
71
- context=None) -> Iterator[service_pb2.MultiOutputResponse]:
72
- """
73
- This is the method that will be called when the servicer is run. It takes in an input and
74
- returns an output.
75
- """
76
- # Duplicate the iterator
77
- request, request_copy = tee(request)
61
+ try:
62
+ yield from self.model.generate_wrapper(request)
63
+ except Exception as e:
64
+ if _RAISE_EXCEPTIONS:
65
+ raise
66
+ yield service_pb2.MultiOutputResponse(
67
+ status=status_pb2.Status(
68
+ code=status_code_pb2.MODEL_PREDICTION_FAILED,
69
+ description="Failed",
70
+ details="",
71
+ internal_details=str(e),
72
+ )
73
+ )
74
+
75
+ def StreamModelOutputs(
76
+ self, request: Iterator[service_pb2.PostModelOutputsRequest], context=None
77
+ ) -> Iterator[service_pb2.MultiOutputResponse]:
78
+ """
79
+ This is the method that will be called when the servicer is run. It takes in an input and
80
+ returns an output.
81
+ """
82
+ # Duplicate the iterator
83
+ request, request_copy = tee(request)
78
84
 
79
- # Download any urls that are not already bytes.
80
- for req in request:
81
- ensure_urls_downloaded(req)
85
+ # Download any urls that are not already bytes.
86
+ for req in request:
87
+ ensure_urls_downloaded(req)
82
88
 
83
- try:
84
- yield from self.model.stream_wrapper(request_copy)
85
- except Exception as e:
86
- if _RAISE_EXCEPTIONS:
87
- raise
88
- yield service_pb2.MultiOutputResponse(status=status_pb2.Status(
89
- code=status_code_pb2.MODEL_PREDICTION_FAILED,
90
- description="Failed",
91
- details="",
92
- internal_details=str(e),
93
- ))
89
+ try:
90
+ yield from self.model.stream_wrapper(request_copy)
91
+ except Exception as e:
92
+ if _RAISE_EXCEPTIONS:
93
+ raise
94
+ yield service_pb2.MultiOutputResponse(
95
+ status=status_pb2.Status(
96
+ code=status_code_pb2.MODEL_PREDICTION_FAILED,
97
+ description="Failed",
98
+ details="",
99
+ internal_details=str(e),
100
+ )
101
+ )