tracebloc 6.0.2__tar.gz → 6.0.4__tar.gz

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 (220) hide show
  1. {tracebloc-6.0.2 → tracebloc-6.0.4}/PKG-INFO +1 -1
  2. {tracebloc-6.0.2 → tracebloc-6.0.4}/pyproject.toml +2 -2
  3. tracebloc-6.0.4/tracebloc/api/multipart.py +143 -0
  4. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/client.py +4 -3
  5. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/families/hf/__init__.py +24 -19
  6. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/families/hf/_build.py +19 -12
  7. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/families/hf/_model_type.py +17 -13
  8. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/gate.py +13 -58
  9. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/licence/__init__.py +2 -1
  10. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/assemble.py +46 -29
  11. tracebloc-6.0.4/tracebloc/convert/package_folder.py +79 -0
  12. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/fetch.py +2 -2
  13. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/inference.py +21 -10
  14. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/answer.py +7 -2
  15. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/conversion.py +8 -4
  16. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/data_methods.py +26 -29
  17. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/library.py +15 -10
  18. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/link_checks.py +18 -10
  19. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/regeneration.py +41 -20
  20. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/stored.py +65 -16
  21. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/augmentation.py +6 -6
  22. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/callbacks.py +12 -9
  23. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/converted.py +13 -13
  24. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/features.py +24 -12
  25. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/image_channels.py +18 -4
  26. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/image_size.py +16 -9
  27. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/lora.py +2 -2
  28. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/lora_validation.py +15 -8
  29. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/loss.py +4 -4
  30. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/loss_policy.py +6 -3
  31. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/loss_source.py +15 -3
  32. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/memory_estimate.py +9 -7
  33. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/memory_sizing.py +14 -9
  34. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/plan.py +18 -11
  35. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/preprocessing.py +10 -10
  36. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/shape.py +2 -2
  37. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/subdataset.py +30 -26
  38. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/submitter.py +21 -19
  39. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/summary.py +8 -6
  40. tracebloc-6.0.4/tracebloc/upload/torch_image_classifier.py +73 -0
  41. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_key_point_detector.py +69 -89
  42. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_nlp_base.py +45 -63
  43. tracebloc-6.0.4/tracebloc/upload/torch_object_detector.py +196 -0
  44. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_semantic_segmentation.py +44 -77
  45. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_smoke_loop.py +10 -1
  46. tracebloc-6.0.4/tracebloc/upload/torch_time_series_classifier.py +145 -0
  47. tracebloc-6.0.4/tracebloc/upload/torch_time_series_forecaster.py +138 -0
  48. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc.egg-info/PKG-INFO +1 -1
  49. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc.egg-info/SOURCES.txt +2 -0
  50. tracebloc-6.0.2/tracebloc/upload/torch_image_classifier.py +0 -104
  51. tracebloc-6.0.2/tracebloc/upload/torch_object_detector.py +0 -257
  52. tracebloc-6.0.2/tracebloc/upload/torch_time_series_classifier.py +0 -198
  53. tracebloc-6.0.2/tracebloc/upload/torch_time_series_forecaster.py +0 -194
  54. {tracebloc-6.0.2 → tracebloc-6.0.4}/MANIFEST.in +0 -0
  55. {tracebloc-6.0.2 → tracebloc-6.0.4}/README.md +0 -0
  56. {tracebloc-6.0.2 → tracebloc-6.0.4}/license.txt +0 -0
  57. {tracebloc-6.0.2 → tracebloc-6.0.4}/setup.cfg +0 -0
  58. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/__init__.py +0 -0
  59. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/api/__init__.py +0 -0
  60. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/api/experiment_status.py +0 -0
  61. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/api/responses.py +0 -0
  62. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/auth/__init__.py +0 -0
  63. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/auth/env_login.py +0 -0
  64. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/checks.py +0 -0
  65. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/compat/__init__.py +0 -0
  66. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/compat/deprecation.py +0 -0
  67. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/compat/frameworks.py +0 -0
  68. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/config.py +0 -0
  69. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/console/__init__.py +0 -0
  70. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/console/logger.py +0 -0
  71. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/contracts/stage_urls.v1.json +0 -0
  72. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/contracts/stage_urls.v1.source.json +0 -0
  73. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/contracts/survival_payload.py +0 -0
  74. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/contracts/training_requirements.source.json +0 -0
  75. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/contracts/training_requirements.txt +0 -0
  76. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/__init__.py +0 -0
  77. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/acceptance.py +0 -0
  78. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/families/__init__.py +0 -0
  79. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/families/tabular.py +0 -0
  80. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/families/vision/__init__.py +0 -0
  81. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/families/vision/_matching.py +0 -0
  82. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/heads.py +0 -0
  83. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/interfaces.py +0 -0
  84. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/licence/spdx.py +0 -0
  85. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/outputs.py +0 -0
  86. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/__init__.py +0 -0
  87. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/arguments.py +0 -0
  88. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/checkpoint.py +0 -0
  89. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/gate_rules.py +0 -0
  90. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/generate.py +0 -0
  91. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/head.py +0 -0
  92. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/import_check.py +0 -0
  93. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/layer0.py +0 -0
  94. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/live.py +0 -0
  95. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/model_class.py +0 -0
  96. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/remote.py +0 -0
  97. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/repo.py +0 -0
  98. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/shake.py +0 -0
  99. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/owncode/source_tree.py +0 -0
  100. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/package.py +0 -0
  101. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/padding.py +0 -0
  102. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/report.py +0 -0
  103. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/tokenizers.py +0 -0
  104. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/convert/training_versions.py +0 -0
  105. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/__init__.py +0 -0
  106. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/base.py +0 -0
  107. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/detection.py +0 -0
  108. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/keypoint_detection.py +0 -0
  109. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/semantic_segmentation.py +0 -0
  110. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/tabular.py +0 -0
  111. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/text.py +0 -0
  112. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/time_series.py +0 -0
  113. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/datasets/time_to_event.py +0 -0
  114. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/downloads/lifelines_weights.py +0 -0
  115. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/downloads/seed_weights.py +0 -0
  116. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/exceptions.py +0 -0
  117. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/__init__.py +0 -0
  118. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/augmentation_methods.py +0 -0
  119. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/check_model.py +0 -0
  120. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/model_dataset.py +0 -0
  121. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/response.py +0 -0
  122. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/training_methods.py +0 -0
  123. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/linking/user_methods.py +0 -0
  124. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/notebook/__init__.py +0 -0
  125. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/notebook/templates/_partials.tpl +0 -0
  126. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/notebook/templates/embeddings.tpl +0 -0
  127. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/notebook/templates/nlp_finetune.tpl +0 -0
  128. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/notebook/templates/nlp_generative.tpl +0 -0
  129. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/notebook/templates/survival.tpl +0 -0
  130. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/notebook/templates/tabular_timeseries.tpl +0 -0
  131. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/notebook/templates/vision_from_scratch.tpl +0 -0
  132. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/__init__.py +0 -0
  133. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/classes.py +0 -0
  134. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/declaration.py +0 -0
  135. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/fitted_model.py +0 -0
  136. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/frame_recording.py +0 -0
  137. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/link_check.py +0 -0
  138. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/pairs.py +0 -0
  139. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/schema.py +0 -0
  140. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/seed_prefixes.py +0 -0
  141. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/sklearn_check.py +0 -0
  142. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/survival.py +0 -0
  143. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/torch_checks.py +0 -0
  144. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/raw_mode/width_note.py +0 -0
  145. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/__init__.py +0 -0
  146. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/training/link_total.py +0 -0
  147. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/__init__.py +0 -0
  148. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/lifelines_time_to_event.py +0 -0
  149. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/loss_config.py +0 -0
  150. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/model_params.py +0 -0
  151. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/model_upload.py +0 -0
  152. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/nlp_probes.py +0 -0
  153. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/scikit_survival_time_to_event.py +0 -0
  154. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/sequence_length.py +0 -0
  155. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/skl_tabular_base.py +0 -0
  156. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/skl_tabular_classifier.py +0 -0
  157. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/skl_tabular_regression.py +0 -0
  158. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/statistical_base.py +0 -0
  159. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/survival_base.py +0 -0
  160. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_causal_language_modeler.py +0 -0
  161. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_embeddings.py +0 -0
  162. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_handler.py +0 -0
  163. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_masked_language_modeler.py +0 -0
  164. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_multi_label_text_classifier.py +0 -0
  165. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_sentence_pair_classifier.py +0 -0
  166. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_seq2seq_modeler.py +0 -0
  167. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_tabular_classifier.py +0 -0
  168. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_tabular_regression.py +0 -0
  169. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_text_classifier.py +0 -0
  170. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_text_regressor.py +0 -0
  171. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_time_to_event.py +0 -0
  172. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/torch_token_classifier.py +0 -0
  173. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/user_methods.py +0 -0
  174. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/weight_loaders.py +0 -0
  175. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/weights_averaging.py +0 -0
  176. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/weights_check.py +0 -0
  177. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/upload/weights_parts.py +0 -0
  178. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/user.py +0 -0
  179. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/__init__.py +0 -0
  180. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/class_order.py +0 -0
  181. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/constants.py +0 -0
  182. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/custom_loss_probe.py +0 -0
  183. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/data_probes.py +0 -0
  184. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/declared_classes.py +0 -0
  185. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/declared_cls.py +0 -0
  186. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/detection_utils.py +0 -0
  187. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/device.py +0 -0
  188. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/entry_point.py +0 -0
  189. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/errors.py +0 -0
  190. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/feature_dict.py +0 -0
  191. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/loss_shape.py +0 -0
  192. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/model_loading.py +0 -0
  193. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/model_params.py +0 -0
  194. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/nlp_model_probes.py +0 -0
  195. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/registry.py +0 -0
  196. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/resources.py +0 -0
  197. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/safetensors_io.py +0 -0
  198. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/staging.py +0 -0
  199. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/synthetic_self_supervised.py +0 -0
  200. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/synthetic_text.py +0 -0
  201. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/tabular_classification_utils.py +0 -0
  202. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/tabular_custom_loss_utils.py +0 -0
  203. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/tabular_regression_utils.py +0 -0
  204. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/text_classification_utils.py +0 -0
  205. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/time_series_utils.py +0 -0
  206. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/time_to_event_utils.py +0 -0
  207. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/tokenizer_checks.py +0 -0
  208. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/utils/warnings_once.py +0 -0
  209. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/__init__.py +0 -0
  210. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/checker.py +0 -0
  211. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/estimator_checks.py +0 -0
  212. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/header_rules.py +0 -0
  213. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/lifelines_checks.py +0 -0
  214. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/pytorch_checks.py +0 -0
  215. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/rewriter.py +0 -0
  216. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/scikit_survival_checks.py +0 -0
  217. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc/validation/sklearn_checks.py +0 -0
  218. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc.egg-info/dependency_links.txt +0 -0
  219. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc.egg-info/requires.txt +0 -0
  220. {tracebloc-6.0.2 → tracebloc-6.0.4}/tracebloc.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tracebloc
3
- Version: 6.0.2
3
+ Version: 6.0.4
4
4
  Summary: Build AI with anyone. On data that can't move. SDK for the tracebloc collaborative AI workspace.
5
5
  Author-email: tracebloc <lukas@tracebloc.io>
6
6
  License-Expression: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "tracebloc"
7
- version = "6.0.2"
7
+ version = "6.0.4"
8
8
  description = "Build AI with anyone. On data that can't move. SDK for the tracebloc collaborative AI workspace."
9
9
  license = "MIT"
10
10
  license-files = ["license.txt"]
@@ -276,7 +276,7 @@ ignore = ["N812"]
276
276
  include = ["tracebloc"]
277
277
  typeCheckingMode = "basic"
278
278
  pythonVersion = "3.11"
279
- strict = ["tracebloc/api", "tracebloc/auth", "tracebloc/checks.py", "tracebloc/client.py", "tracebloc/compat", "tracebloc/config.py", "tracebloc/datasets", "tracebloc/downloads", "tracebloc/fetch.py", "tracebloc/raw_mode"]
279
+ strict = ["tracebloc/api", "tracebloc/auth", "tracebloc/checks.py", "tracebloc/client.py", "tracebloc/compat", "tracebloc/config.py", "tracebloc/convert/families/hf", "tracebloc/datasets", "tracebloc/downloads", "tracebloc/fetch.py", "tracebloc/linking/answer.py", "tracebloc/linking/conversion.py", "tracebloc/linking/library.py", "tracebloc/linking/regeneration.py", "tracebloc/linking/stored.py", "tracebloc/raw_mode", "tracebloc/training/__init__.py", "tracebloc/training/augmentation.py", "tracebloc/training/callbacks.py", "tracebloc/training/converted.py", "tracebloc/training/image_channels.py", "tracebloc/training/image_size.py", "tracebloc/training/link_total.py", "tracebloc/training/lora.py", "tracebloc/training/loss_policy.py", "tracebloc/training/loss_source.py", "tracebloc/training/memory_estimate.py", "tracebloc/training/memory_sizing.py", "tracebloc/training/plan.py", "tracebloc/training/preprocessing.py", "tracebloc/training/shape.py", "tracebloc/training/subdataset.py"]
280
280
 
281
281
  # --- import-linter (layers, tracebloc/backend#9172) -----------------------
282
282
  # `make lint` runs `lint-imports`. A layer may import any layer below it, never
@@ -0,0 +1,143 @@
1
+ """Multipart bodies sent from the open files instead of built in memory.
2
+
3
+ requests encodes ``files=`` by reading every file into one in-memory body, so a
4
+ 1 GiB weights upload holds about 2 GiB. :class:`StreamingMultipartSession`
5
+ prepares the same request with a body that streams each file from its open
6
+ handle, with a ``Content-Length``: the bytes on the wire are the ones requests
7
+ would send. Callers keep passing ``files=`` and ``data=`` to
8
+ ``Session.request``; a request it cannot stream is prepared as requests does.
9
+ """
10
+
11
+ from __future__ import annotations
12
+
13
+ import io
14
+ import os
15
+ import uuid
16
+ from collections.abc import Iterator, Mapping
17
+ from typing import Any, BinaryIO, cast
18
+
19
+ import requests
20
+ from requests.models import PreparedRequest, Request, RequestEncodingMixin
21
+ from requests.utils import to_key_val_list
22
+
23
+ #: Bytes read from a file per chunk handed to the connection.
24
+ CHUNK_BYTES = 1024 * 1024
25
+
26
+
27
+ class _Placeholder:
28
+ """Stands in for a file while requests frames the body: same ``name`` (so
29
+ the same filename), and a unique token as its content."""
30
+
31
+ def __init__(self, name: Any, token: bytes) -> None:
32
+ self.name = name
33
+ self._content = token
34
+
35
+ def read(self, *_args: Any) -> bytes:
36
+ return self._content
37
+
38
+
39
+ class _FilePart:
40
+ """A file's content from its position when prepared to its end."""
41
+
42
+ def __init__(self, handle: BinaryIO) -> None:
43
+ self.handle = handle
44
+ self.start = handle.tell()
45
+ self.size = os.fstat(handle.fileno()).st_size - self.start
46
+
47
+ def chunks(self) -> Iterator[bytes]:
48
+ self.handle.seek(self.start)
49
+ left = self.size
50
+ while left:
51
+ chunk = self.handle.read(min(CHUNK_BYTES, left))
52
+ if not chunk:
53
+ raise OSError(
54
+ f"{getattr(self.handle, 'name', 'a file')} shrank while it was sent"
55
+ )
56
+ left -= len(chunk)
57
+ yield chunk
58
+
59
+
60
+ class MultipartStream:
61
+ """A multipart body as framing bytes and file parts; iterable any number of
62
+ times (a retry re-sends it whole), with its length known up front."""
63
+
64
+ def __init__(self, segments: list[bytes | _FilePart], content_type: str) -> None:
65
+ self._segments = segments
66
+ self.content_type = content_type
67
+
68
+ def __len__(self) -> int:
69
+ return sum(
70
+ len(segment) if isinstance(segment, bytes) else segment.size
71
+ for segment in self._segments
72
+ )
73
+
74
+ def __iter__(self) -> Iterator[bytes]:
75
+ for segment in self._segments:
76
+ if isinstance(segment, bytes):
77
+ if segment:
78
+ yield segment
79
+ else:
80
+ yield from segment.chunks()
81
+
82
+
83
+ def _plain_file(value: Any) -> BinaryIO | None:
84
+ """``value`` when it is a seekable binary file on disk, else ``None``."""
85
+ if not isinstance(value, io.BufferedIOBase) or not value.seekable():
86
+ return None
87
+ try:
88
+ value.fileno()
89
+ except (OSError, io.UnsupportedOperation):
90
+ return None
91
+ return value # type: ignore[return-value] # a BufferedIOBase with a fileno
92
+
93
+
94
+ def multipart_stream(files: Any, data: Any) -> MultipartStream | None:
95
+ """The streamed body for ``files`` and ``data``, or ``None`` when a file is
96
+ not a plain one (bytes, a tuple, an in-memory buffer) or ``data`` is not
97
+ form fields: requests then encodes the request itself."""
98
+ if not files or isinstance(data, (str, bytes)):
99
+ return None
100
+ if data is not None and not isinstance(data, (Mapping, list, tuple)):
101
+ return None
102
+ pairs = cast("list[tuple[Any, Any]]", to_key_val_list(files))
103
+ parts: dict[bytes, _FilePart] = {}
104
+ placeholders: list[tuple[Any, _Placeholder]] = []
105
+ for key, value in pairs:
106
+ handle = _plain_file(value)
107
+ if handle is None:
108
+ return None
109
+ token = b"\x00tracebloc-part-" + uuid.uuid4().hex.encode() + b"\x00"
110
+ parts[token] = _FilePart(handle)
111
+ placeholders.append((key, _Placeholder(getattr(value, "name", None), token)))
112
+ body, content_type = RequestEncodingMixin._encode_files( # pyright: ignore[reportPrivateUsage]
113
+ cast(Any, placeholders), cast(Any, data)
114
+ )
115
+ segments: list[bytes | _FilePart] = []
116
+ rest = body
117
+ for token, part in parts.items():
118
+ if rest.count(token) != 1:
119
+ return None
120
+ before, rest = rest.split(token)
121
+ segments += [before, part]
122
+ segments.append(rest)
123
+ return MultipartStream(segments, content_type)
124
+
125
+
126
+ class StreamingMultipartSession(requests.Session):
127
+ """A :class:`requests.Session` that sends a multipart request's files from
128
+ their open handles."""
129
+
130
+ def prepare_request(self, request: Request) -> PreparedRequest:
131
+ stream = multipart_stream(request.files, request.data)
132
+ if stream is None:
133
+ return super().prepare_request(request)
134
+ files, data = request.files, request.data
135
+ request.files, request.data = [], []
136
+ try:
137
+ prepared = super().prepare_request(request)
138
+ finally:
139
+ request.files, request.data = files, data
140
+ prepared.body = stream # type: ignore[assignment]
141
+ prepared.headers["Content-Type"] = stream.content_type
142
+ prepared.headers["Content-Length"] = str(len(stream))
143
+ return prepared
@@ -223,8 +223,8 @@ class TraceblocClient:
223
223
  with the returned token. Must be accompanied by
224
224
  ``token_scheme``.
225
225
  session: Optional pre-built :class:`requests.Session`. Exposed
226
- for tests and advanced users. If omitted, the client builds
227
- its own session with the default retry adapter mounted.
226
+ for tests and advanced users. If omitted, the client builds a
227
+ file-streaming one with the default retry adapter mounted.
228
228
  token_scheme: ``Authorization`` scheme for ``token`` (``Token``
229
229
  or ``Bearer``). Required together with ``token``.
230
230
  """
@@ -242,7 +242,8 @@ class TraceblocClient:
242
242
  self.set_token(token, token_scheme)
243
243
 
244
244
  if session is None:
245
- session = requests.Session()
245
+ from tracebloc.api.multipart import StreamingMultipartSession
246
+ session = StreamingMultipartSession()
246
247
  adapter = HTTPAdapter(max_retries=_DEFAULT_RETRY)
247
248
  session.mount("http://", adapter)
248
249
  session.mount("https://", adapter)
@@ -21,12 +21,12 @@ import importlib
21
21
  import json
22
22
  import re
23
23
  from pathlib import Path
24
- from typing import Any, Mapping
24
+ from typing import Any, Mapping, cast
25
25
 
26
26
  from tracebloc.convert.families.hf._build import head_prefixes, load, model_source
27
27
  from tracebloc.convert.families.hf._build import with_pad_token_id, write_weights
28
- from tracebloc.convert.families.hf._model_type import _AUTO, CONFIG_FILE, _mapping
29
- from tracebloc.convert.families.hf._model_type import _names, model_type_of
28
+ from tracebloc.convert.families.hf._model_type import AUTO_PACKAGE, CONFIG_FILE, auto_mapping
29
+ from tracebloc.convert.families.hf._model_type import mapping_names, model_type_of
30
30
  from tracebloc.convert.families.vision import read_normalisation
31
31
  from tracebloc.convert.heads import head_config
32
32
  from tracebloc.convert.interfaces import ComparedOutput, ConversionInput, Proof
@@ -36,7 +36,7 @@ from tracebloc.convert.interfaces import Provenance, SourcedValue, ValueSource
36
36
  from tracebloc.convert.interfaces import UseCaseTask
37
37
  from tracebloc.utils.constants import Framework, TaskCategory
38
38
  from tracebloc.validation.header_rules import NO_OUTPUT_CLASSES, SELF_SUPERVISED_NLP
39
- from tracebloc.validation.header_rules import SHAPE_VALUES
39
+ from tracebloc.validation.header_rules import SHAPE_VALUES as _SHAPE_VALUES # pyright: ignore[reportUnknownVariableType]
40
40
 
41
41
  #: A sentence-transformers folder's module list.
42
42
  ST_MODULES = "modules.json"
@@ -125,6 +125,8 @@ DROPPED_CONFIG_KEYS = frozenset(
125
125
  }
126
126
  )
127
127
 
128
+ # TODO(tracebloc/backend#9179): drop this cast once validation is held to strict mode.
129
+ SHAPE_VALUES = cast("dict[str, tuple[str, ...]]", _SHAPE_VALUES)
128
130
  IMAGE_TASKS = frozenset(SHAPE_VALUES["image_size"])
129
131
  #: The tasks whose input is text: those reading a sequence length, not features.
130
132
  TEXT_TASKS = frozenset(SHAPE_VALUES["sequence_length"]) - frozenset(
@@ -150,12 +152,12 @@ def _modality(model_type: str) -> str | None:
150
152
  mappings; ``None`` for a model with both or neither."""
151
153
  text = (
152
154
  model_type
153
- in importlib.import_module(f"{_AUTO}.tokenization_auto").TOKENIZER_MAPPING_NAMES
155
+ in importlib.import_module(f"{AUTO_PACKAGE}.tokenization_auto").TOKENIZER_MAPPING_NAMES
154
156
  )
155
157
  images = (
156
158
  model_type
157
159
  in importlib.import_module(
158
- f"{_AUTO}.image_processing_auto"
160
+ f"{AUTO_PACKAGE}.image_processing_auto"
159
161
  ).IMAGE_PROCESSOR_MAPPING_NAMES
160
162
  )
161
163
  return "text" if text and not images else "images" if images and not text else None
@@ -164,13 +166,14 @@ def _modality(model_type: str) -> str | None:
164
166
  def _sentence_transformer(folder: Path) -> tuple[Path, tuple[str, ...] | None]:
165
167
  """The folder holding the transformer, and a sentence-transformers folder's
166
168
  pooling modes (``None`` when it is not one)."""
167
- modules = _read_json(folder / ST_MODULES)
168
- if not isinstance(modules, list):
169
+ read = _read_json(folder / ST_MODULES)
170
+ if not isinstance(read, list):
169
171
  return folder, None
172
+ entries = cast("list[object]", read) # a JSON array: any JSON values
173
+ modules = [cast("dict[str, object]", e) for e in entries if isinstance(e, dict)]
170
174
  paths = {
171
175
  str(module.get("type", "")).rsplit(".", 1)[-1]: str(module.get("path", ""))
172
176
  for module in modules
173
- if isinstance(module, dict)
174
177
  }
175
178
  inside = {
176
179
  kind: folder / path
@@ -179,7 +182,7 @@ def _sentence_transformer(folder: Path) -> tuple[Path, tuple[str, ...] | None]:
179
182
  }
180
183
  if "Transformer" not in inside:
181
184
  return folder, None
182
- pooling = (
185
+ pooling: dict[str, object] | None = (
183
186
  _read_json(inside["Pooling"] / CONFIG_FILE) if "Pooling" in inside else None
184
187
  )
185
188
  modes = tuple(
@@ -225,7 +228,8 @@ def _class_names(config: Mapping[str, Any]) -> tuple[str, ...]:
225
228
  if not isinstance(id2label, dict):
226
229
  return ()
227
230
  try:
228
- ordered = sorted((int(index), str(name)) for index, name in id2label.items())
231
+ labels = cast("dict[str, object]", id2label) # a parsed config.json: str keys
232
+ ordered = sorted((int(index), str(name)) for index, name in labels.items())
229
233
  except (TypeError, ValueError):
230
234
  return ()
231
235
  return tuple(name for _, name in ordered)
@@ -236,7 +240,7 @@ def _declared_task(model_type: str, architecture: str | None) -> TaskCategory |
236
240
  for category, (_, mapping) in TASK_CLASSES.items():
237
241
  if category is TaskCategory.EMBEDDINGS:
238
242
  continue
239
- if architecture in _names(_mapping(mapping).get(model_type)):
243
+ if architecture in mapping_names(auto_mapping(mapping).get(model_type)):
240
244
  return category
241
245
  return None
242
246
 
@@ -244,8 +248,9 @@ def _declared_task(model_type: str, architecture: str | None) -> TaskCategory |
244
248
  def _image_values(folder: Path, config: Mapping[str, Any]) -> dict[str, SourcedValue]:
245
249
  """Normalisation from ``preprocessor_config.json``; the side from ``config.json``."""
246
250
  values = read_normalisation(folder)
247
- side = config.get("image_size")
248
- side = side[-1] if isinstance(side, (list, tuple)) and side else side
251
+ side: object = config.get("image_size")
252
+ if isinstance(side, (list, tuple)) and side:
253
+ side = cast("list[object] | tuple[object, ...]", side)[-1]
249
254
  if isinstance(side, int) and not isinstance(side, bool) and side > 0:
250
255
  values["image_size"] = _sourced(side, f"{CONFIG_FILE} image_size")
251
256
  return values
@@ -274,11 +279,11 @@ def task_class(state: Mapping[str, Any], category: TaskCategory, label: str) ->
274
279
  architecture = state["architecture"]
275
280
  if (
276
281
  category is TaskCategory.EMBEDDINGS
277
- and architecture in _names(_mapping(encoders).get(model_type))
278
- and architecture not in _names(_mapping(mapping).get(model_type))
282
+ and architecture in mapping_names(auto_mapping(encoders).get(model_type))
283
+ and architecture not in mapping_names(auto_mapping(mapping).get(model_type))
279
284
  ):
280
285
  return encoder
281
- if not mapping or not _names(_mapping(mapping).get(model_type)):
286
+ if not mapping or not mapping_names(auto_mapping(mapping).get(model_type)):
282
287
  import transformers
283
288
 
284
289
  raise ConversionRefusedError(
@@ -362,7 +367,7 @@ class HuggingFaceFamily:
362
367
  if config.get("model_type") != model_type:
363
368
  read_from = f"{CONFIG_FILE} architectures"
364
369
  config = {**config, "model_type": model_type}
365
- known = importlib.import_module(f"{_AUTO}.configuration_auto")
370
+ known = importlib.import_module(f"{AUTO_PACKAGE}.configuration_auto")
366
371
  if model_type not in known.CONFIG_MAPPING_NAMES:
367
372
  raise ConversionRefusedError(
368
373
  RefusalCause.NO_TASK_CLASS,
@@ -371,7 +376,7 @@ class HuggingFaceFamily:
371
376
  "transformers version the model was saved with",
372
377
  )
373
378
  weights = _has_weights(folder)
374
- architectures = _names(config.get("architectures"))
379
+ architectures = mapping_names(config.get("architectures"))
375
380
  architecture = architectures[0] if architectures else None
376
381
  declared = _declared_task(model_type, architecture)
377
382
  if pooling is not None:
@@ -12,17 +12,18 @@ import contextlib
12
12
  import re
13
13
  from collections import Counter
14
14
  from pathlib import Path
15
- from typing import Any, Iterable, Iterator, Mapping
15
+ from typing import Any, Generator, Iterable, Mapping, cast
16
16
 
17
17
  from tracebloc.convert.interfaces import ConversionRefusedError, RefusalCause
18
18
  from tracebloc.convert.interfaces import SourcedValue
19
- from tracebloc.convert.heads import collapse as head_prefixes
19
+ # Re-exported: hf's __init__ and its tests read it here.
20
+ from tracebloc.convert.heads import collapse as head_prefixes # pyright: ignore[reportUnusedImport]
20
21
  from tracebloc.convert.heads import head_key
21
22
  from tracebloc.utils.constants import TaskCategory
22
23
 
23
24
 
24
25
  @contextlib.contextmanager
25
- def _quiet() -> Iterator[None]:
26
+ def _quiet() -> Generator[None, None, None]:
26
27
  """transformers' load report and progress bars off; the report records the load."""
27
28
  from transformers.utils import logging
28
29
 
@@ -78,8 +79,9 @@ def checkpoint_keys(folder: Path) -> tuple[str, ...]:
78
79
 
79
80
  try:
80
81
  if (folder / "model.safetensors").is_file():
81
- with safe_open(str(folder / "model.safetensors"), framework="pt") as file:
82
- return tuple(file.keys())
82
+ # safetensors types safe_open's handle as unknown.
83
+ with safe_open(str(folder / "model.safetensors"), framework="pt") as file: # pyright: ignore[reportUnknownVariableType]
84
+ return tuple(file.keys()) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType]
83
85
  for index in ("model.safetensors.index.json", "pytorch_model.bin.index.json"):
84
86
  if (folder / index).is_file():
85
87
  weight_map = json.loads((folder / index).read_text())["weight_map"]
@@ -147,14 +149,16 @@ def load(
147
149
 
148
150
  task_model = getattr(transformers, auto_class)
149
151
  labels = {} if classes is None else {"num_labels": classes.value}
150
- config = transformers.AutoConfig.for_model(**state["config"], **labels)
152
+ # transformers leaves for_model's **kwargs untyped.
153
+ config = transformers.AutoConfig.for_model(**state["config"], **labels) # pyright: ignore[reportUnknownMemberType]
151
154
  renames = None
152
155
  if state["weights"]:
153
156
  keys = checkpoint_keys(Path(state["folder"]))
154
157
  with _quiet():
155
158
  renames = backbone_renames(task_model, config, keys)
156
- with _quiet(), torch.random.fork_rng(devices=[]):
157
- torch.manual_seed(0)
159
+ # torch leaves fork_rng's devices and manual_seed's seed untyped.
160
+ with _quiet(), torch.random.fork_rng(devices=[]): # pyright: ignore[reportUnknownMemberType]
161
+ torch.manual_seed(0) # pyright: ignore[reportUnknownMemberType]
158
162
  if not state["weights"]:
159
163
  return task_model.from_config(config).eval(), (), ()
160
164
  model, info = task_model.from_pretrained(
@@ -187,10 +191,11 @@ def write_weights(model: Any, wrapper: str | None, target: Path) -> tuple[str, .
187
191
  Every key goes under ``wrapper.`` when the generated file wraps the task
188
192
  model. A tied tensor is written once per key, as a strict load needs.
189
193
  """
190
- from safetensors.torch import save_file
194
+ # safetensors leaves save_file's PathLike untyped.
195
+ from safetensors.torch import save_file # pyright: ignore[reportUnknownVariableType]
191
196
 
192
197
  seen: set[int] = set()
193
- out = {}
198
+ out: dict[str, Any] = {}
194
199
  for key, tensor in model.state_dict().items():
195
200
  tensor = tensor.detach()
196
201
  storage = tensor.untyped_storage().data_ptr()
@@ -215,10 +220,12 @@ def with_pad_token_id(
215
220
  if config.get("pad_token_id") is not None or tokenizer is None:
216
221
  return config
217
222
  try:
218
- reads = "pad_token_id" in inspect.getsource(type(model).forward)
223
+ # Any transformers task class: its forward, and tokenizers' padding dict, are untyped.
224
+ reads = "pad_token_id" in inspect.getsource(type(model).forward) # pyright: ignore[reportUnknownMemberType, reportUnknownArgumentType]
219
225
  from tokenizers import Tokenizer
220
226
 
221
- padding = Tokenizer.from_file(str(tokenizer)).padding
227
+ tokenizer_file = Tokenizer.from_file(str(tokenizer))
228
+ padding = cast("dict[str, Any] | None", tokenizer_file.padding) # pyright: ignore[reportUnknownMemberType]
222
229
  except (OSError, TypeError, ValueError, ImportError):
223
230
  return config
224
231
  if not reads or not padding or padding.get("pad_id") is None:
@@ -8,23 +8,25 @@ from __future__ import annotations
8
8
 
9
9
  import importlib
10
10
  from pathlib import Path
11
- from typing import Any, Mapping
11
+ from typing import Any, Iterable, Mapping, cast
12
12
 
13
13
  from tracebloc.convert.interfaces import ConversionRefusedError, RefusalCause
14
14
 
15
15
  CONFIG_FILE = "config.json"
16
- _AUTO = "transformers.models.auto"
16
+ AUTO_PACKAGE = "transformers.models.auto"
17
17
 
18
18
 
19
- def _names(value: Any) -> tuple[str, ...]:
19
+ def mapping_names(value: Any) -> tuple[str, ...]:
20
20
  """A mapping's class names for one ``model_type``: one name or several."""
21
21
  if isinstance(value, str):
22
22
  return (value,)
23
- return tuple(value) if isinstance(value, (tuple, list)) else ()
23
+ if isinstance(value, (tuple, list)):
24
+ return tuple(cast("Iterable[str]", value)) # a mapping's names are str
25
+ return ()
24
26
 
25
27
 
26
- def _mapping(name: str) -> Mapping[str, Any]:
27
- return getattr(importlib.import_module(f"{_AUTO}.modeling_auto"), name, {})
28
+ def auto_mapping(name: str) -> Mapping[str, Any]:
29
+ return getattr(importlib.import_module(f"{AUTO_PACKAGE}.modeling_auto"), name, {})
28
30
 
29
31
 
30
32
  def _architecture_model_type(folder: Path, architecture: str) -> str:
@@ -32,13 +34,13 @@ def _architecture_model_type(folder: Path, architecture: str) -> str:
32
34
  when they give none, or several the class's own config does not settle."""
33
35
  import transformers
34
36
 
35
- modeling = importlib.import_module(f"{_AUTO}.modeling_auto")
37
+ modeling = importlib.import_module(f"{AUTO_PACKAGE}.modeling_auto")
36
38
  found = {
37
39
  model_type
38
40
  for name in vars(modeling)
39
41
  if name.endswith("_MAPPING_NAMES")
40
- for model_type, classes in _mapping(name).items()
41
- if architecture in _names(classes)
42
+ for model_type, classes in auto_mapping(name).items()
43
+ if architecture in mapping_names(classes)
42
44
  }
43
45
  if len(found) > 1:
44
46
  try:
@@ -62,10 +64,12 @@ def model_type_of(folder: Path, config: Any) -> str | None:
62
64
  folder is not a transformers model or ships its own code."""
63
65
  if not isinstance(config, dict):
64
66
  return None
65
- if isinstance(config.get("model_type"), str):
66
- return config["model_type"]
67
- architectures = _names(config.get("architectures"))
68
- if "auto_map" in config or not architectures:
67
+ read = cast("dict[str, Any]", config) # a parsed config.json: str keys
68
+ model_type = read.get("model_type")
69
+ if isinstance(model_type, str):
70
+ return model_type
71
+ architectures = mapping_names(read.get("architectures"))
72
+ if "auto_map" in read or not architectures:
69
73
  return None
70
74
  from tracebloc.compat.frameworks import require_module
71
75
 
@@ -17,7 +17,6 @@ uploaded only once the acceptance check has passed (:func:`upload_file_for`).
17
17
 
18
18
  from __future__ import annotations
19
19
 
20
- import json
21
20
  import os
22
21
  import shutil
23
22
  import tempfile
@@ -26,6 +25,7 @@ from dataclasses import dataclass, replace
26
25
  from pathlib import Path
27
26
  from typing import Any, Sequence
28
27
 
28
+ from tracebloc.console.logger import say
29
29
  from tracebloc.convert.interfaces import (
30
30
  CheckFinding,
31
31
  ConversionInput,
@@ -58,12 +58,17 @@ from tracebloc.convert.package import (
58
58
  WrittenPackage,
59
59
  as_path,
60
60
  derive_seed_excluded_prefixes,
61
- file_stem,
62
61
  python_sources,
63
62
  ship_within_weights_cap,
64
63
  write_package,
65
64
  )
66
- from tracebloc.convert.report import REPORT_FILE, report_document, write_report
65
+ from tracebloc.convert.report import report_document, write_report
66
+ from tracebloc.convert.package_folder import (
67
+ output_directory,
68
+ earlier_conversion,
69
+ publish_staged,
70
+ remove_superseded,
71
+ )
67
72
  from tracebloc.exceptions import ModelValidationError
68
73
  from tracebloc.utils.constants import (
69
74
  PYTORCH_FRAMEWORK,
@@ -280,40 +285,6 @@ def _header_with_defaults(
280
285
  return header
281
286
 
282
287
 
283
- def _output_directory(
284
- source: ConversionInput, out_dir: Path | None
285
- ) -> tuple[Path, str]:
286
- """Where the package is written, and the model file's name."""
287
- if source.path is not None:
288
- stem = source.path.stem if source.path.is_file() else source.path.name
289
- default = source.path.parent / f"{file_stem(stem)}_tracebloc"
290
- else:
291
- stem = type(source.live_object).__name__
292
- default = Path.cwd() / f"{file_stem(stem)}_tracebloc"
293
- return (out_dir if out_dir is not None else default), stem
294
-
295
-
296
- def _earlier_conversion(directory: Path) -> list[Path]:
297
- """The files an earlier conversion wrote into ``directory``, its report last.
298
-
299
- A directory holding files but no readable report is not a conversion's,
300
- and is refused rather than written into.
301
- """
302
- if not directory.is_dir() or not any(directory.iterdir()):
303
- return []
304
- report = directory / REPORT_FILE
305
- try:
306
- files = json.loads(report.read_text(encoding="utf-8"))["files"]
307
- names = [files[key] for key in ("model_file", "weights", "tokenizer")]
308
- except (OSError, ValueError, KeyError, TypeError):
309
- raise ModelValidationError(
310
- f"{directory} already holds files and no readable {REPORT_FILE}, so "
311
- f"it is not an earlier conversion's; move it or pass out_dir."
312
- ) from None
313
- listed = [n for n in names if isinstance(n, str) and Path(n).name == n]
314
- return [directory / name for name in listed] + [report]
315
-
316
-
317
288
  def _tracebloc_version() -> str:
318
289
  from importlib.metadata import PackageNotFoundError, version
319
290
 
@@ -337,8 +308,8 @@ def _build(
337
308
  reader = LICENCE_HOOK.load()
338
309
  licence = reader(source, recognition) if reader is not None else None
339
310
  licence = confirm_licence(licence, licence_confirmed, confirmed_by)
340
- directory, stem = _output_directory(source, out_dir)
341
- earlier = _earlier_conversion(directory)
311
+ directory, stem = output_directory(source, out_dir)
312
+ earlier = earlier_conversion(directory)
342
313
  with tempfile.TemporaryDirectory(prefix="tracebloc_build_") as raw:
343
314
  built = family.build(recognition, task, Path(raw))
344
315
  package = replace(
@@ -371,20 +342,7 @@ def _build(
371
342
  tracebloc_version=_tracebloc_version(),
372
343
  )
373
344
  staged_report = write_report(stage, document)
374
- written = replace(
375
- staged,
376
- directory=directory,
377
- model_file=directory / staged.model_file.name,
378
- weights=directory / staged.weights.name if staged.weights else None,
379
- tokenizer=(
380
- directory / staged.tokenizer.name if staged.tokenizer else None
381
- ),
382
- )
383
- report_path = directory / staged_report.name
384
- for path in sorted(stage.iterdir()):
385
- if path != staged_report:
386
- os.replace(path, directory / path.name)
387
- os.replace(staged_report, report_path)
345
+ written, report_path = publish_staged(directory, stage, staged, staged_report)
388
346
  except BaseException:
389
347
  shutil.rmtree(stage, ignore_errors=True)
390
348
  if created and not any(directory.iterdir()):
@@ -392,10 +350,7 @@ def _build(
392
350
  raise
393
351
  finally:
394
352
  shutil.rmtree(stage, ignore_errors=True)
395
- current = {written.model_file, written.weights, written.tokenizer, report_path}
396
- for path in earlier:
397
- if path not in current:
398
- path.unlink(missing_ok=True)
353
+ remove_superseded(earlier, written, report_path)
399
354
  return ConversionOutcome(
400
355
  layer=layer,
401
356
  source=source,
@@ -495,5 +450,5 @@ def upload_file_for(model_path: str, conversion: ConversionOutcome | None) -> st
495
450
  )
496
451
  if conversion.converted:
497
452
  require_confirmation(conversion.licence, conversion.report)
498
- print(licence_line(conversion.licence))
453
+ say(licence_line(conversion.licence))
499
454
  return model_path
@@ -20,6 +20,7 @@ from datetime import datetime, timezone
20
20
  from pathlib import Path
21
21
  from typing import Any, Callable, Mapping
22
22
 
23
+ from tracebloc.console.logger import say
23
24
  from tracebloc.convert.interfaces import (
24
25
  ConversionInput,
25
26
  ConversionRefusedError,
@@ -477,7 +478,7 @@ def ask_to_confirm(licence: Licence, ask: Callable[[str], str] = input) -> bool:
477
478
  return False
478
479
  if get_ipython() is None:
479
480
  return False
480
- print(licence_line(licence))
481
+ say(licence_line(licence))
481
482
  answer = ask(f"{statement(licence)} Confirm? [y/N] ")
482
483
  return answer.strip().lower() in ("y", "yes")
483
484