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
@@ -11,236 +11,256 @@ from clarifai.utils.logging import logger
11
11
 
12
12
 
13
13
  class HuggingFaceLoader:
14
-
15
- HF_DOWNLOAD_TEXT = "The 'huggingface_hub' package is not installed. Please install it using 'pip install huggingface_hub'."
16
-
17
- def __init__(self, repo_id=None, token=None, model_type_id=None):
18
- self.repo_id = repo_id
19
- self.token = token
20
- self.clarifai_model_type_id = model_type_id
21
- if token:
22
- if self.validate_hftoken(token):
14
+ HF_DOWNLOAD_TEXT = "The 'huggingface_hub' package is not installed. Please install it using 'pip install huggingface_hub'."
15
+
16
+ def __init__(self, repo_id=None, token=None, model_type_id=None):
17
+ self.repo_id = repo_id
18
+ self.token = token
19
+ self.clarifai_model_type_id = model_type_id
20
+ if token:
21
+ if self.validate_hftoken(token):
22
+ try:
23
+ from huggingface_hub import login
24
+ except ImportError:
25
+ raise ImportError(self.HF_DOWNLOAD_TEXT)
26
+ login(token=token)
27
+ logger.info("Hugging Face token validated")
28
+ else:
29
+ self.token = None
30
+ logger.info("Continuing without Hugging Face token")
31
+
32
+ @classmethod
33
+ def validate_hftoken(cls, hf_token: str):
34
+ try:
35
+ if importlib.util.find_spec("huggingface_hub") is None:
36
+ raise ImportError(cls.HF_DOWNLOAD_TEXT)
37
+ from huggingface_hub import HfApi
38
+
39
+ api = HfApi()
40
+ api.whoami(token=hf_token)
41
+ return True
42
+ except Exception as e:
43
+ logger.error(
44
+ f"Error setting up Hugging Face token, please make sure you have the correct token: {e}"
45
+ )
46
+ return False
47
+
48
+ def download_checkpoints(
49
+ self, checkpoint_path: str, allowed_file_patterns=None, ignore_file_patterns=None
50
+ ):
51
+ # throw error if huggingface_hub wasn't installed
23
52
  try:
24
- from huggingface_hub import login
53
+ from huggingface_hub import snapshot_download
25
54
  except ImportError:
26
- raise ImportError(self.HF_DOWNLOAD_TEXT)
27
- login(token=token)
28
- logger.info("Hugging Face token validated")
29
- else:
30
- self.token = None
31
- logger.info("Continuing without Hugging Face token")
32
-
33
- @classmethod
34
- def validate_hftoken(cls, hf_token: str):
35
- try:
36
- if importlib.util.find_spec("huggingface_hub") is None:
37
- raise ImportError(cls.HF_DOWNLOAD_TEXT)
38
- from huggingface_hub import HfApi
39
-
40
- api = HfApi()
41
- api.whoami(token=hf_token)
42
- return True
43
- except Exception as e:
44
- logger.error(
45
- f"Error setting up Hugging Face token, please make sure you have the correct token: {e}")
46
- return False
47
-
48
- def download_checkpoints(self,
49
- checkpoint_path: str,
50
- allowed_file_patterns=None,
51
- ignore_file_patterns=None):
52
- # throw error if huggingface_hub wasn't installed
53
- try:
54
- from huggingface_hub import snapshot_download
55
- except ImportError:
56
- raise ImportError(self.HF_DOWNLOAD_TEXT)
57
- if os.path.exists(checkpoint_path) and self.validate_download(
58
- checkpoint_path, allowed_file_patterns, ignore_file_patterns):
59
- logger.info("Checkpoints already exist")
60
- return True
61
- else:
62
- os.makedirs(checkpoint_path, exist_ok=True)
63
- try:
64
- is_hf_model_exists = self.validate_hf_model()
65
- if not is_hf_model_exists:
66
- logger.error("Model %s not found on Hugging Face" % (self.repo_id))
67
- return False
55
+ raise ImportError(self.HF_DOWNLOAD_TEXT)
56
+ if os.path.exists(checkpoint_path) and self.validate_download(
57
+ checkpoint_path, allowed_file_patterns, ignore_file_patterns
58
+ ):
59
+ logger.info("Checkpoints already exist")
60
+ return True
61
+ else:
62
+ os.makedirs(checkpoint_path, exist_ok=True)
63
+ try:
64
+ is_hf_model_exists = self.validate_hf_model()
65
+ if not is_hf_model_exists:
66
+ logger.error("Model %s not found on Hugging Face" % (self.repo_id))
67
+ return False
68
+
69
+ self.ignore_patterns = self._get_ignore_patterns()
70
+ if ignore_file_patterns:
71
+ if self.ignore_patterns:
72
+ self.ignore_patterns.extend(ignore_file_patterns)
73
+ else:
74
+ self.ignore_patterns = ignore_file_patterns
75
+ snapshot_download(
76
+ repo_id=self.repo_id,
77
+ local_dir=checkpoint_path,
78
+ local_dir_use_symlinks=False,
79
+ allow_patterns=allowed_file_patterns,
80
+ ignore_patterns=self.ignore_patterns,
81
+ )
82
+ # Remove the `.cache` folder if it exists
83
+ cache_path = os.path.join(checkpoint_path, ".cache")
84
+ if os.path.exists(cache_path) and os.path.isdir(cache_path):
85
+ shutil.rmtree(cache_path)
86
+
87
+ except Exception as e:
88
+ logger.error(f"Error downloading model checkpoints {e}")
89
+ return False
90
+ finally:
91
+ is_downloaded = self.validate_download(
92
+ checkpoint_path, allowed_file_patterns, ignore_file_patterns
93
+ )
94
+ if not is_downloaded:
95
+ logger.error("Error validating downloaded model checkpoints")
96
+ return False
97
+ return True
98
+
99
+ def download_config(self, checkpoint_path: str):
100
+ # throw error if huggingface_hub wasn't installed
101
+ try:
102
+ from huggingface_hub import hf_hub_download
103
+ except ImportError:
104
+ raise ImportError(self.HF_DOWNLOAD_TEXT)
105
+ if os.path.exists(checkpoint_path) and os.path.exists(
106
+ os.path.join(checkpoint_path, 'config.json')
107
+ ):
108
+ logger.info("HF model's config.json already exists")
109
+ return True
110
+ os.makedirs(checkpoint_path, exist_ok=True)
111
+ try:
112
+ is_hf_model_exists = self.validate_hf_model()
113
+ if not is_hf_model_exists:
114
+ logger.error("Model %s not found on Hugging Face" % (self.repo_id))
115
+ return False
116
+ hf_hub_download(
117
+ repo_id=self.repo_id, filename='config.json', local_dir=checkpoint_path
118
+ )
119
+ except Exception as e:
120
+ logger.error(f"Error downloading model's config.json {e}")
121
+ return False
122
+ return True
123
+
124
+ def validate_hf_model(
125
+ self,
126
+ ):
127
+ # check if model exists on HF
128
+ try:
129
+ from huggingface_hub import file_exists, repo_exists
130
+ except ImportError:
131
+ raise ImportError(self.HF_DOWNLOAD_TEXT)
132
+ if self.clarifai_model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE:
133
+ return repo_exists(self.repo_id) and file_exists(self.repo_id, 'config.json')
134
+ else:
135
+ return repo_exists(self.repo_id)
136
+
137
+ def validate_download(
138
+ self, checkpoint_path: str, allowed_file_patterns: list, ignore_file_patterns: list
139
+ ):
140
+ # check if model exists on HF
141
+ try:
142
+ from huggingface_hub import list_repo_files
143
+ except ImportError:
144
+ raise ImportError(self.HF_DOWNLOAD_TEXT)
145
+ # Get the list of files on the repo
146
+ repo_files = list_repo_files(self.repo_id, token=self.token)
147
+
148
+ # Get the list of files on the repo that are allowed
149
+ if allowed_file_patterns:
150
+
151
+ def should_allow(file_path):
152
+ return any(
153
+ fnmatch.fnmatch(file_path, pattern) for pattern in allowed_file_patterns
154
+ )
155
+
156
+ repo_files = [f for f in repo_files if should_allow(f)]
68
157
 
69
158
  self.ignore_patterns = self._get_ignore_patterns()
70
159
  if ignore_file_patterns:
71
- if self.ignore_patterns:
72
- self.ignore_patterns.extend(ignore_file_patterns)
73
- else:
74
- self.ignore_patterns = ignore_file_patterns
75
- snapshot_download(
76
- repo_id=self.repo_id,
77
- local_dir=checkpoint_path,
78
- local_dir_use_symlinks=False,
79
- allow_patterns=allowed_file_patterns,
80
- ignore_patterns=self.ignore_patterns)
81
- # Remove the `.cache` folder if it exists
82
- cache_path = os.path.join(checkpoint_path, ".cache")
83
- if os.path.exists(cache_path) and os.path.isdir(cache_path):
84
- shutil.rmtree(cache_path)
85
-
86
- except Exception as e:
87
- logger.error(f"Error downloading model checkpoints {e}")
88
- return False
89
- finally:
90
- is_downloaded = self.validate_download(checkpoint_path, allowed_file_patterns,
91
- ignore_file_patterns)
92
- if not is_downloaded:
93
- logger.error("Error validating downloaded model checkpoints")
94
- return False
95
- return True
96
-
97
- def download_config(self, checkpoint_path: str):
98
- # throw error if huggingface_hub wasn't installed
99
- try:
100
- from huggingface_hub import hf_hub_download
101
- except ImportError:
102
- raise ImportError(self.HF_DOWNLOAD_TEXT)
103
- if os.path.exists(checkpoint_path) and os.path.exists(
104
- os.path.join(checkpoint_path, 'config.json')):
105
- logger.info("HF model's config.json already exists")
106
- return True
107
- os.makedirs(checkpoint_path, exist_ok=True)
108
- try:
109
- is_hf_model_exists = self.validate_hf_model()
110
- if not is_hf_model_exists:
111
- logger.error("Model %s not found on Hugging Face" % (self.repo_id))
160
+ if self.ignore_patterns:
161
+ self.ignore_patterns.extend(ignore_file_patterns)
162
+ else:
163
+ self.ignore_patterns = ignore_file_patterns
164
+ # Get the list of files on the repo that are not ignored
165
+ if getattr(self, "ignore_patterns", None):
166
+ patterns = self.ignore_patterns
167
+
168
+ def should_ignore(file_path):
169
+ return any(fnmatch.fnmatch(file_path, pattern) for pattern in patterns)
170
+
171
+ repo_files = [f for f in repo_files if not should_ignore(f)]
172
+
173
+ # Check if downloaded files match the files we expect (ignoring ignored patterns)
174
+ checkpoint_dir_files = []
175
+ for dp, dn, fn in os.walk(os.path.expanduser(checkpoint_path)):
176
+ checkpoint_dir_files.extend(
177
+ [os.path.relpath(os.path.join(dp, f), checkpoint_path) for f in fn]
178
+ )
179
+
180
+ # Validate by comparing file lists
181
+ return (
182
+ len(checkpoint_dir_files) >= len(repo_files)
183
+ and not (len(set(repo_files) - set(checkpoint_dir_files)) > 0)
184
+ and len(repo_files) > 0
185
+ )
186
+
187
+ def _get_ignore_patterns(self):
188
+ # check if model exists on HF
189
+ try:
190
+ from huggingface_hub import list_repo_files
191
+ except ImportError:
192
+ raise ImportError(self.HF_DOWNLOAD_TEXT)
193
+
194
+ # Get the list of files on the repo that are not ignored
195
+ repo_files = list_repo_files(self.repo_id, token=self.token)
196
+ self.ignore_patterns = None
197
+ if any(f.endswith(".safetensors") for f in repo_files):
198
+ self.ignore_patterns = [
199
+ "**/original/*",
200
+ "**/*.pth",
201
+ "**/*.bin",
202
+ "*.pth",
203
+ "*.bin",
204
+ "**/.cache/*",
205
+ ]
206
+ return self.ignore_patterns
207
+
208
+ @staticmethod
209
+ def validate_config(checkpoint_path: str):
210
+ # check if downloaded config.json exists
211
+ return os.path.exists(checkpoint_path) and os.path.exists(
212
+ os.path.join(checkpoint_path, 'config.json')
213
+ )
214
+
215
+ @staticmethod
216
+ def validate_concept(checkpoint_path: str):
217
+ # check if downloaded concept exists in hf model
218
+ config_path = os.path.join(checkpoint_path, 'config.json')
219
+ with open(config_path, 'r') as f:
220
+ config = json.load(f)
221
+
222
+ labels = config.get('id2label', None)
223
+ if labels:
224
+ return True
112
225
  return False
113
- hf_hub_download(repo_id=self.repo_id, filename='config.json', local_dir=checkpoint_path)
114
- except Exception as e:
115
- logger.error(f"Error downloading model's config.json {e}")
116
- return False
117
- return True
118
-
119
- def validate_hf_model(self,):
120
- # check if model exists on HF
121
- try:
122
- from huggingface_hub import file_exists, repo_exists
123
- except ImportError:
124
- raise ImportError(self.HF_DOWNLOAD_TEXT)
125
- if self.clarifai_model_type_id in CONCEPTS_REQUIRED_MODEL_TYPE:
126
- return repo_exists(self.repo_id) and file_exists(self.repo_id, 'config.json')
127
- else:
128
- return repo_exists(self.repo_id)
129
-
130
- def validate_download(self, checkpoint_path: str, allowed_file_patterns: list,
131
- ignore_file_patterns: list):
132
- # check if model exists on HF
133
- try:
134
- from huggingface_hub import list_repo_files
135
- except ImportError:
136
- raise ImportError(self.HF_DOWNLOAD_TEXT)
137
- # Get the list of files on the repo
138
- repo_files = list_repo_files(self.repo_id, token=self.token)
139
-
140
- # Get the list of files on the repo that are allowed
141
- if allowed_file_patterns:
142
-
143
- def should_allow(file_path):
144
- return any(fnmatch.fnmatch(file_path, pattern) for pattern in allowed_file_patterns)
145
-
146
- repo_files = [f for f in repo_files if should_allow(f)]
147
-
148
- self.ignore_patterns = self._get_ignore_patterns()
149
- if ignore_file_patterns:
150
- if self.ignore_patterns:
151
- self.ignore_patterns.extend(ignore_file_patterns)
152
- else:
153
- self.ignore_patterns = ignore_file_patterns
154
- # Get the list of files on the repo that are not ignored
155
- if getattr(self, "ignore_patterns", None):
156
- patterns = self.ignore_patterns
157
-
158
- def should_ignore(file_path):
159
- return any(fnmatch.fnmatch(file_path, pattern) for pattern in patterns)
160
-
161
- repo_files = [f for f in repo_files if not should_ignore(f)]
162
-
163
- # Check if downloaded files match the files we expect (ignoring ignored patterns)
164
- checkpoint_dir_files = []
165
- for dp, dn, fn in os.walk(os.path.expanduser(checkpoint_path)):
166
- checkpoint_dir_files.extend(
167
- [os.path.relpath(os.path.join(dp, f), checkpoint_path) for f in fn])
168
-
169
- # Validate by comparing file lists
170
- return len(checkpoint_dir_files) >= len(repo_files) and not (
171
- len(set(repo_files) - set(checkpoint_dir_files)) > 0) and len(repo_files) > 0
172
-
173
- def _get_ignore_patterns(self):
174
- # check if model exists on HF
175
- try:
176
- from huggingface_hub import list_repo_files
177
- except ImportError:
178
- raise ImportError(self.HF_DOWNLOAD_TEXT)
179
-
180
- # Get the list of files on the repo that are not ignored
181
- repo_files = list_repo_files(self.repo_id, token=self.token)
182
- self.ignore_patterns = None
183
- if any(f.endswith(".safetensors") for f in repo_files):
184
- self.ignore_patterns = [
185
- "**/original/*", "**/*.pth", "**/*.bin", "*.pth", "*.bin", "**/.cache/*"
186
- ]
187
- return self.ignore_patterns
188
-
189
- @staticmethod
190
- def validate_config(checkpoint_path: str):
191
- # check if downloaded config.json exists
192
- return os.path.exists(checkpoint_path) and os.path.exists(
193
- os.path.join(checkpoint_path, 'config.json'))
194
-
195
- @staticmethod
196
- def validate_concept(checkpoint_path: str):
197
- # check if downloaded concept exists in hf model
198
- config_path = os.path.join(checkpoint_path, 'config.json')
199
- with open(config_path, 'r') as f:
200
- config = json.load(f)
201
-
202
- labels = config.get('id2label', None)
203
- if labels:
204
- return True
205
- return False
206
-
207
- @staticmethod
208
- def fetch_labels(checkpoint_path: str):
209
- # Fetch labels for classification, detection and segmentation models
210
- config_path = os.path.join(checkpoint_path, 'config.json')
211
- with open(config_path, 'r') as f:
212
- config = json.load(f)
213
-
214
- labels = config['id2label']
215
- return labels
216
-
217
- @staticmethod
218
- def get_huggingface_checkpoint_total_size(repo_name):
219
- """
220
- Fetches the JSON data for a Hugging Face model using the API with `?blobs=true`.
221
- Calculates the total size from the JSON output.
222
-
223
- Args:
224
- repo_name (str): The name of the model on Hugging Face Hub. e.g. "casperhansen/llama-3-8b-instruct-awq"
225
-
226
- Returns:
227
- int: The total size in bytes.
228
- """
229
- try:
230
- url = f"https://huggingface.co/api/models/{repo_name}?blobs=true"
231
- response = requests.get(url)
232
- response.raise_for_status() # Raise an exception for bad status codes
233
- json_data = response.json()
234
-
235
- if isinstance(json_data, str):
236
- data = json.loads(json_data)
237
- else:
238
- data = json_data
239
-
240
- total_size = 0
241
- for file in data['siblings']:
242
- total_size += file['size']
243
- return total_size
244
- except Exception as e:
245
- logger.error(f"Error fetching checkpoint size from huggingface.co: {e}")
246
- return 0
226
+
227
+ @staticmethod
228
+ def fetch_labels(checkpoint_path: str):
229
+ # Fetch labels for classification, detection and segmentation models
230
+ config_path = os.path.join(checkpoint_path, 'config.json')
231
+ with open(config_path, 'r') as f:
232
+ config = json.load(f)
233
+
234
+ labels = config['id2label']
235
+ return labels
236
+
237
+ @staticmethod
238
+ def get_huggingface_checkpoint_total_size(repo_name):
239
+ """
240
+ Fetches the JSON data for a Hugging Face model using the API with `?blobs=true`.
241
+ Calculates the total size from the JSON output.
242
+
243
+ Args:
244
+ repo_name (str): The name of the model on Hugging Face Hub. e.g. "casperhansen/llama-3-8b-instruct-awq"
245
+
246
+ Returns:
247
+ int: The total size in bytes.
248
+ """
249
+ try:
250
+ url = f"https://huggingface.co/api/models/{repo_name}?blobs=true"
251
+ response = requests.get(url)
252
+ response.raise_for_status() # Raise an exception for bad status codes
253
+ json_data = response.json()
254
+
255
+ if isinstance(json_data, str):
256
+ data = json.loads(json_data)
257
+ else:
258
+ data = json_data
259
+
260
+ total_size = 0
261
+ for file in data['siblings']:
262
+ total_size += file['size']
263
+ return total_size
264
+ except Exception as e:
265
+ logger.error(f"Error fetching checkpoint size from huggingface.co: {e}")
266
+ return 0