code-loader 1.0.208.dev7__py3-none-any.whl → 1.0.208.dev8__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.
@@ -85,11 +85,6 @@ def _reject_stringized_sample_preprocess_response(function: Callable[..., Any],
85
85
  "This breaks Tensorleap type detection, so it must be referenced as a real type.")
86
86
 
87
87
 
88
- def _reject_stringized_preprocess_response(function: Callable[..., Any], arg_name: str, annotation: Any) -> None:
89
- _reject_stringized_annotation(
90
- function, arg_name, annotation, PreprocessResponse,
91
- "Tensorleap uses that annotation to tell a dataset-computed custom latent space from a "
92
- "model-computed one, so it must be a real type.")
93
88
 
94
89
 
95
90
 
@@ -7,6 +7,7 @@ import warnings
7
7
  import logging
8
8
  from collections import defaultdict
9
9
  import functools
10
+ import typing
10
11
  from functools import lru_cache
11
12
  from pathlib import Path
12
13
  from typing import Optional, Union, Callable, List, Dict, Set, Any
@@ -36,7 +37,7 @@ from code_loader.contract.visualizer_classes import LeapImage, LeapImageMask, Le
36
37
  LeapHorizontalBar, LeapImageWithBBox, LeapImageWithHeatmap, LeapVideo, LeapAudio, LeapValidationError, \
37
38
  map_leap_data_type_to_visualizer_class
38
39
  from code_loader.inner_leap_binder.leapbinder import mapping_runtime_mode_env_var_mame, \
39
- _reject_stringized_preprocess_response, _reject_stringized_sample_preprocess_response
40
+ _reject_stringized_sample_preprocess_response
40
41
  from code_loader.mixpanel_tracker import clear_integration_events, AnalyticsEvent, emit_integration_event_once
41
42
 
42
43
  _called_from_inside_tl_decorator = 0
@@ -1751,15 +1752,32 @@ def tensorleap_metadata(
1751
1752
  return decorating_function
1752
1753
 
1753
1754
 
1755
+ def _is_preprocess_response_type(annotation: Any) -> bool:
1756
+ if isinstance(annotation, type):
1757
+ return issubclass(annotation, PreprocessResponse)
1758
+ return any(_is_preprocess_response_type(arg) for arg in get_args(annotation))
1759
+
1760
+
1754
1761
  def _classify_custom_latent_space_signature(user_function) -> str:
1755
- argspec = inspect.getfullargspec(user_function)
1756
- params = argspec.args
1757
- if len(params) != 2:
1758
- return 'model'
1762
+ """Dataset-computed when a parameter is typed PreprocessResponse (a subclass or an
1763
+ Optional[...] of it included), model-computed otherwise."""
1764
+ params = list(inspect.signature(user_function).parameters.values())
1765
+ hints = typing.get_type_hints(user_function)
1766
+ preprocess_params = [p.name for p in params if _is_preprocess_response_type(hints.get(p.name))]
1767
+ if preprocess_params:
1768
+ positional = [p.name for p in params
1769
+ if p.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD)]
1770
+ if positional[1:2] != preprocess_params[:1] or len(preprocess_params) > 1:
1771
+ raise Exception(
1772
+ f"tensorleap_custom_latent_space validation failed: '{user_function.__name__}' is "
1773
+ f"dataset-computed (it takes a PreprocessResponse), so it is called as "
1774
+ f"{user_function.__name__}(sample_id, preprocess) and its PreprocessResponse must be "
1775
+ f"the second positional parameter, and the only one. Got parameters "
1776
+ f"{[p.name for p in params]} with PreprocessResponse on {preprocess_params}.")
1777
+ return 'dataset'
1759
1778
 
1760
- second = params[1]
1761
- first = params[0]
1762
- if second not in argspec.annotations:
1779
+ if len(params) == 2 and params[1].name not in hints:
1780
+ first, second = params[0].name, params[1].name
1763
1781
  raise Exception(
1764
1782
  f"tensorleap_custom_latent_space validation failed: '{user_function.__name__}' has "
1765
1783
  f"exactly two parameters ('{first}', '{second}') and '{second}' has no type "
@@ -1771,11 +1789,6 @@ def _classify_custom_latent_space_signature(user_function) -> str:
1771
1789
  f"If you are upgrading an existing project, this signature used to be accepted "
1772
1790
  f"unannotated as dataset-computed; add ': PreprocessResponse' to '{second}' to keep "
1773
1791
  f"the previous behavior.")
1774
-
1775
- annotation = argspec.annotations[second]
1776
- _reject_stringized_preprocess_response(user_function, second, annotation)
1777
- if annotation is PreprocessResponse:
1778
- return 'dataset'
1779
1792
  return 'model'
1780
1793
 
1781
1794
 
code_loader/leaploader.py CHANGED
@@ -55,8 +55,6 @@ class LeapLoader(LeapLoaderBase):
55
55
  self._preprocess_result_cached = None
56
56
  self._synthetic_lookup: Dict[str, Tuple[PreprocessResponse, Any]] = {}
57
57
  self._synthetic_populator: Optional[Callable[[str], None]] = None
58
- # Dataset-computed custom LS the engine dropped for this job; get_sample stops computing them.
59
- self._skipped_custom_latent_spaces: FrozenSet[str] = frozenset()
60
58
 
61
59
  try:
62
60
  from code_loader.mixpanel_tracker import track_code_loader_loaded
@@ -1208,10 +1206,17 @@ class LeapLoader(LeapLoaderBase):
1208
1206
  if any(handler.instance_aware for handler in latent_handlers.values()):
1209
1207
  raise Exception(
1210
1208
  "instance-aware custom latent spaces are not supported with grouped preprocess responses")
1209
+ # TODO: support model-computed custom latent spaces on grouped datasets (skip them here,
1210
+ # as the per-sample path does, once the grouped metrics path is verified to compute them).
1211
+ model_ls_names = [name for name, handler in latent_handlers.items()
1212
+ if handler.computed_at == CustomLatentSpaceComputedAt.MODEL]
1213
+ if model_ls_names:
1214
+ raise Exception(
1215
+ f"model-computed custom latent spaces {model_ls_names} are not supported with "
1216
+ f"grouped preprocess responses yet")
1211
1217
  custom_latent_spaces = {
1212
1218
  name: self._to_grouped_list(handler.function(group_ids, preprocess_state))
1213
1219
  for name, handler in latent_handlers.items()
1214
- if name not in self._skipped_custom_latent_spaces
1215
1220
  }
1216
1221
 
1217
1222
  return DatasetSample(inputs=inputs, gt=gt, metadata=metadata, metadata_is_none=metadata_is_none,
@@ -1435,8 +1440,7 @@ class LeapLoader(LeapLoaderBase):
1435
1440
  instance_id: Optional[int] = None) -> Optional[Dict[str, npt.NDArray[np.float32]]]:
1436
1441
  handlers = {handler_name: handler for handler_name, handler
1437
1442
  in global_leap_binder.setup_container.custom_latent_spaces.items()
1438
- if handler.computed_at != CustomLatentSpaceComputedAt.MODEL
1439
- and handler_name not in self._skipped_custom_latent_spaces}
1443
+ if handler.computed_at != CustomLatentSpaceComputedAt.MODEL}
1440
1444
  if not handlers:
1441
1445
  return None
1442
1446
  if preprocess.is_grouped:
@@ -1463,10 +1467,6 @@ class LeapLoader(LeapLoaderBase):
1463
1467
  self.exec_script()
1464
1468
  return len(global_leap_binder.setup_container.custom_latent_spaces) > 0
1465
1469
 
1466
- def set_skipped_custom_latent_spaces(self, names: Iterable[str]) -> None:
1467
- """Stop computing these dataset-computed custom latent spaces in get_sample(s)."""
1468
- self._skipped_custom_latent_spaces = frozenset(names)
1469
-
1470
1470
  @lru_cache()
1471
1471
  def get_custom_latent_space_names(self) -> Tuple[str, ...]:
1472
1472
  """Names of all registered custom latent spaces, in registration order.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.208.dev7
3
+ Version: 1.0.208.dev8
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -21,9 +21,9 @@ code_loader/experiment_api/types.py,sha256=MY8xFARHwdVA7p4dxyhD60ShmttgTvb4qdp1o
21
21
  code_loader/experiment_api/utils.py,sha256=XZHtxge12TS4H4-8PjV3sKuhp8Ud6ojAiIzTZJEqBqc,3304
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
- code_loader/inner_leap_binder/leapbinder.py,sha256=SYj8j1ptJ-CD979fVpcyQxzBan3jiKSRP1JYLNVx20E,63148
25
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=wHPiXA-PsR0QODYndPvLTLDzgvqxPO0XQUnQFJNysTM,209819
26
- code_loader/leaploader.py,sha256=aWfqSBDuJxyQWbV_x98mjtoOun0alM-0Ah1YhN6i0pE,97509
24
+ code_loader/inner_leap_binder/leapbinder.py,sha256=fplNN3TfJHg79YpEPHKK3b6CxrR7W0ugDeHhAZfYty0,62784
25
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=paUtnncLn-4iFUJhqEOg3rPtKh9DoS3_HVgGUgOz8c4,210906
26
+ code_loader/leaploader.py,sha256=DiVCs076JP21HXBfpKkzs3Qaumg8Cz26q1tIc4C-kcg,97552
27
27
  code_loader/leaploaderbase.py,sha256=JzgpEfY-kNUWbWUb_cZ1G1zHo6oSci6QhT7hqw3E1Jg,12371
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=v6VraCdbFADoNwNx5TH89BLnZ6yfPoWMkyJrqQ_usFc,12377
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.208.dev7.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
- code_loader-1.0.208.dev7.dist-info/METADATA,sha256=6EV16u91cLdng6Gqt1Tzk68IX8lehp4ovlJSlzg5pYA,1095
37
- code_loader-1.0.208.dev7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- code_loader-1.0.208.dev7.dist-info/RECORD,,
35
+ code_loader-1.0.208.dev8.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
+ code_loader-1.0.208.dev8.dist-info/METADATA,sha256=Zv4Z5dCnspuqPU778nnj7nEOkmHqIhxBg44L_ZwRIUw,1095
37
+ code_loader-1.0.208.dev8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
+ code_loader-1.0.208.dev8.dist-info/RECORD,,