code-loader 1.0.205.dev2__py3-none-any.whl → 1.0.206.dev1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -86,8 +86,6 @@ class DatasetSetup:
86
86
  custom_losses: List[CustomLossInstance]
87
87
  metrics: List[MetricInstance] = field(default_factory=list)
88
88
  simulations: List[SimulationInstance] = field(default_factory=list)
89
- # Structural: the integration registered an element-instance mask encoder.
90
- has_element_instances: bool = False
91
89
 
92
90
 
93
91
  @dataclass
@@ -2981,11 +2981,49 @@ def tensorleap_simulation(name: str, sim_params: dict):
2981
2981
 
2982
2982
 
2983
2983
  def tensorleap_element_instance_preprocess(
2984
- instance_length_encoder: InstanceLengthCallableInterface, instance_mask_encoder: InstanceCallableInterface):
2984
+ instance_length_encoder: InstanceLengthCallableInterface,
2985
+ instance_mask_encoder: InstanceCallableInterface,
2986
+ instance_metadata_types: Optional[Dict[str, DatasetMetadataType]] = None):
2985
2987
  def decorating_function(user_function: Callable[[], List[PreprocessResponse]]):
2988
+ def register_instance_extra_metadata(metadata_types: Dict[str, DatasetMetadataType]) -> None:
2989
+ # Idempotent: set_metadata appends without deduping, and the probe path runs inside
2990
+ # preprocess, so a second preprocess call would register a duplicate handler.
2991
+ if any(handler.name == "builtin_instance_extra_metadata"
2992
+ for handler in leap_binder.setup_container.metadata):
2993
+ return
2994
+ names = list(metadata_types)
2995
+
2996
+ def builtin_instance_extra_metadata(idx: str, preprocess: PreprocessResponse) -> Dict[str, None]:
2997
+ # Sample rows declare the columns without claiming values; the engine injects the
2998
+ # real per-instance ones. A fresh dict, because nulling the probed
2999
+ # ElementInstance's own dict in place destroyed any encoder that returned a
3000
+ # reference into preprocess.data.
3001
+ return {name: None for name in names}
3002
+
3003
+ leap_binder.set_metadata(builtin_instance_extra_metadata,
3004
+ "builtin_instance_extra_metadata", metadata_types)
3005
+
3006
+ def probe_instance_metadata_types(sample_id: Union[int, str], preprocess_response: PreprocessResponse,
3007
+ idx: int) -> Optional[Dict[str, DatasetMetadataType]]:
3008
+ # Fallback when the types are not declared: infer them from one probed instance. A
3009
+ # None there carries no type, so name the fields and point at the declaration.
3010
+ element_instance = instance_mask_encoder(sample_id, preprocess_response, idx)
3011
+ element_instance_metadata = getattr(element_instance, 'instance_metadata', None)
3012
+ if element_instance_metadata is None:
3013
+ return None
3014
+ not_inferable = [name for name, value in element_instance_metadata.items() if value is None]
3015
+ if not_inferable:
3016
+ raise Exception(
3017
+ f"tensorleap_element_instance_preprocess validation failed: cannot infer the "
3018
+ f"type of instance metadata {not_inferable} from instance {idx} of sample "
3019
+ f"{sample_id!r}, because it is None on that instance. The type cannot come from "
3020
+ f"the value, so declare it: tensorleap_element_instance_preprocess(..., "
3021
+ f"instance_metadata_types={{'{not_inferable[0]}': DatasetMetadataType.float}}).")
3022
+ return map_dict_to_metadata_types(element_instance_metadata)
3023
+
2986
3024
  def user_function_instance() -> List[PreprocessResponse]:
2987
3025
  result = user_function()
2988
- found_instance_metadata = False
3026
+ found_instance_metadata = instance_metadata_types is not None
2989
3027
  for preprocess_response in result:
2990
3028
  if preprocess_response.is_grouped:
2991
3029
  raise Exception(
@@ -3009,15 +3047,10 @@ def tensorleap_element_instance_preprocess(
3009
3047
  # "Index <id> with sample_id: <id> cannot be found!".
3010
3048
  for idx, instance_id in enumerate(instances_ids):
3011
3049
  if not found_instance_metadata:
3012
- element_instance = instance_mask_encoder(sample_id, preprocess_response, idx)
3013
- element_instance_metadata = element_instance.instance_metadata
3014
- if element_instance_metadata is not None:
3015
- element_instance_metadata_types = map_dict_to_metadata_types(element_instance_metadata)
3016
- def builtin_instance_extra_metadata(idx: str, preprocess: PreprocessResponse) -> Dict[str, str]:
3017
- for k, v in element_instance_metadata.items():
3018
- element_instance_metadata[k] = None
3019
- return element_instance_metadata
3020
- leap_binder.set_metadata(builtin_instance_extra_metadata,"builtin_instance_extra_metadata", element_instance_metadata_types)
3050
+ probed_types = probe_instance_metadata_types(
3051
+ sample_id, preprocess_response, idx)
3052
+ if probed_types is not None:
3053
+ register_instance_extra_metadata(probed_types)
3021
3054
  found_instance_metadata = True
3022
3055
 
3023
3056
  instance_to_sample_ids_mappings[instance_id] = sample_id
@@ -3033,6 +3066,8 @@ def tensorleap_element_instance_preprocess(
3033
3066
 
3034
3067
  leap_binder.set_preprocess(user_function_instance)
3035
3068
  leap_binder.set_metadata(builtin_instance_metadata, "builtin_instance_metadata")
3069
+ if instance_metadata_types is not None:
3070
+ register_instance_extra_metadata(instance_metadata_types)
3036
3071
 
3037
3072
  def _validate_input_args(*args, **kwargs):
3038
3073
  assert len(args) == 0 and len(kwargs) == 0, \
code_loader/leaploader.py CHANGED
@@ -935,23 +935,7 @@ class LeapLoader(LeapLoaderBase):
935
935
 
936
936
  return DatasetSetup(preprocess=dataset_preprocess, inputs=inputs, outputs=ground_truths,
937
937
  metadata=metadata_instances, visualizers=visualizers, prediction_types=prediction_types,
938
- custom_losses=custom_losses, metrics=metrics, simulations=simulations,
939
- has_element_instances=self._has_element_instances())
940
-
941
- def _has_element_instances(self) -> bool:
942
- """Does this dataset have element instances? Both halves, because either alone lies.
943
-
944
- A registered mask encoder without instance mappings is an integration that declares
945
- instances and produces none: the engine would take the pooling path with nothing to pool,
946
- and ask the UI to visualize an instance population that does not exist. Mappings without an
947
- encoder cannot be masked. Preprocessing has already run by the time this is called (the
948
- lengths above come from it), so reading the mappings costs nothing extra.
949
- """
950
- setup = global_leap_binder.setup_container
951
- if not setup.instance_masks:
952
- return False
953
- return any(response.instance_to_sample_ids_mappings
954
- for response in self._preprocess_result().values())
938
+ custom_losses=custom_losses, metrics=metrics, simulations=simulations)
955
939
 
956
940
  def get_model_setup_response(self) -> ModelSetup:
957
941
  setup = global_leap_binder.setup_container
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.205.dev2
3
+ Version: 1.0.206.dev1
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -5,7 +5,7 @@ code_loader/contract/datasetclasses.py,sha256=ySmO5Ld4fyfUWOJxUdnH2qCMota4dtwtgM
5
5
  code_loader/contract/enums.py,sha256=__GkPkwAXi2agmDGtEQgbMucPm4-n80maG6n_MmObPA,1691
6
6
  code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
7
7
  code_loader/contract/mapping.py,sha256=sWJhpng-IkOzQnWQdMT5w2ZZ3X1Z_OOzSwCLXIS7oxE,1446
8
- code_loader/contract/responsedataclasses.py,sha256=2SQCccuIlSeUJT0igyvIJRYtmaWSqqlQwtaAA1iEuSI,5044
8
+ code_loader/contract/responsedataclasses.py,sha256=5VFgGjRubMW8ItMPils3rkBNejunCGLaa192AIi-xko,4925
9
9
  code_loader/contract/sim_config.py,sha256=le8KMALZiP0WU4UcuKnTOSWBW2rNjpnWYfII502NqDM,3493
10
10
  code_loader/contract/visualizer_classes.py,sha256=vzX9YcwxKOm3IpYj8OaqsA1odPlRgj2Cfvglwd88Wbw,18213
11
11
  code_loader/default_losses.py,sha256=NoOQym1106bDN5dcIk56Elr7ZG5quUHArqfP5-Nyxyo,1139
@@ -22,8 +22,8 @@ code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZ
22
22
  code_loader/experiment_api/workingspace_config_utils.py,sha256=DLzXQCg4dgTV_YgaSbeTVzq-2ja_SQw4zi7LXwKL9cY,990
23
23
  code_loader/inner_leap_binder/__init__.py,sha256=koOlJyMNYzGbEsoIbXathSmQ-L38N_pEXH_HvL7beXU,99
24
24
  code_loader/inner_leap_binder/leapbinder.py,sha256=mWcjx31fnrtRfV5agveW79lcMGJhwhDfLz7brpexBv0,60408
25
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=qmFozDAWYWtQwNcAkyb9zs0gCh7nS6ZJNFAaIEFX4J8,193104
26
- code_loader/leaploader.py,sha256=Ksm0ASezQ9t9dQzKR0iGVkwD_6mSpEgSCc3rgZEMP5Y,92254
25
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=lM2wFqzxdTVoe9lwC5YFdgnY8UwvY5r9foDnKJpQ7Mc,195252
26
+ code_loader/leaploader.py,sha256=JjC5ljuofrtUP4qMh2KzRQLrIWvSTpR8ep6om92c3qc,91308
27
27
  code_loader/leaploaderbase.py,sha256=Aa8wCcxojf8EBn_14W5I1gKI4OMBdpdEcNAZ_6E2eV4,10940
28
28
  code_loader/mixpanel_tracker.py,sha256=rNwRmFifNbdUoqLQvvhhgpKczWpWiEmd8MfyJe27sxw,9131
29
29
  code_loader/plot_functions/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -32,7 +32,7 @@ code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6Lz
32
32
  code_loader/utils.py,sha256=mlwr-4ZeeEMMIRdMAL7JF0b-5ko7QSRhbKZ64DqKbTY,11452
33
33
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  code_loader/visualizers/default_visualizers.py,sha256=grTPin_lCE9aci8i8CqA7DqQwAyXRB7_EamA3na_pls,5438
35
- code_loader-1.0.205.dev2.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
- code_loader-1.0.205.dev2.dist-info/METADATA,sha256=absRO9KyVArGALeMt_X5LtJZ-jnT3B5OnJuVy6eM5uY,1095
37
- code_loader-1.0.205.dev2.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- code_loader-1.0.205.dev2.dist-info/RECORD,,
35
+ code_loader-1.0.206.dev1.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
+ code_loader-1.0.206.dev1.dist-info/METADATA,sha256=v7DbX7F0l3-_L0R5gieoiNSAff1YAA9dqnJ9ncCD2yE,1095
37
+ code_loader-1.0.206.dev1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
38
+ code_loader-1.0.206.dev1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.9.0
2
+ Generator: poetry-core 1.9.1
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any