tracebloc 1.2.89__tar.gz → 1.2.91__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.
- {tracebloc-1.2.89 → tracebloc-1.2.91}/PKG-INFO +1 -1
- {tracebloc-1.2.89 → tracebloc-1.2.91}/pyproject.toml +1 -1
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_linking.py +14 -16
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/tabular.py +1 -2
- tracebloc-1.2.91/tracebloc/training/link_total.py +19 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/loss.py +14 -228
- tracebloc-1.2.91/tracebloc/training/loss_policy.py +112 -0
- tracebloc-1.2.91/tracebloc/training/loss_source.py +157 -0
- tracebloc-1.2.91/tracebloc/upload/nlp_probes.py +217 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_nlp_base.py +7 -195
- tracebloc-1.2.91/tracebloc/utils/declared_cls.py +64 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/text_classification_utils.py +5 -5
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc.egg-info/PKG-INFO +1 -1
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc.egg-info/SOURCES.txt +5 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/MANIFEST.in +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/README.md +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/license.txt +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/setup.cfg +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_deprecation.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_framework_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_http_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_link_answer.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_link_regeneration.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_raw_width_note.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_stored_link.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/_upload_conversion.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/checks.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/client.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/config.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/contracts/stage_urls.v1.json +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/contracts/stage_urls.v1.source.json +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/contracts/survival_payload.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/contracts/training_requirements.source.json +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/contracts/training_requirements.txt +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/acceptance.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/families/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/families/hf/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/families/hf/_build.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/families/hf/_model_type.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/families/tabular.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/families/vision/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/families/vision/_matching.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/gate.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/heads.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/interfaces.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/licence/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/licence/spdx.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/outputs.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/arguments.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/assemble.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/checkpoint.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/gate_rules.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/generate.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/head.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/import_check.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/layer0.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/live.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/model_class.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/remote.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/repo.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/shake.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/owncode/source_tree.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/package.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/report.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/tokenizers.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/convert/training_versions.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/base.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/detection.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/keypoint_detection.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/semantic_segmentation.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/text.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/time_series.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/datasets/time_to_event.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/env_login.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/exceptions.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/fetch.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/inference.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/library_fetch.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/lifelines_weights.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/link_model_dataset.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/notebook/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/notebook/templates/_partials.tpl +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/notebook/templates/embeddings.tpl +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/notebook/templates/nlp_finetune.tpl +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/notebook/templates/nlp_generative.tpl +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/notebook/templates/survival.tpl +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/notebook/templates/tabular_timeseries.tpl +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/notebook/templates/vision_from_scratch.tpl +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/classes.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/declaration.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/fitted_model.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/frame_recording.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/link_check.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/pairs.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/schema.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/seed_prefixes.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/sklearn_check.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/survival.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode/torch_checks.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode_frame.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode_seed.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode_survival.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/raw_mode_torch.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/seed_weights.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/augmentation.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/callbacks.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/converted.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/features.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/image_channels.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/image_size.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/lora.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/lora_validation.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/memory_estimate.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/plan.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/preprocessing.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/shape.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/subdataset.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/submitter.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/training/summary.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/lifelines_time_to_event.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/model_upload.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/scikit_survival_time_to_event.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/sequence_length.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/skl_tabular_base.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/skl_tabular_classifier.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/skl_tabular_regression.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/statistical_base.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/survival_base.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_causal_language_modeler.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_embeddings.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_handler.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_image_classifier.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_key_point_detector.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_masked_language_modeler.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_multi_label_text_classifier.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_object_detector.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_semantic_segmentation.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_sentence_pair_classifier.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_seq2seq_modeler.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_tabular_classifier.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_tabular_regression.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_text_classifier.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_text_regressor.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_time_series_classifier.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_time_series_forecaster.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_time_to_event.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/torch_token_classifier.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/weight_loaders.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/upload/weights_parts.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/user.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/class_order.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/constants.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/custom_loss_probe.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/data_probes.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/declared_classes.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/detection_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/device.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/entry_point.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/errors.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/feature_dict.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/general_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/key_point_detection_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/model_loading.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/model_params.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/registry.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/resources.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/safetensors_io.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/semantic_segmentation_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/tabular_classification_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/tabular_custom_loss_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/tabular_regression_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/time_series_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/time_to_event_utils.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/utils/warnings_once.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/__init__.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/checker.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/estimator_checks.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/header_rules.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/lifelines_checks.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/pytorch_checks.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/rewriter.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/scikit_survival_checks.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc/validation/sklearn_checks.py +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc.egg-info/dependency_links.txt +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc.egg-info/requires.txt +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc.egg-info/top_level.txt +0 -0
- {tracebloc-1.2.89 → tracebloc-1.2.91}/tracebloc_package/__init__.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "tracebloc"
|
|
7
|
-
version = "1.2.
|
|
7
|
+
version = "1.2.91"
|
|
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"]
|
|
@@ -34,7 +34,8 @@ from ._link_answer import compared_keys
|
|
|
34
34
|
from ._link_regeneration import regenerated_for_link # noqa: F401
|
|
35
35
|
from .exceptions import APIError, DatasetLinkingError
|
|
36
36
|
from .training.image_size import image_size_warning
|
|
37
|
-
from .training.
|
|
37
|
+
from .training.link_total import label_sum_allowed
|
|
38
|
+
from .training.subdataset import dataset_record_total
|
|
38
39
|
from .utils.class_order import class_order_text
|
|
39
40
|
from .utils.general_utils import get_images_count, resource_fit_warning
|
|
40
41
|
from .validation.sklearn_checks import non_averageable_estimator_reason
|
|
@@ -238,7 +239,9 @@ def _render_mismatch_diagnostics(
|
|
|
238
239
|
"""
|
|
239
240
|
expected_msg = ""
|
|
240
241
|
if category not in NO_OUTPUT_CLASSES:
|
|
241
|
-
|
|
242
|
+
# A one-output head is 1-wide whatever the dataset's bucket count.
|
|
243
|
+
width = 1 if category in SINGLE_OUTPUT else content.get("dataset_classes")
|
|
244
|
+
expected_msg += f" output_classes : {width}\n"
|
|
242
245
|
if "datasetShape" in content:
|
|
243
246
|
expected_msg += f" shape : {content['datasetShape']}\n"
|
|
244
247
|
if "sequenceLength" in content:
|
|
@@ -341,13 +344,12 @@ def _apply_link_success(
|
|
|
341
344
|
"""
|
|
342
345
|
total_images = content["total_images"]
|
|
343
346
|
num_classes = content["dataset_classes"]
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
# sum (same stance as the record bound); a held count (``is_held``) leaves None.
|
|
347
|
+
# A SINGLE_OUTPUT dataset has no classes: no key, and no label sum to fall back on.
|
|
348
|
+
class_names = (
|
|
349
|
+
content.get("class_names", {}) if category in SINGLE_OUTPUT else content["class_names"]
|
|
350
|
+
)
|
|
349
351
|
total_dataset_size = dataset_record_total(total_images)
|
|
350
|
-
if total_dataset_size is None and
|
|
352
|
+
if total_dataset_size is None and label_sum_allowed(total_images, class_names, category):
|
|
351
353
|
total_dataset_size = get_images_count(class_names)
|
|
352
354
|
feature_modification = content["allow_feature_modification"]
|
|
353
355
|
table_name = content["table_name"]
|
|
@@ -389,14 +391,10 @@ def _apply_link_success(
|
|
|
389
391
|
if input_contract: # raw mode's checked input contract (backend#5679)
|
|
390
392
|
print(f"{input_contract}\n")
|
|
391
393
|
|
|
392
|
-
# Hard-fail:
|
|
393
|
-
#
|
|
394
|
-
#
|
|
395
|
-
#
|
|
396
|
-
# tag-aware derivation (post-split keys are single tags, so
|
|
397
|
-
# splitting is a no-op). A mismatch means the head validated at
|
|
398
|
-
# upload will be resized at experiment start — the validated
|
|
399
|
-
# architecture no longer applies, so we block here.
|
|
394
|
+
# Hard-fail: token-classification labels are BIO tag sequences, so the
|
|
395
|
+
# head must match the count of DISTINCT TAGS, not of sequences (splitting
|
|
396
|
+
# is a no-op on already-split keys). A mismatch would be resized at
|
|
397
|
+
# experiment start, invalidating the validated architecture.
|
|
400
398
|
if category == TOKEN_CLASSIFICATION and class_names:
|
|
401
399
|
distinct_tags = sorted(
|
|
402
400
|
{tag for sequence in class_names for tag in str(sequence).split()}
|
|
@@ -20,8 +20,7 @@ class TabularRegressionDataset(SyntheticDataset):
|
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
class TabularClassificationDataset(SyntheticDataset):
|
|
23
|
-
"""Tabular classification rows
|
|
24
|
-
``tabular_classification_utils.get_dataloader``."""
|
|
23
|
+
"""Tabular classification rows (features, float32 labels)."""
|
|
25
24
|
|
|
26
25
|
_size_attr = "labels"
|
|
27
26
|
_size_is_count = False
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""When a link may size a dataset from its label counts."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from tracebloc.validation.header_rules import SINGLE_OUTPUT
|
|
8
|
+
|
|
9
|
+
from .subdataset import any_held
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def label_sum_allowed(total_images: Any, class_names: Any, category: Any) -> bool:
|
|
13
|
+
"""True when an unreadable record count may fall back to the label sum.
|
|
14
|
+
|
|
15
|
+
``class_names`` counts tags / boxes, several per record, so the sum is only
|
|
16
|
+
a fallback: never for a SINGLE_OUTPUT category (no labels to sum), never when a
|
|
17
|
+
count is held (``is_held``), which must stay ``None``.
|
|
18
|
+
"""
|
|
19
|
+
return category not in SINGLE_OUTPUT and not any_held(total_images, class_names)
|
|
@@ -9,7 +9,9 @@ Part of the LinkModelDataset decomposition. Pure verbatim move of:
|
|
|
9
9
|
surgery so the file is self-contained on the training edge,
|
|
10
10
|
- ``__link_num_feature_points()`` — the feature-count read used by the
|
|
11
11
|
link-time re-validation handlers,
|
|
12
|
-
- the five module-level import-surgery helpers
|
|
12
|
+
- the five module-level import-surgery helpers (now in
|
|
13
|
+
:mod:`tracebloc.training.loss_source`; the policy table is in
|
|
14
|
+
:mod:`tracebloc.training.loss_policy`; both re-exported here, RFC-0348 A.5).
|
|
13
15
|
|
|
14
16
|
Like :class:`~tracebloc.training.submitter.ExperimentSubmitter`, this is a
|
|
15
17
|
**coordinator**, not a state-owning sub-object (see docs/ARCHITECTURE.md):
|
|
@@ -57,242 +59,26 @@ from tracebloc.utils.constants import (
|
|
|
57
59
|
EMBEDDINGS,
|
|
58
60
|
TIME_TO_EVENT_PREDICTION,
|
|
59
61
|
SKLEARN_FRAMEWORK,
|
|
60
|
-
PYTORCH_FRAMEWORK,
|
|
61
|
-
LIFELINES_FRAMEWORK,
|
|
62
|
-
SCIKIT_SURVIVAL_FRAMEWORK,
|
|
63
|
-
SEMANTIC_SEGMENTATION,
|
|
64
62
|
TIME_SERIES_FORECASTING,
|
|
65
63
|
TIME_SERIES_CLASSIFICATION,
|
|
66
64
|
)
|
|
67
65
|
|
|
68
66
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
binding each reference needs without having to model scopes.
|
|
76
|
-
"""
|
|
77
|
-
import ast
|
|
78
|
-
|
|
79
|
-
try:
|
|
80
|
-
tree = ast.parse(src)
|
|
81
|
-
except SyntaxError:
|
|
82
|
-
return set()
|
|
83
|
-
return {node.id for node in ast.walk(tree) if isinstance(node, ast.Name)}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def _is_tracebloc(name: str) -> bool:
|
|
87
|
-
"""True for ``tracebloc`` and its submodules (``tracebloc.x``)."""
|
|
88
|
-
return name == "tracebloc" or name.startswith("tracebloc.")
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def _imports_tracebloc(src: str) -> bool:
|
|
92
|
-
"""True if ``src`` imports ``tracebloc`` *anywhere* — top-level OR inside a
|
|
93
|
-
function/class body.
|
|
94
|
-
|
|
95
|
-
A custom loss runs on the training edge, which has the tracebloc *client*
|
|
96
|
-
but not the SDK package, so any ``import tracebloc`` in the loss aborts
|
|
97
|
-
training with ``ModuleNotFoundError: No module named 'tracebloc'``. Top-level
|
|
98
|
-
import filtering (:func:`_extract_top_level_imports`) only drops imports
|
|
99
|
-
*carried over* from the defining module's header; an import written inside
|
|
100
|
-
the loss body is part of the serialized source and survives. Walk the whole
|
|
101
|
-
AST so a body-level ``import tracebloc`` is caught and the upload is rejected
|
|
102
|
-
here rather than failing mid-run on the edge.
|
|
103
|
-
"""
|
|
104
|
-
import ast
|
|
105
|
-
|
|
106
|
-
try:
|
|
107
|
-
tree = ast.parse(src)
|
|
108
|
-
except SyntaxError:
|
|
109
|
-
return False
|
|
110
|
-
for node in ast.walk(tree):
|
|
111
|
-
if isinstance(node, ast.Import):
|
|
112
|
-
if any(_is_tracebloc(a.name) for a in node.names):
|
|
113
|
-
return True
|
|
114
|
-
elif isinstance(node, ast.ImportFrom):
|
|
115
|
-
# level>0 is a relative import (no module name to match); skip.
|
|
116
|
-
if node.module and _is_tracebloc(node.module):
|
|
117
|
-
return True
|
|
118
|
-
return False
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
def _extract_top_level_imports(module_src: str, used_names=None) -> str:
|
|
122
|
-
"""Return a module's top-level *absolute* imports needed by a custom loss.
|
|
123
|
-
|
|
124
|
-
Used to make a serialized custom-loss ``loss.py`` self-contained.
|
|
125
|
-
|
|
126
|
-
- Relative imports (``from .pkg import x``) are skipped: the client loads
|
|
127
|
-
``loss.py`` as a top-level module, where relative imports cannot resolve
|
|
128
|
-
and would raise ``ImportError`` — copying them only guarantees a runtime
|
|
129
|
-
failure.
|
|
130
|
-
- ``tracebloc`` imports are *always* dropped: the SDK is the upload-side
|
|
131
|
-
client and is never present on the training edge, so a carried-over
|
|
132
|
-
``from tracebloc import User`` aborts training with ``ModuleNotFoundError``
|
|
133
|
-
(the smoke-train passes in-process where tracebloc *is* importable, so it
|
|
134
|
-
only surfaces on the edge).
|
|
135
|
-
- When ``used_names`` is given (the set of names the loss body references),
|
|
136
|
-
an import is kept only if it binds a name the loss actually uses. The
|
|
137
|
-
common case — defining the loss in the same script that does
|
|
138
|
-
``from tracebloc import User`` to upload — therefore drops the tracebloc,
|
|
139
|
-
``os`` and other unrelated imports while keeping the framework imports the
|
|
140
|
-
loss relies on. ``used_names=None`` keeps every non-tracebloc absolute
|
|
141
|
-
import (best-effort, when the loss body could not be parsed).
|
|
142
|
-
"""
|
|
143
|
-
import ast
|
|
144
|
-
|
|
145
|
-
try:
|
|
146
|
-
tree = ast.parse(module_src)
|
|
147
|
-
except SyntaxError:
|
|
148
|
-
return ""
|
|
149
|
-
|
|
150
|
-
def _alias_used(bound: str) -> bool:
|
|
151
|
-
return used_names is None or bound in used_names
|
|
152
|
-
|
|
153
|
-
lines = []
|
|
154
|
-
for node in tree.body:
|
|
155
|
-
if isinstance(node, ast.Import):
|
|
156
|
-
kept = []
|
|
157
|
-
for alias in node.names:
|
|
158
|
-
top_pkg = alias.name.split(".")[0]
|
|
159
|
-
if _is_tracebloc(alias.name):
|
|
160
|
-
continue
|
|
161
|
-
bound = alias.asname or top_pkg
|
|
162
|
-
if _alias_used(bound):
|
|
163
|
-
kept.append(alias)
|
|
164
|
-
if kept:
|
|
165
|
-
lines.append(ast.unparse(ast.Import(names=kept)))
|
|
166
|
-
elif isinstance(node, ast.ImportFrom) and (node.level or 0) == 0:
|
|
167
|
-
if node.module and _is_tracebloc(node.module):
|
|
168
|
-
continue
|
|
169
|
-
kept = []
|
|
170
|
-
for alias in node.names:
|
|
171
|
-
# ``from x import *`` binds unknown names; keep it whenever the
|
|
172
|
-
# module is non-tracebloc rather than risk dropping a needed one.
|
|
173
|
-
if alias.name == "*":
|
|
174
|
-
kept.append(alias)
|
|
175
|
-
continue
|
|
176
|
-
bound = alias.asname or alias.name
|
|
177
|
-
if _alias_used(bound):
|
|
178
|
-
kept.append(alias)
|
|
179
|
-
if kept:
|
|
180
|
-
lines.append(
|
|
181
|
-
ast.unparse(
|
|
182
|
-
ast.ImportFrom(module=node.module, names=kept, level=0)
|
|
183
|
-
)
|
|
184
|
-
)
|
|
185
|
-
return "\n".join(line for line in lines if line).strip()
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
def _imported_bindings(import_src: str) -> set[str]:
|
|
189
|
-
"""Names bound by a block of import statements.
|
|
190
|
-
|
|
191
|
-
Returns the ``asname``, the imported name, or the top-level package for
|
|
192
|
-
each import. Used to tell whether a generated ``loss.py`` header already
|
|
193
|
-
provides a framework name (``torch`` / ``nn`` / ``F``) before
|
|
194
|
-
deciding to append the default framework import — so a recovered header
|
|
195
|
-
that keeps only, say, ``import math`` doesn't suppress the ``torch``
|
|
196
|
-
fallback the loss body still needs.
|
|
197
|
-
"""
|
|
198
|
-
import ast
|
|
199
|
-
|
|
200
|
-
try:
|
|
201
|
-
tree = ast.parse(import_src)
|
|
202
|
-
except SyntaxError:
|
|
203
|
-
return set()
|
|
204
|
-
bound: set[str] = set()
|
|
205
|
-
for node in ast.walk(tree):
|
|
206
|
-
if isinstance(node, ast.Import):
|
|
207
|
-
for alias in node.names:
|
|
208
|
-
bound.add(alias.asname or alias.name.split(".")[0])
|
|
209
|
-
elif isinstance(node, ast.ImportFrom):
|
|
210
|
-
for alias in node.names:
|
|
211
|
-
if alias.name != "*":
|
|
212
|
-
bound.add(alias.asname or alias.name)
|
|
213
|
-
return bound
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
# Single source of truth for standard-loss policy (#129). Keyed on
|
|
217
|
-
# ``(framework, category)`` → ``(default, allowed)``: the default a plan starts
|
|
218
|
-
# with (``LinkModelDataset.__init__``) and the losses the setter accepts
|
|
219
|
-
# (``loss_function()``). These used to be two ``if/elif`` cascades that nothing
|
|
220
|
-
# forced to agree — they drifted apart on #127. One row per category means they
|
|
221
|
-
# can't diverge; ``default in allowed`` is checked by the loss-policy matrix.
|
|
222
|
-
#
|
|
223
|
-
# A ``(framework, None)`` row is the framework's catch-all. Only PyTorch and
|
|
224
|
-
# sklearn have rows: lifelines / scikit-survival share PyTorch's policy exactly,
|
|
225
|
-
# so ``_resolve_loss_policy`` normalizes them to PyTorch.
|
|
226
|
-
|
|
227
|
-
# Cross-entropy is the only wired loss for these — token/sequence-level tasks
|
|
228
|
-
# and semantic segmentation (MSE/L1 crash against integer/Long targets).
|
|
229
|
-
_CROSSENTROPY_ONLY_CATEGORIES = (
|
|
230
|
-
TEXT_CLASSIFICATION,
|
|
231
|
-
TOKEN_CLASSIFICATION,
|
|
232
|
-
SENTENCE_PAIR_CLASSIFICATION,
|
|
233
|
-
MASKED_LANGUAGE_MODELING,
|
|
234
|
-
CAUSAL_LANGUAGE_MODELING,
|
|
235
|
-
SEQ2SEQ,
|
|
236
|
-
EMBEDDINGS,
|
|
237
|
-
TIME_SERIES_CLASSIFICATION,
|
|
238
|
-
SEMANTIC_SEGMENTATION,
|
|
67
|
+
from tracebloc.training.loss_source import ( # noqa: F401 (re-export, RFC-0348 A.5)
|
|
68
|
+
_referenced_names,
|
|
69
|
+
_is_tracebloc,
|
|
70
|
+
_imports_tracebloc,
|
|
71
|
+
_extract_top_level_imports,
|
|
72
|
+
_imported_bindings,
|
|
239
73
|
)
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
),
|
|
246
|
-
# Cox proportional-hazards across every survival framework; the PyTorch
|
|
247
|
-
# runtime hardcodes cox_ph_loss_torch and ignores the rest (#762 > #113).
|
|
248
|
-
(PYTORCH_FRAMEWORK, TIME_TO_EVENT_PREDICTION): ("coxph", ("coxph",)),
|
|
249
|
-
(PYTORCH_FRAMEWORK, TIME_SERIES_FORECASTING): ("mse", ("mse", "l1")),
|
|
250
|
-
# Multi-hot targets against the logits; the engine never reads a model's own loss.
|
|
251
|
-
(PYTORCH_FRAMEWORK, MULTI_LABEL_TEXT_CLASSIFICATION): (
|
|
252
|
-
"bcewithlogits",
|
|
253
|
-
("bcewithlogits",),
|
|
254
|
-
),
|
|
255
|
-
# One float target per text against the (batch, 1) logits.
|
|
256
|
-
(PYTORCH_FRAMEWORK, TEXT_REGRESSION): ("mse", ("mse", "l1")),
|
|
257
|
-
# Catch-all: image / keypoint / object-detection.
|
|
258
|
-
(PYTORCH_FRAMEWORK, None): ("mse", ("crossentropy", "mse", "l1")),
|
|
259
|
-
# sklearn's allowlist is category-independent (worker wires only MSE + binary
|
|
260
|
-
# cross-entropy); its default is framework-aware (mse), closing the #129 gap.
|
|
261
|
-
(SKLEARN_FRAMEWORK, None): ("mse", ("mse", "binarycrossentropy")),
|
|
262
|
-
}
|
|
263
|
-
_LOSS_POLICY.update(
|
|
264
|
-
{
|
|
265
|
-
(PYTORCH_FRAMEWORK, category): ("crossentropy", ("crossentropy",))
|
|
266
|
-
for category in _CROSSENTROPY_ONLY_CATEGORIES
|
|
267
|
-
}
|
|
74
|
+
from tracebloc.training.loss_policy import ( # noqa: F401 (re-export, RFC-0348 A.5)
|
|
75
|
+
_CROSSENTROPY_ONLY_CATEGORIES,
|
|
76
|
+
_LOSS_POLICY,
|
|
77
|
+
_resolve_loss_policy,
|
|
78
|
+
default_loss_for,
|
|
268
79
|
)
|
|
269
80
|
|
|
270
81
|
|
|
271
|
-
def _resolve_loss_policy(framework, category):
|
|
272
|
-
"""Return ``(default, allowed)`` for a ``(framework, category)`` pair.
|
|
273
|
-
|
|
274
|
-
Tries the specific row, then the framework's ``(framework, None)``
|
|
275
|
-
catch-all. lifelines / scikit-survival normalize to PyTorch (same policy).
|
|
276
|
-
"""
|
|
277
|
-
if framework in (LIFELINES_FRAMEWORK, SCIKIT_SURVIVAL_FRAMEWORK):
|
|
278
|
-
framework = PYTORCH_FRAMEWORK
|
|
279
|
-
if (framework, category) in _LOSS_POLICY:
|
|
280
|
-
return _LOSS_POLICY[(framework, category)]
|
|
281
|
-
if (framework, None) in _LOSS_POLICY:
|
|
282
|
-
return _LOSS_POLICY[(framework, None)]
|
|
283
|
-
raise KeyError(f"No loss policy for framework={framework!r}")
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
def default_loss_for(framework, category):
|
|
287
|
-
"""Standard loss assigned when the user sets no custom loss.
|
|
288
|
-
|
|
289
|
-
Reads the ``default`` half of :data:`_LOSS_POLICY` — the same table the
|
|
290
|
-
setter's allowlist comes from, so a plan can't start at a rejected default.
|
|
291
|
-
"""
|
|
292
|
-
default, _ = _resolve_loss_policy(framework, category)
|
|
293
|
-
return {TYPE: STANDARD, VALUE: default}
|
|
294
|
-
|
|
295
|
-
|
|
296
82
|
class LossFunctionConfig(_FacadeCoordinator):
|
|
297
83
|
"""Link-time loss-function coordinator for :class:`LinkModelDataset`.
|
|
298
84
|
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"""The standard-loss policy table (RFC-0348 A.5).
|
|
2
|
+
|
|
3
|
+
Moved verbatim from :mod:`tracebloc.training.loss`, which re-exports every
|
|
4
|
+
name. One row per ``(framework, category)`` gives the default loss a plan
|
|
5
|
+
starts with and the losses ``loss_function()`` accepts.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from tracebloc.utils.constants import (
|
|
11
|
+
STANDARD,
|
|
12
|
+
TYPE,
|
|
13
|
+
VALUE,
|
|
14
|
+
TABULAR_CLASSIFICATION,
|
|
15
|
+
TEXT_CLASSIFICATION,
|
|
16
|
+
TOKEN_CLASSIFICATION,
|
|
17
|
+
SENTENCE_PAIR_CLASSIFICATION,
|
|
18
|
+
MULTI_LABEL_TEXT_CLASSIFICATION,
|
|
19
|
+
TEXT_REGRESSION,
|
|
20
|
+
MASKED_LANGUAGE_MODELING,
|
|
21
|
+
CAUSAL_LANGUAGE_MODELING,
|
|
22
|
+
SEQ2SEQ,
|
|
23
|
+
EMBEDDINGS,
|
|
24
|
+
TIME_TO_EVENT_PREDICTION,
|
|
25
|
+
SKLEARN_FRAMEWORK,
|
|
26
|
+
PYTORCH_FRAMEWORK,
|
|
27
|
+
LIFELINES_FRAMEWORK,
|
|
28
|
+
SCIKIT_SURVIVAL_FRAMEWORK,
|
|
29
|
+
SEMANTIC_SEGMENTATION,
|
|
30
|
+
TIME_SERIES_FORECASTING,
|
|
31
|
+
TIME_SERIES_CLASSIFICATION,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# Single source of truth for standard-loss policy (#129). Keyed on
|
|
36
|
+
# ``(framework, category)`` → ``(default, allowed)``: the default a plan starts
|
|
37
|
+
# with (``LinkModelDataset.__init__``) and the losses the setter accepts
|
|
38
|
+
# (``loss_function()``). These used to be two ``if/elif`` cascades that nothing
|
|
39
|
+
# forced to agree — they drifted apart on #127. One row per category means they
|
|
40
|
+
# can't diverge; ``default in allowed`` is checked by the loss-policy matrix.
|
|
41
|
+
#
|
|
42
|
+
# A ``(framework, None)`` row is the framework's catch-all. Only PyTorch and
|
|
43
|
+
# sklearn have rows: lifelines / scikit-survival share PyTorch's policy exactly,
|
|
44
|
+
# so ``_resolve_loss_policy`` normalizes them to PyTorch.
|
|
45
|
+
|
|
46
|
+
# Cross-entropy is the only wired loss for these — token/sequence-level tasks
|
|
47
|
+
# and semantic segmentation (MSE/L1 crash against integer/Long targets).
|
|
48
|
+
_CROSSENTROPY_ONLY_CATEGORIES = (
|
|
49
|
+
TEXT_CLASSIFICATION,
|
|
50
|
+
TOKEN_CLASSIFICATION,
|
|
51
|
+
SENTENCE_PAIR_CLASSIFICATION,
|
|
52
|
+
MASKED_LANGUAGE_MODELING,
|
|
53
|
+
CAUSAL_LANGUAGE_MODELING,
|
|
54
|
+
SEQ2SEQ,
|
|
55
|
+
EMBEDDINGS,
|
|
56
|
+
TIME_SERIES_CLASSIFICATION,
|
|
57
|
+
SEMANTIC_SEGMENTATION,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
_LOSS_POLICY = {
|
|
61
|
+
(PYTORCH_FRAMEWORK, TABULAR_CLASSIFICATION): (
|
|
62
|
+
"crossentropy",
|
|
63
|
+
("mse", "crossentropy", "binarycrossentropy"),
|
|
64
|
+
),
|
|
65
|
+
# Cox proportional-hazards across every survival framework; the PyTorch
|
|
66
|
+
# runtime hardcodes cox_ph_loss_torch and ignores the rest (#762 > #113).
|
|
67
|
+
(PYTORCH_FRAMEWORK, TIME_TO_EVENT_PREDICTION): ("coxph", ("coxph",)),
|
|
68
|
+
(PYTORCH_FRAMEWORK, TIME_SERIES_FORECASTING): ("mse", ("mse", "l1")),
|
|
69
|
+
# Multi-hot targets against the logits; the engine never reads a model's own loss.
|
|
70
|
+
(PYTORCH_FRAMEWORK, MULTI_LABEL_TEXT_CLASSIFICATION): (
|
|
71
|
+
"bcewithlogits",
|
|
72
|
+
("bcewithlogits",),
|
|
73
|
+
),
|
|
74
|
+
# One float target per text against the (batch, 1) logits.
|
|
75
|
+
(PYTORCH_FRAMEWORK, TEXT_REGRESSION): ("mse", ("mse", "l1")),
|
|
76
|
+
# Catch-all: image / keypoint / object-detection.
|
|
77
|
+
(PYTORCH_FRAMEWORK, None): ("mse", ("crossentropy", "mse", "l1")),
|
|
78
|
+
# sklearn's allowlist is category-independent (worker wires only MSE + binary
|
|
79
|
+
# cross-entropy); its default is framework-aware (mse), closing the #129 gap.
|
|
80
|
+
(SKLEARN_FRAMEWORK, None): ("mse", ("mse", "binarycrossentropy")),
|
|
81
|
+
}
|
|
82
|
+
_LOSS_POLICY.update(
|
|
83
|
+
{
|
|
84
|
+
(PYTORCH_FRAMEWORK, category): ("crossentropy", ("crossentropy",))
|
|
85
|
+
for category in _CROSSENTROPY_ONLY_CATEGORIES
|
|
86
|
+
}
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _resolve_loss_policy(framework, category):
|
|
91
|
+
"""Return ``(default, allowed)`` for a ``(framework, category)`` pair.
|
|
92
|
+
|
|
93
|
+
Tries the specific row, then the framework's ``(framework, None)``
|
|
94
|
+
catch-all. lifelines / scikit-survival normalize to PyTorch (same policy).
|
|
95
|
+
"""
|
|
96
|
+
if framework in (LIFELINES_FRAMEWORK, SCIKIT_SURVIVAL_FRAMEWORK):
|
|
97
|
+
framework = PYTORCH_FRAMEWORK
|
|
98
|
+
if (framework, category) in _LOSS_POLICY:
|
|
99
|
+
return _LOSS_POLICY[(framework, category)]
|
|
100
|
+
if (framework, None) in _LOSS_POLICY:
|
|
101
|
+
return _LOSS_POLICY[(framework, None)]
|
|
102
|
+
raise KeyError(f"No loss policy for framework={framework!r}")
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def default_loss_for(framework, category):
|
|
106
|
+
"""Standard loss assigned when the user sets no custom loss.
|
|
107
|
+
|
|
108
|
+
Reads the ``default`` half of :data:`_LOSS_POLICY` — the same table the
|
|
109
|
+
setter's allowlist comes from, so a plan can't start at a rejected default.
|
|
110
|
+
"""
|
|
111
|
+
default, _ = _resolve_loss_policy(framework, category)
|
|
112
|
+
return {TYPE: STANDARD, VALUE: default}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""Import surgery for a serialized custom loss (RFC-0348 A.5).
|
|
2
|
+
|
|
3
|
+
Moved verbatim from :mod:`tracebloc.training.loss`, which re-exports every
|
|
4
|
+
name. :class:`~tracebloc.training.loss.LossFunctionConfig` uses these to make
|
|
5
|
+
a user's ``loss.py`` self-contained before it ships to the training edge:
|
|
6
|
+
which names the loss body references, which of the defining module's
|
|
7
|
+
top-level imports it needs, and whether it imports ``tracebloc`` anywhere.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def _referenced_names(src: str) -> set[str]:
|
|
14
|
+
"""Return every bare name referenced in ``src`` (an AST ``Name`` id).
|
|
15
|
+
|
|
16
|
+
Used to decide which of the defining module's top-level imports a custom
|
|
17
|
+
loss actually relies on. Attribute access (``torch.nn.functional``) roots
|
|
18
|
+
at a ``Name`` node (``torch``), so collecting all ``Name`` ids captures the
|
|
19
|
+
binding each reference needs without having to model scopes.
|
|
20
|
+
"""
|
|
21
|
+
import ast
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
tree = ast.parse(src)
|
|
25
|
+
except SyntaxError:
|
|
26
|
+
return set()
|
|
27
|
+
return {node.id for node in ast.walk(tree) if isinstance(node, ast.Name)}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def _is_tracebloc(name: str) -> bool:
|
|
31
|
+
"""True for ``tracebloc`` and its submodules (``tracebloc.x``)."""
|
|
32
|
+
return name == "tracebloc" or name.startswith("tracebloc.")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _imports_tracebloc(src: str) -> bool:
|
|
36
|
+
"""True if ``src`` imports ``tracebloc`` *anywhere* — top-level OR inside a
|
|
37
|
+
function/class body.
|
|
38
|
+
|
|
39
|
+
A custom loss runs on the training edge, which has the tracebloc *client*
|
|
40
|
+
but not the SDK package, so any ``import tracebloc`` in the loss aborts
|
|
41
|
+
training with ``ModuleNotFoundError: No module named 'tracebloc'``. Top-level
|
|
42
|
+
import filtering (:func:`_extract_top_level_imports`) only drops imports
|
|
43
|
+
*carried over* from the defining module's header; an import written inside
|
|
44
|
+
the loss body is part of the serialized source and survives. Walk the whole
|
|
45
|
+
AST so a body-level ``import tracebloc`` is caught and the upload is rejected
|
|
46
|
+
here rather than failing mid-run on the edge.
|
|
47
|
+
"""
|
|
48
|
+
import ast
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
tree = ast.parse(src)
|
|
52
|
+
except SyntaxError:
|
|
53
|
+
return False
|
|
54
|
+
for node in ast.walk(tree):
|
|
55
|
+
if isinstance(node, ast.Import):
|
|
56
|
+
if any(_is_tracebloc(a.name) for a in node.names):
|
|
57
|
+
return True
|
|
58
|
+
elif isinstance(node, ast.ImportFrom):
|
|
59
|
+
# level>0 is a relative import (no module name to match); skip.
|
|
60
|
+
if node.module and _is_tracebloc(node.module):
|
|
61
|
+
return True
|
|
62
|
+
return False
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _extract_top_level_imports(module_src: str, used_names=None) -> str:
|
|
66
|
+
"""Return a module's top-level *absolute* imports needed by a custom loss.
|
|
67
|
+
|
|
68
|
+
Used to make a serialized custom-loss ``loss.py`` self-contained.
|
|
69
|
+
|
|
70
|
+
- Relative imports (``from .pkg import x``) are skipped: the client loads
|
|
71
|
+
``loss.py`` as a top-level module, where relative imports cannot resolve
|
|
72
|
+
and would raise ``ImportError`` — copying them only guarantees a runtime
|
|
73
|
+
failure.
|
|
74
|
+
- ``tracebloc`` imports are *always* dropped: the SDK is the upload-side
|
|
75
|
+
client and is never present on the training edge, so a carried-over
|
|
76
|
+
``from tracebloc import User`` aborts training with ``ModuleNotFoundError``
|
|
77
|
+
(the smoke-train passes in-process where tracebloc *is* importable, so it
|
|
78
|
+
only surfaces on the edge).
|
|
79
|
+
- When ``used_names`` is given (the set of names the loss body references),
|
|
80
|
+
an import is kept only if it binds a name the loss actually uses. The
|
|
81
|
+
common case — defining the loss in the same script that does
|
|
82
|
+
``from tracebloc import User`` to upload — therefore drops the tracebloc,
|
|
83
|
+
``os`` and other unrelated imports while keeping the framework imports the
|
|
84
|
+
loss relies on. ``used_names=None`` keeps every non-tracebloc absolute
|
|
85
|
+
import (best-effort, when the loss body could not be parsed).
|
|
86
|
+
"""
|
|
87
|
+
import ast
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
tree = ast.parse(module_src)
|
|
91
|
+
except SyntaxError:
|
|
92
|
+
return ""
|
|
93
|
+
|
|
94
|
+
def _alias_used(bound: str) -> bool:
|
|
95
|
+
return used_names is None or bound in used_names
|
|
96
|
+
|
|
97
|
+
lines = []
|
|
98
|
+
for node in tree.body:
|
|
99
|
+
if isinstance(node, ast.Import):
|
|
100
|
+
kept = []
|
|
101
|
+
for alias in node.names:
|
|
102
|
+
top_pkg = alias.name.split(".")[0]
|
|
103
|
+
if _is_tracebloc(alias.name):
|
|
104
|
+
continue
|
|
105
|
+
bound = alias.asname or top_pkg
|
|
106
|
+
if _alias_used(bound):
|
|
107
|
+
kept.append(alias)
|
|
108
|
+
if kept:
|
|
109
|
+
lines.append(ast.unparse(ast.Import(names=kept)))
|
|
110
|
+
elif isinstance(node, ast.ImportFrom) and (node.level or 0) == 0:
|
|
111
|
+
if node.module and _is_tracebloc(node.module):
|
|
112
|
+
continue
|
|
113
|
+
kept = []
|
|
114
|
+
for alias in node.names:
|
|
115
|
+
# ``from x import *`` binds unknown names; keep it whenever the
|
|
116
|
+
# module is non-tracebloc rather than risk dropping a needed one.
|
|
117
|
+
if alias.name == "*":
|
|
118
|
+
kept.append(alias)
|
|
119
|
+
continue
|
|
120
|
+
bound = alias.asname or alias.name
|
|
121
|
+
if _alias_used(bound):
|
|
122
|
+
kept.append(alias)
|
|
123
|
+
if kept:
|
|
124
|
+
lines.append(
|
|
125
|
+
ast.unparse(
|
|
126
|
+
ast.ImportFrom(module=node.module, names=kept, level=0)
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
return "\n".join(line for line in lines if line).strip()
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _imported_bindings(import_src: str) -> set[str]:
|
|
133
|
+
"""Names bound by a block of import statements.
|
|
134
|
+
|
|
135
|
+
Returns the ``asname``, the imported name, or the top-level package for
|
|
136
|
+
each import. Used to tell whether a generated ``loss.py`` header already
|
|
137
|
+
provides a framework name (``torch`` / ``nn`` / ``F``) before
|
|
138
|
+
deciding to append the default framework import — so a recovered header
|
|
139
|
+
that keeps only, say, ``import math`` doesn't suppress the ``torch``
|
|
140
|
+
fallback the loss body still needs.
|
|
141
|
+
"""
|
|
142
|
+
import ast
|
|
143
|
+
|
|
144
|
+
try:
|
|
145
|
+
tree = ast.parse(import_src)
|
|
146
|
+
except SyntaxError:
|
|
147
|
+
return set()
|
|
148
|
+
bound: set[str] = set()
|
|
149
|
+
for node in ast.walk(tree):
|
|
150
|
+
if isinstance(node, ast.Import):
|
|
151
|
+
for alias in node.names:
|
|
152
|
+
bound.add(alias.asname or alias.name.split(".")[0])
|
|
153
|
+
elif isinstance(node, ast.ImportFrom):
|
|
154
|
+
for alias in node.names:
|
|
155
|
+
if alias.name != "*":
|
|
156
|
+
bound.add(alias.asname or alias.name)
|
|
157
|
+
return bound
|