tracebloc 1.2.85__tar.gz → 1.2.87__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 (181) hide show
  1. {tracebloc-1.2.85 → tracebloc-1.2.87}/PKG-INFO +1 -1
  2. {tracebloc-1.2.85 → tracebloc-1.2.87}/pyproject.toml +1 -1
  3. tracebloc-1.2.87/tracebloc/raw_mode/__init__.py +91 -0
  4. tracebloc-1.2.87/tracebloc/raw_mode/classes.py +100 -0
  5. tracebloc-1.2.87/tracebloc/raw_mode/declaration.py +89 -0
  6. tracebloc-1.2.87/tracebloc/raw_mode/fitted_model.py +86 -0
  7. tracebloc-1.2.85/tracebloc/raw_mode_frame.py → tracebloc-1.2.87/tracebloc/raw_mode/frame_recording.py +4 -3
  8. tracebloc-1.2.87/tracebloc/raw_mode/link_check.py +58 -0
  9. tracebloc-1.2.87/tracebloc/raw_mode/pairs.py +54 -0
  10. tracebloc-1.2.87/tracebloc/raw_mode/schema.py +58 -0
  11. tracebloc-1.2.85/tracebloc/raw_mode_seed.py → tracebloc-1.2.87/tracebloc/raw_mode/seed_prefixes.py +1 -1
  12. tracebloc-1.2.87/tracebloc/raw_mode/sklearn_check.py +100 -0
  13. tracebloc-1.2.85/tracebloc/raw_mode_survival.py → tracebloc-1.2.87/tracebloc/raw_mode/survival.py +5 -10
  14. tracebloc-1.2.85/tracebloc/raw_mode_torch.py → tracebloc-1.2.87/tracebloc/raw_mode/torch_checks.py +11 -15
  15. tracebloc-1.2.87/tracebloc/raw_mode_frame.py +12 -0
  16. tracebloc-1.2.87/tracebloc/raw_mode_seed.py +9 -0
  17. tracebloc-1.2.87/tracebloc/raw_mode_survival.py +18 -0
  18. tracebloc-1.2.87/tracebloc/raw_mode_torch.py +27 -0
  19. tracebloc-1.2.87/tracebloc/upload/torch_handler.py +74 -0
  20. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_image_classifier.py +2 -52
  21. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_semantic_segmentation.py +2 -52
  22. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_tabular_classifier.py +3 -53
  23. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_tabular_regression.py +3 -53
  24. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_text_classifier.py +2 -2
  25. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_time_to_event.py +3 -53
  26. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_token_classifier.py +2 -2
  27. tracebloc-1.2.87/tracebloc/utils/declared_classes.py +6 -0
  28. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/detection_utils.py +2 -2
  29. tracebloc-1.2.87/tracebloc/validation/estimator_checks.py +16 -0
  30. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/validation/lifelines_checks.py +2 -10
  31. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/validation/scikit_survival_checks.py +2 -10
  32. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/validation/sklearn_checks.py +4 -10
  33. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc.egg-info/PKG-INFO +1 -1
  34. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc.egg-info/SOURCES.txt +15 -1
  35. tracebloc-1.2.85/tracebloc/raw_mode.py +0 -499
  36. {tracebloc-1.2.85 → tracebloc-1.2.87}/MANIFEST.in +0 -0
  37. {tracebloc-1.2.85 → tracebloc-1.2.87}/README.md +0 -0
  38. {tracebloc-1.2.85 → tracebloc-1.2.87}/license.txt +0 -0
  39. {tracebloc-1.2.85 → tracebloc-1.2.87}/setup.cfg +0 -0
  40. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/__init__.py +0 -0
  41. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_deprecation.py +0 -0
  42. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_framework_utils.py +0 -0
  43. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_http_utils.py +0 -0
  44. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_link_answer.py +0 -0
  45. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_link_regeneration.py +0 -0
  46. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_linking.py +0 -0
  47. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_raw_width_note.py +0 -0
  48. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_stored_link.py +0 -0
  49. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/_upload_conversion.py +0 -0
  50. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/checks.py +0 -0
  51. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/client.py +0 -0
  52. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/config.py +0 -0
  53. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/contracts/stage_urls.v1.json +0 -0
  54. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/contracts/stage_urls.v1.source.json +0 -0
  55. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/contracts/survival_payload.py +0 -0
  56. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/contracts/training_requirements.source.json +0 -0
  57. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/contracts/training_requirements.txt +0 -0
  58. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/__init__.py +0 -0
  59. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/acceptance.py +0 -0
  60. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/families/__init__.py +0 -0
  61. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/families/hf/__init__.py +0 -0
  62. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/families/hf/_build.py +0 -0
  63. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/families/hf/_model_type.py +0 -0
  64. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/families/tabular.py +0 -0
  65. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/families/vision/__init__.py +0 -0
  66. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/families/vision/_matching.py +0 -0
  67. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/gate.py +0 -0
  68. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/heads.py +0 -0
  69. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/interfaces.py +0 -0
  70. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/licence/__init__.py +0 -0
  71. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/licence/spdx.py +0 -0
  72. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/outputs.py +0 -0
  73. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/__init__.py +0 -0
  74. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/arguments.py +0 -0
  75. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/assemble.py +0 -0
  76. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/checkpoint.py +0 -0
  77. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/gate_rules.py +0 -0
  78. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/generate.py +0 -0
  79. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/head.py +0 -0
  80. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/import_check.py +0 -0
  81. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/layer0.py +0 -0
  82. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/live.py +0 -0
  83. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/model_class.py +0 -0
  84. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/remote.py +0 -0
  85. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/repo.py +0 -0
  86. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/shake.py +0 -0
  87. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/owncode/source_tree.py +0 -0
  88. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/package.py +0 -0
  89. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/report.py +0 -0
  90. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/tokenizers.py +0 -0
  91. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/convert/training_versions.py +0 -0
  92. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/env_login.py +0 -0
  93. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/exceptions.py +0 -0
  94. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/fetch.py +0 -0
  95. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/inference.py +0 -0
  96. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/library_fetch.py +0 -0
  97. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/lifelines_weights.py +0 -0
  98. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/link_model_dataset.py +0 -0
  99. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/notebook/__init__.py +0 -0
  100. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/notebook/templates/_partials.tpl +0 -0
  101. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/notebook/templates/embeddings.tpl +0 -0
  102. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/notebook/templates/nlp_finetune.tpl +0 -0
  103. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/notebook/templates/nlp_generative.tpl +0 -0
  104. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/notebook/templates/survival.tpl +0 -0
  105. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/notebook/templates/tabular_timeseries.tpl +0 -0
  106. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/notebook/templates/vision_from_scratch.tpl +0 -0
  107. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/seed_weights.py +0 -0
  108. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/__init__.py +0 -0
  109. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/augmentation.py +0 -0
  110. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/callbacks.py +0 -0
  111. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/converted.py +0 -0
  112. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/features.py +0 -0
  113. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/image_channels.py +0 -0
  114. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/image_size.py +0 -0
  115. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/lora.py +0 -0
  116. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/lora_validation.py +0 -0
  117. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/loss.py +0 -0
  118. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/memory_estimate.py +0 -0
  119. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/plan.py +0 -0
  120. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/preprocessing.py +0 -0
  121. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/shape.py +0 -0
  122. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/subdataset.py +0 -0
  123. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/submitter.py +0 -0
  124. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/training/summary.py +0 -0
  125. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/__init__.py +0 -0
  126. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/lifelines_time_to_event.py +0 -0
  127. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/model_upload.py +0 -0
  128. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/scikit_survival_time_to_event.py +0 -0
  129. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/sequence_length.py +0 -0
  130. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/skl_tabular_base.py +0 -0
  131. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/skl_tabular_classifier.py +0 -0
  132. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/skl_tabular_regression.py +0 -0
  133. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/statistical_base.py +0 -0
  134. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/survival_base.py +0 -0
  135. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_causal_language_modeler.py +0 -0
  136. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_embeddings.py +0 -0
  137. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_key_point_detector.py +0 -0
  138. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_masked_language_modeler.py +0 -0
  139. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_multi_label_text_classifier.py +0 -0
  140. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_nlp_base.py +0 -0
  141. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_object_detector.py +0 -0
  142. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_sentence_pair_classifier.py +0 -0
  143. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_seq2seq_modeler.py +0 -0
  144. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_time_series_classifier.py +0 -0
  145. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/torch_time_series_forecaster.py +0 -0
  146. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/weight_loaders.py +0 -0
  147. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/upload/weights_parts.py +0 -0
  148. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/user.py +0 -0
  149. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/__init__.py +0 -0
  150. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/class_order.py +0 -0
  151. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/constants.py +0 -0
  152. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/custom_loss_probe.py +0 -0
  153. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/data_probes.py +0 -0
  154. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/device.py +0 -0
  155. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/entry_point.py +0 -0
  156. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/errors.py +0 -0
  157. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/feature_dict.py +0 -0
  158. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/general_utils.py +0 -0
  159. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/key_point_detection_utils.py +0 -0
  160. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/model_loading.py +0 -0
  161. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/model_params.py +0 -0
  162. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/registry.py +0 -0
  163. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/resources.py +0 -0
  164. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/safetensors_io.py +0 -0
  165. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/semantic_segmentation_utils.py +0 -0
  166. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/tabular_classification_utils.py +0 -0
  167. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/tabular_custom_loss_utils.py +0 -0
  168. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/tabular_regression_utils.py +0 -0
  169. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/text_classification_utils.py +0 -0
  170. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/time_series_utils.py +0 -0
  171. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/time_to_event_utils.py +0 -0
  172. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/utils/warnings_once.py +0 -0
  173. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/validation/__init__.py +0 -0
  174. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/validation/checker.py +0 -0
  175. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/validation/header_rules.py +0 -0
  176. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/validation/pytorch_checks.py +0 -0
  177. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc/validation/rewriter.py +0 -0
  178. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc.egg-info/dependency_links.txt +0 -0
  179. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc.egg-info/requires.txt +0 -0
  180. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc.egg-info/top_level.txt +0 -0
  181. {tracebloc-1.2.85 → tracebloc-1.2.87}/tracebloc_package/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tracebloc
3
- Version: 1.2.85
3
+ Version: 1.2.87
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 = "1.2.85"
7
+ version = "1.2.87"
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"]
@@ -0,0 +1,91 @@
1
+ """Raw mode, the SDK half: check a model that brings its own data preparation.
2
+
3
+ RFC-0243 D9 (backend#5679). A model trained outside tracebloc ships its own
4
+ preparation, e.g. a fitted scikit-learn ``Pipeline`` (imputer + encoder +
5
+ scaler + estimator), and declares it in the model file::
6
+
7
+ DATA_PREPARATION = "model"
8
+
9
+ The backend reads that declaration at an inference-only Start and tells the
10
+ engine, which then gives the model the test table's RAW columns
11
+ (tracebloc/tracebloc-engine#1639):
12
+
13
+ * input: a ``pandas.DataFrame`` of every dataset column except the label, by
14
+ name, in the dataset schema's order, as stored (raw dtypes, categoricals as
15
+ strings, missing values as NaN);
16
+ * output, classification: class NAMES (the dataset's labels) or platform class
17
+ INDICES; output, regression: the target in its original units.
18
+
19
+ The fitted estimator lives in the pickled weights, which the backend never
20
+ unpickles, so the checks that need it run here, at the dataset link, before
21
+ anything is started:
22
+
23
+ * columns: the columns the model was fitted on (``feature_names_in_``) must all
24
+ be among the dataset's non-label columns, since the engine passes them by
25
+ name. A model fitted on a numpy array names none, and is refused;
26
+ * classes (classification): the model's ``classes_`` must be the dataset's
27
+ class names, or all platform class indices, as the engine maps them.
28
+
29
+ That is the scikit-learn tabular pair (tabular classification and regression on
30
+ ``sklearn``: scikit-learn, xgboost, lightgbm). The other pairs the engine runs
31
+ raw have their own checks, each the strongest that can run before Start:
32
+ PyTorch tabular and time series in :mod:`tracebloc.raw_mode.torch_checks` (the model's
33
+ own ``preprocess`` / forward called on synthetic rows built from the schema),
34
+ time-to-event on lifelines and scikit-survival in
35
+ :mod:`tracebloc.raw_mode.survival` (the fitted covariates). Any other pair
36
+ (PyTorch time-to-event among them) is the platform's to accept or refuse at
37
+ Start.
38
+
39
+ The package (RFC-0348 C.2): ``declaration`` (the model file's
40
+ ``DATA_PREPARATION``), ``pairs`` (the tasks run raw), ``fitted_model`` (the
41
+ weights, unpickled), ``schema`` (the dataset's columns), ``classes`` (class
42
+ mapping), ``sklearn_check``, ``torch_checks`` with ``frame_recording`` and
43
+ ``seed_prefixes``, ``survival``, and ``link_check`` (the link's raw-mode step).
44
+ This module re-exports what ``tracebloc/raw_mode.py`` held, so existing callers
45
+ import exactly what they did; the old ``tracebloc.raw_mode_frame``,
46
+ ``raw_mode_seed``, ``raw_mode_survival`` and ``raw_mode_torch`` modules re-export
47
+ their moved names too. New code imports from the module named for the concept.
48
+ """
49
+
50
+ from .declaration import ( # noqa: F401 (re-export, RFC-0348 C.2)
51
+ DATA_PREPARATION,
52
+ MODEL_PREPARES,
53
+ CONTRACT_HEADER,
54
+ _declared,
55
+ declares_raw_mode,
56
+ )
57
+ from .pairs import ( # noqa: F401 (re-export, RFC-0348 C.2)
58
+ SKLEARN_TABULAR,
59
+ TORCH_TABULAR,
60
+ TORCH_SERIES,
61
+ SURVIVAL,
62
+ RAW_MODE_CHECKED,
63
+ )
64
+ from .fitted_model import ( # noqa: F401 (re-export, RFC-0348 C.2)
65
+ load_fitted_model,
66
+ load_beside,
67
+ require_fitted_weights,
68
+ load_or_refuse,
69
+ )
70
+ from .schema import ( # noqa: F401 (re-export, RFC-0348 C.2)
71
+ LABEL_COLUMN,
72
+ SCHEMA_PATH,
73
+ dataset_schema,
74
+ dataset_columns,
75
+ )
76
+ from .classes import ( # noqa: F401 (re-export, RFC-0348 C.2)
77
+ _integral,
78
+ foreign_classes,
79
+ _listed,
80
+ check_exact_classes,
81
+ link_dataset_classes,
82
+ )
83
+ from .sklearn_check import ( # noqa: F401 (re-export, RFC-0348 C.2)
84
+ _FIT_ON_A_DATAFRAME,
85
+ model_feature_names,
86
+ check_raw_model,
87
+ )
88
+ from .link_check import ( # noqa: F401 (re-export, RFC-0348 C.2)
89
+ RawModeCheck,
90
+ raw_mode_input_contract,
91
+ )
@@ -0,0 +1,100 @@
1
+ """A raw-mode model's classes against the dataset's, mapped as the engine's
2
+ ``RawModelAdapter`` maps them: by name first, else as platform class indices."""
3
+
4
+ from __future__ import annotations
5
+
6
+ from ..exceptions import RawModeCheckError
7
+
8
+
9
+ def _integral(values):
10
+ """``values`` as ints when every one is a whole number, else ``None``
11
+ (the engine's ``_integral_values``: ``1.0`` is ``1``, ``"1"`` is not)."""
12
+ integers = []
13
+ for value in values:
14
+ if isinstance(value, bool) or not isinstance(value, (int, float)):
15
+ try: # numpy scalars
16
+ value = value.item()
17
+ except AttributeError:
18
+ return None
19
+ if isinstance(value, bool) or not isinstance(value, (int, float)):
20
+ return None
21
+ if isinstance(value, float) and not value.is_integer():
22
+ return None
23
+ integers.append(int(value))
24
+ return integers
25
+
26
+
27
+
28
+ def foreign_classes(model_classes, dataset_classes):
29
+ """The model's classes the engine cannot map onto ``dataset_classes``,
30
+ sorted; ``[]`` when it can.
31
+
32
+ As the engine reads them (``RawModelAdapter``): by NAME first, so an integer
33
+ label that is a class name maps by name; otherwise, when every one is a
34
+ whole number, as platform class indices ``0 .. n-1``.
35
+ """
36
+ known = {str(name) for name in dataset_classes}
37
+ integral = _integral(model_classes)
38
+ names = (
39
+ [str(value) for value in integral]
40
+ if integral is not None
41
+ else [str(value) for value in model_classes]
42
+ )
43
+ if all(name in known for name in names):
44
+ return []
45
+ if integral is not None and all(0 <= v < len(known) for v in integral):
46
+ return []
47
+ return sorted(set(names) - known)
48
+
49
+
50
+
51
+ def _listed(values):
52
+ """``classes_`` (a list, a numpy array, a tensor) as a flat list."""
53
+ if hasattr(values, "tolist"):
54
+ values = values.tolist()
55
+ flat = []
56
+ for value in values if isinstance(values, (list, tuple)) else [values]:
57
+ flat.extend(_listed(value) if isinstance(value, (list, tuple)) else [value])
58
+ return flat
59
+
60
+
61
+
62
+ def check_exact_classes(model_classes, dataset_classes):
63
+ """Refuse, by name, a ``classes_`` that is not EXACTLY the dataset's classes,
64
+ each once (the PyTorch raw paths: a score column per platform class).
65
+
66
+ Mapped as the engine's ``RawModelAdapter`` maps it: by name first, else all
67
+ whole numbers as platform indices ``0 .. n-1``.
68
+ """
69
+ model_classes = _listed(model_classes)
70
+ known = [str(name) for name in dataset_classes]
71
+ foreign = foreign_classes(model_classes, dataset_classes)
72
+ if foreign:
73
+ raise RawModeCheckError(
74
+ f"The model's classes_ name class(es) {foreign} that are not among "
75
+ f"this dataset's classes {known}."
76
+ )
77
+ integral = _integral(model_classes)
78
+ names = [str(v) for v in (integral if integral is not None else model_classes)]
79
+ if all(name in known for name in names):
80
+ indices = [known.index(name) for name in names]
81
+ else: # all platform indices (foreign_classes passed them)
82
+ indices = integral
83
+ if sorted(indices) != list(range(len(known))):
84
+ raise RawModeCheckError(
85
+ f"The model's classes_ {[str(c) for c in model_classes]} must name "
86
+ f"exactly this dataset's classes {known}, each once, in the model's "
87
+ "output column order."
88
+ )
89
+
90
+
91
+
92
+ def link_dataset_classes(content):
93
+ """The use case's classes from the link answer: ``class_order``, else the
94
+ keys of ``class_names``."""
95
+ dataset_classes = content.get("class_order")
96
+ if not isinstance(dataset_classes, (list, tuple)) or not dataset_classes:
97
+ class_names = content.get("class_names")
98
+ dataset_classes = list(class_names) if isinstance(class_names, dict) else []
99
+ return list(dataset_classes)
100
+
@@ -0,0 +1,89 @@
1
+ """Raw mode's declaration: ``DATA_PREPARATION = "model"`` in the model file,
2
+ read as the platform reads it (parsed, never imported)."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import ast
7
+ import os
8
+ import zipfile
9
+
10
+ from ..exceptions import RawModeCheckError
11
+ from ..utils.general_utils import format_exception
12
+
13
+
14
+ #: The module-level constant a model file declares its data preparation with.
15
+ DATA_PREPARATION = "DATA_PREPARATION"
16
+
17
+
18
+ #: The declared value meaning "the model brings its own preparation".
19
+ MODEL_PREPARES = "model"
20
+
21
+
22
+ #: The first line of every printed input contract.
23
+ CONTRACT_HEADER = (
24
+ 'Raw mode (DATA_PREPARATION = "model"): the model prepares its own data.'
25
+ )
26
+
27
+
28
+
29
+ def _declared(source):
30
+ """The string ``source`` assigns to ``DATA_PREPARATION`` at module level
31
+ (the last assignment wins, as the platform reads it), or ``None``.
32
+ Parsed, never imported."""
33
+ try:
34
+ tree = ast.parse(source)
35
+ except (SyntaxError, ValueError, RecursionError, MemoryError):
36
+ return None
37
+ value = None
38
+ for node in tree.body:
39
+ if (
40
+ isinstance(node, ast.Assign)
41
+ and len(node.targets) == 1
42
+ and isinstance(node.targets[0], ast.Name)
43
+ and node.targets[0].id == DATA_PREPARATION
44
+ and isinstance(node.value, ast.Constant)
45
+ ):
46
+ value = node.value.value
47
+ if not isinstance(value, str):
48
+ return None
49
+ return MODEL_PREPARES if value.strip().lower() == MODEL_PREPARES else "tracebloc"
50
+
51
+
52
+
53
+ def declares_raw_mode(model_file_path):
54
+ """Whether the model file (a ``.py``, or a ``.zip`` of them) declares
55
+ ``DATA_PREPARATION = "model"``, as the platform reads it.
56
+
57
+ Raises :class:`RawModeCheckError` when the members of a zip disagree: the
58
+ platform refuses such a model, since it cannot tell which one runs.
59
+ """
60
+ if not model_file_path or not os.path.isfile(model_file_path):
61
+ return False
62
+ found = {}
63
+ try:
64
+ if zipfile.is_zipfile(model_file_path):
65
+ with zipfile.ZipFile(model_file_path) as archive:
66
+ for info in archive.infolist():
67
+ if info.is_dir() or not info.filename.endswith(".py"):
68
+ continue
69
+ value = _declared(archive.read(info).decode("utf-8-sig", "replace"))
70
+ if value is not None:
71
+ found[info.filename] = value
72
+ else:
73
+ with open(model_file_path, encoding="utf-8-sig", errors="replace") as file:
74
+ value = _declared(file.read())
75
+ if value is not None:
76
+ found[os.path.basename(model_file_path)] = value
77
+ except (OSError, zipfile.BadZipFile) as error:
78
+ raise RawModeCheckError(
79
+ "The model file could not be read to find its data preparation "
80
+ f"declaration: {format_exception(error)}"
81
+ ) from error
82
+ if len(set(found.values())) > 1:
83
+ listed = ", ".join(f"{name}: {found[name]}" for name in sorted(found))
84
+ raise RawModeCheckError(
85
+ f"The model's files disagree on its data preparation ({listed}): "
86
+ f'declare DATA_PREPARATION = "model" in one file of the zip, or in none.'
87
+ )
88
+ return MODEL_PREPARES in found.values()
89
+
@@ -0,0 +1,86 @@
1
+ """The fitted raw-mode model: its uploaded weights, unpickled beside the model
2
+ file, or a named refusal."""
3
+
4
+ from __future__ import annotations
5
+
6
+ import os
7
+ import pickle
8
+ import sys
9
+ import zipfile
10
+
11
+ from ..exceptions import RawModeCheckError
12
+ from ..utils.general_utils import format_exception
13
+
14
+
15
+ def load_fitted_model(weights_path):
16
+ """The fitted estimator in the weights file (``.joblib``, else pickle)."""
17
+ if os.path.splitext(weights_path)[1].lower() == ".joblib":
18
+ import joblib
19
+
20
+ return joblib.load(weights_path)
21
+ # The user's own weights file, which upload_model already unpickles in this
22
+ # process (``Model.validate_model_file``): no new trust boundary.
23
+ with open(weights_path, "rb") as file:
24
+ return pickle.load(file) # nosec B301
25
+
26
+
27
+
28
+ def load_beside(model_file_path):
29
+ """``load_fitted_model`` with the model file's folder importable, so a class
30
+ pickled from that file unpickles; a zip model is importable as the archive
31
+ itself. The entry goes to the FRONT of ``sys.path`` for the load only, so a
32
+ folder already on the path (a notebook's own) cannot win with a same-named
33
+ module, and comes out after. Modules imported from those entries are dropped
34
+ after the load, so a later model reads its own. Every raw pair that unpickles
35
+ a fitted model loads through this."""
36
+ if not model_file_path:
37
+ entries = []
38
+ elif zipfile.is_zipfile(model_file_path):
39
+ entries = [os.path.abspath(model_file_path)]
40
+ else:
41
+ entries = [os.path.dirname(os.path.abspath(model_file_path))]
42
+
43
+ def load(weights_path):
44
+ before = set(sys.modules)
45
+ sys.path[:0] = entries
46
+ try:
47
+ return load_fitted_model(weights_path)
48
+ finally:
49
+ for entry in entries:
50
+ sys.path.remove(entry) # the first copy: the one put in front
51
+ for name in set(sys.modules) - before:
52
+ origin = getattr(sys.modules.get(name), "__file__", None)
53
+ if origin and any(
54
+ os.path.abspath(origin).startswith(entry + os.sep)
55
+ for entry in entries
56
+ ):
57
+ sys.modules.pop(name, None)
58
+
59
+ return load
60
+
61
+
62
+
63
+ def require_fitted_weights(user):
64
+ """The uploaded weights file of a model scored as fitted, or a named
65
+ refusal when there is none."""
66
+ weights_path = user._User__weights_file_path
67
+ if not user._User__weights or not weights_path or not os.path.isfile(weights_path):
68
+ raise RawModeCheckError(
69
+ "A model that brings its own data preparation is scored as fitted: "
70
+ "upload it with its fitted weights (weights=True, e.g. "
71
+ "<model>_weights.pkl)."
72
+ )
73
+ return weights_path
74
+
75
+
76
+
77
+ def load_or_refuse(load, weights_path):
78
+ """``load(weights_path)``; a failure is a named refusal, never a pass."""
79
+ try:
80
+ return load(weights_path)
81
+ except Exception as error:
82
+ raise RawModeCheckError(
83
+ f"Could not load the fitted model from its weights: "
84
+ f"{format_exception(error)}"
85
+ ) from error
86
+
@@ -1,5 +1,5 @@
1
1
  """The frame a raw-mode PyTorch model's code is called on at link time
2
- (:mod:`tracebloc.raw_mode_torch`): a DataFrame that records every column the
2
+ (:mod:`tracebloc.raw_mode.torch_checks`): a DataFrame that records every column the
3
3
  code read by name and the dataset does not have, so that read is refused by
4
4
  name rather than reported as a failure on the dummy values."""
5
5
 
@@ -106,7 +106,8 @@ def reads_frames(model_file_path, category, framework):
106
106
  columns (the platform's count includes ``time``) and average with it. Raw
107
107
  mode is inference only (RFC-0243 D9), so the upload skips the step; the
108
108
  link checks the model instead (``check_series_*``, the fitted covariates)."""
109
- from .raw_mode import SURVIVAL, TORCH_SERIES, declares_raw_mode
109
+ from .declaration import declares_raw_mode
110
+ from .pairs import SURVIVAL, TORCH_SERIES
110
111
 
111
112
  pairs = TORCH_SERIES | SURVIVAL
112
113
  return (category, framework) in pairs and declares_raw_mode(model_file_path)
@@ -119,7 +120,7 @@ def raw_upload_failure(task):
119
120
  ``("model", error)``, named as the link names it, never raised. The upload
120
121
  (``model_func_checks``) and the Run tab's Trains check
121
122
  (``tracebloc.checks.trains``) both call this, so they cannot disagree."""
122
- from .exceptions import RawModeCheckError
123
+ from ..exceptions import RawModeCheckError
123
124
 
124
125
  path = getattr(task, "_Model__model_path", None)
125
126
  try:
@@ -0,0 +1,58 @@
1
+ """Raw mode's step in the dataset link: pick the pair's check and run it."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import NamedTuple
6
+
7
+ from .classes import link_dataset_classes
8
+ from .declaration import declares_raw_mode
9
+ from .fitted_model import load_beside, load_or_refuse, require_fitted_weights
10
+ from .pairs import RAW_MODE_CHECKED, SURVIVAL, TORCH_SERIES, TORCH_TABULAR
11
+ from .schema import dataset_columns
12
+ from .sklearn_check import check_raw_model
13
+
14
+
15
+ class RawModeCheck(NamedTuple):
16
+ """``raw_mode_input_contract``'s answer: the checked input contract (to
17
+ print with the class order) and the fitted model it was checked on."""
18
+
19
+ #: The checked input contract as text.
20
+ contract: str
21
+ #: The fitted model unpickled from the weights (the model that runs), or
22
+ #: ``None`` when the pair's check loads none (the PyTorch pairs).
23
+ fitted: object = None
24
+
25
+
26
+
27
+ def raw_mode_input_contract(user, dataset_id, content):
28
+ """``User.__check_model``'s raw-mode step, on a passed link answer.
29
+
30
+ ``None`` when the model does not declare raw mode, or its task is not one
31
+ the engine runs raw; otherwise a :class:`RawModeCheck`: the checked input
32
+ contract and the fitted model it loaded, which is what runs, so the link's
33
+ federated-averageability gate judges it, not the ``MyModel()`` factory
34
+ (backend#5679, #872). Raises :class:`RawModeCheckError` with a named reason.
35
+ """
36
+ if not declares_raw_mode(user._User__model_file_path):
37
+ return None
38
+ pair = (user._User__category, user._User__framework)
39
+ if pair not in RAW_MODE_CHECKED:
40
+ return None
41
+ if pair in TORCH_TABULAR or pair in TORCH_SERIES:
42
+ from .torch_checks import torch_input_contract
43
+
44
+ return RawModeCheck(torch_input_contract(user, dataset_id, content))
45
+ if pair in SURVIVAL:
46
+ from .survival import survival_input_contract
47
+
48
+ return RawModeCheck(*survival_input_contract(user, dataset_id))
49
+ weights_path = require_fitted_weights(user)
50
+ model = load_or_refuse(load_beside(user._User__model_file_path), weights_path)
51
+ contract = check_raw_model(
52
+ model,
53
+ columns=dataset_columns(user._User__client, dataset_id),
54
+ category=pair[0],
55
+ dataset_classes=link_dataset_classes(content),
56
+ )
57
+ return RawModeCheck(contract, model)
58
+
@@ -0,0 +1,54 @@
1
+ """The (category, framework) pairs the engine runs in raw mode."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ..utils.constants import (
6
+ LIFELINES_FRAMEWORK,
7
+ PYTORCH_FRAMEWORK,
8
+ SCIKIT_SURVIVAL_FRAMEWORK,
9
+ SKLEARN_FRAMEWORK,
10
+ TABULAR_CLASSIFICATION,
11
+ TABULAR_REGRESSION,
12
+ TIME_SERIES_CLASSIFICATION,
13
+ TIME_SERIES_FORECASTING,
14
+ TIME_TO_EVENT_PREDICTION,
15
+ )
16
+
17
+
18
+ #: The (category, framework) pairs the engine runs in raw mode
19
+ #: (tracebloc-engine#1639 sklearn tabular, #1758 PyTorch tabular, #1756 time
20
+ #: series, #1755 time-to-event; backend ``experiments/services/raw_mode.py``).
21
+ SKLEARN_TABULAR = frozenset(
22
+ {
23
+ (TABULAR_CLASSIFICATION, SKLEARN_FRAMEWORK),
24
+ (TABULAR_REGRESSION, SKLEARN_FRAMEWORK),
25
+ }
26
+ )
27
+
28
+
29
+ TORCH_TABULAR = frozenset(
30
+ {
31
+ (TABULAR_CLASSIFICATION, PYTORCH_FRAMEWORK),
32
+ (TABULAR_REGRESSION, PYTORCH_FRAMEWORK),
33
+ }
34
+ )
35
+
36
+
37
+ TORCH_SERIES = frozenset(
38
+ {
39
+ (TIME_SERIES_CLASSIFICATION, PYTORCH_FRAMEWORK),
40
+ (TIME_SERIES_FORECASTING, PYTORCH_FRAMEWORK),
41
+ }
42
+ )
43
+
44
+
45
+ SURVIVAL = frozenset(
46
+ {
47
+ (TIME_TO_EVENT_PREDICTION, LIFELINES_FRAMEWORK),
48
+ (TIME_TO_EVENT_PREDICTION, SCIKIT_SURVIVAL_FRAMEWORK),
49
+ }
50
+ )
51
+
52
+
53
+ RAW_MODE_CHECKED = SKLEARN_TABULAR | TORCH_TABULAR | TORCH_SERIES | SURVIVAL
54
+
@@ -0,0 +1,58 @@
1
+ """The dataset's column schema, as a raw-mode model receives the columns."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from ..exceptions import APIError, RawModeCheckError
6
+ from ..training.features import _EXCLUDED_COLUMNS
7
+ from ..utils.general_utils import format_exception
8
+
9
+
10
+ #: The engine's label column (``core/data/constants.py``); it never reaches
11
+ #: the model.
12
+ LABEL_COLUMN = "label"
13
+
14
+
15
+ #: Where the dataset's column schema is read (``FeatureConfig.load`` too).
16
+ SCHEMA_PATH = "dataset/global_meta_data/"
17
+
18
+
19
+
20
+ def dataset_schema(client, dataset_id, excluded=_EXCLUDED_COLUMNS):
21
+ """The dataset's columns and their stored types, in schema order, less the
22
+ ingestor bookkeeping columns ``excluded`` (the label is kept).
23
+
24
+ Raises :class:`RawModeCheckError` when the schema cannot be read or names no
25
+ column besides the label: the check cannot tell, which is not a pass.
26
+ """
27
+ try:
28
+ response = client.get(
29
+ SCHEMA_PATH, params={"dataset_id": dataset_id}, raise_on_error=False
30
+ )
31
+ schema = response.json().get("schema") if response.status_code == 200 else None
32
+ except Exception as error:
33
+ # raise_on_error=False: only a 426 (SDK below the API floor) has a status.
34
+ if isinstance(error, APIError) and error.status_code != 0:
35
+ raise
36
+ schema, status = None, format_exception(error)
37
+ else:
38
+ status = f"HTTP {response.status_code}"
39
+ columns = {
40
+ column: sql_type
41
+ for column, sql_type in (schema if isinstance(schema, dict) else {}).items()
42
+ if column not in excluded
43
+ }
44
+ if not [column for column in columns if column != LABEL_COLUMN]:
45
+ raise RawModeCheckError(
46
+ f"Could not read dataset '{dataset_id}''s columns ({status}), so a model "
47
+ "that brings its own data preparation cannot be checked against them. "
48
+ "Try again."
49
+ )
50
+ return columns
51
+
52
+
53
+
54
+ def dataset_columns(client, dataset_id):
55
+ """The dataset's non-label columns, in schema order (see
56
+ :func:`dataset_schema`)."""
57
+ return [c for c in dataset_schema(client, dataset_id) if c != LABEL_COLUMN]
58
+
@@ -32,7 +32,7 @@ def seed_excluded_prefixes(model_file_path):
32
32
  nothing declares them or the file cannot be read."""
33
33
  import tempfile
34
34
 
35
- from .upload.weight_loaders import read_seed_excluded_prefixes
35
+ from ..upload.weight_loaders import read_seed_excluded_prefixes
36
36
 
37
37
  if not model_file_path or not os.path.isfile(model_file_path):
38
38
  return ()