code-loader 1.0.208.dev4__py3-none-any.whl → 1.0.208.dev6__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.
- code_loader/contract/datasetclasses.py +2 -2
- code_loader/contract/enums.py +5 -0
- code_loader/inner_leap_binder/leapbinder.py +2 -2
- code_loader/inner_leap_binder/leapbinder_decorators.py +67 -16
- code_loader/leaploader.py +21 -19
- code_loader/leaploaderbase.py +2 -7
- code_loader/utils.py +10 -1
- {code_loader-1.0.208.dev4.dist-info → code_loader-1.0.208.dev6.dist-info}/METADATA +1 -1
- {code_loader-1.0.208.dev4.dist-info → code_loader-1.0.208.dev6.dist-info}/RECORD +11 -11
- {code_loader-1.0.208.dev4.dist-info → code_loader-1.0.208.dev6.dist-info}/LICENSE +0 -0
- {code_loader-1.0.208.dev4.dist-info → code_loader-1.0.208.dev6.dist-info}/WHEEL +0 -0
|
@@ -6,7 +6,7 @@ import numpy as np
|
|
|
6
6
|
import numpy.typing as npt
|
|
7
7
|
|
|
8
8
|
from code_loader.contract.enums import DataStateType, DataStateEnum, LeapDataType, ConfusionMatrixValue, \
|
|
9
|
-
MetricDirection, DatasetMetadataType, LatentSpaceReduction
|
|
9
|
+
MetricDirection, DatasetMetadataType, LatentSpaceReduction, CustomLatentSpaceComputedAt
|
|
10
10
|
from code_loader.contract.visualizer_classes import LeapImage, LeapText, LeapGraph, LeapHorizontalBar, \
|
|
11
11
|
LeapTextMask, LeapImageMask, LeapImageWithBBox, LeapImageWithHeatmap, LeapVideo, LeapAudio
|
|
12
12
|
from code_loader.contract.sim_config import SimConfig
|
|
@@ -325,7 +325,7 @@ class CustomLatentSpaceHandler:
|
|
|
325
325
|
name: str = 'custom_latent_space'
|
|
326
326
|
use_ls_for_analysis: bool = False
|
|
327
327
|
instance_aware: bool = False
|
|
328
|
-
computed_at:
|
|
328
|
+
computed_at: CustomLatentSpaceComputedAt = CustomLatentSpaceComputedAt.DATASET
|
|
329
329
|
arg_names: Optional[List[str]] = None
|
|
330
330
|
reduce: Optional[LatentSpaceReduction] = None
|
|
331
331
|
n_components: int = 512
|
code_loader/contract/enums.py
CHANGED
|
@@ -22,7 +22,7 @@ from code_loader.contract.datasetclasses import SectionCallableInterface, InputH
|
|
|
22
22
|
AUTOREGRESSIVE_LATENT_SPACE_AGGREGATIONS, AUTOREGRESSIVE_IMPLICIT_ARG_NAMES, \
|
|
23
23
|
AutoregressiveMetricHandler, AutoregressiveLossHandler, AutoregressiveVisualizerHandler
|
|
24
24
|
from code_loader.contract.enums import LeapDataType, DataStateEnum, DataStateType, MetricDirection, DatasetMetadataType, \
|
|
25
|
-
TestingSectionEnum, LatentSpaceReduction
|
|
25
|
+
TestingSectionEnum, LatentSpaceReduction, CustomLatentSpaceComputedAt
|
|
26
26
|
from code_loader.contract.mapping import NodeConnection, NodeMapping, NodeMappingType
|
|
27
27
|
from code_loader.contract.responsedataclasses import DatasetTestResultPayload, LeapAnalysisConfiguration
|
|
28
28
|
from code_loader.contract.visualizer_classes import map_leap_data_type_to_visualizer_class
|
|
@@ -561,7 +561,7 @@ class LeapBinder:
|
|
|
561
561
|
name: Optional[str] = None,
|
|
562
562
|
use_ls_for_analysis: bool = False,
|
|
563
563
|
instance_aware: bool = False,
|
|
564
|
-
computed_at:
|
|
564
|
+
computed_at: CustomLatentSpaceComputedAt = CustomLatentSpaceComputedAt.DATASET,
|
|
565
565
|
arg_names: Optional[List[str]] = None,
|
|
566
566
|
reduce: Optional[LatentSpaceReduction] = None,
|
|
567
567
|
n_components: int = 512,
|
|
@@ -18,7 +18,7 @@ import numpy.typing as npt
|
|
|
18
18
|
from code_loader.utils import map_dict_to_metadata_types, is_absent_metadata_value, \
|
|
19
19
|
validate_autoregressive_state_types, autoregressive_nests_equal, \
|
|
20
20
|
simulate_engine_float16_downcast_on_call_args, ENGINE_STORAGE_DTYPE, \
|
|
21
|
-
TL_DISABLE_ENGINE_FLOAT16_SIMULATION_ENV_VAR
|
|
21
|
+
TL_DISABLE_ENGINE_FLOAT16_SIMULATION_ENV_VAR, sample_preprocess_response_arg_name
|
|
22
22
|
|
|
23
23
|
logger = logging.getLogger(__name__)
|
|
24
24
|
|
|
@@ -29,7 +29,7 @@ from code_loader.contract.datasetclasses import CustomCallableInterfaceMultiArgs
|
|
|
29
29
|
InstanceLengthCallableInterface, InstanceSectionCallableInterface, AutoregressiveStepCallableInterface, \
|
|
30
30
|
MAX_CUSTOM_LATENT_SPACE_DIM, CUSTOM_LATENT_SPACE_WARN_DIM
|
|
31
31
|
from code_loader.contract.enums import MetricDirection, LeapDataType, DatasetMetadataType, DataStateType, \
|
|
32
|
-
DataStateEnum, LatentSpaceReduction
|
|
32
|
+
DataStateEnum, LatentSpaceReduction, CustomLatentSpaceComputedAt
|
|
33
33
|
from code_loader import leap_binder, LeapLoader
|
|
34
34
|
from code_loader.contract.mapping import NodeMapping, NodeMappingType, NodeConnection
|
|
35
35
|
from code_loader.contract.visualizer_classes import LeapImage, LeapImageMask, LeapTextMask, LeapText, LeapGraph, \
|
|
@@ -291,11 +291,7 @@ def _require_sample_preprocess_response_supplied(user_function: Callable, args:
|
|
|
291
291
|
"""A SamplePreprocessResponse argument is auto-injected by the platform / check_dataset
|
|
292
292
|
but NOT inside integration_test, where the author calls the function directly. Fail fast
|
|
293
293
|
with an actionable message instead of a raw 'missing argument' TypeError."""
|
|
294
|
-
spr_arg_name =
|
|
295
|
-
for arg_name, arg_type in inspect.getfullargspec(user_function).annotations.items():
|
|
296
|
-
if arg_type == SamplePreprocessResponse:
|
|
297
|
-
spr_arg_name = arg_name
|
|
298
|
-
break
|
|
294
|
+
spr_arg_name = sample_preprocess_response_arg_name(user_function)
|
|
299
295
|
if spr_arg_name is None:
|
|
300
296
|
return
|
|
301
297
|
signature = inspect.signature(user_function)
|
|
@@ -1786,16 +1782,25 @@ def _classify_custom_latent_space_signature(user_function) -> str:
|
|
|
1786
1782
|
def _model_latent_space_arg_names(user_function) -> List[str]:
|
|
1787
1783
|
argspec = inspect.getfullargspec(user_function)
|
|
1788
1784
|
arg_names = list(argspec.args)
|
|
1789
|
-
|
|
1785
|
+
spr_count = 0
|
|
1790
1786
|
for arg_name, arg_type in argspec.annotations.items():
|
|
1787
|
+
if arg_name == 'return':
|
|
1788
|
+
continue
|
|
1791
1789
|
_reject_stringized_sample_preprocess_response(user_function, arg_name, arg_type)
|
|
1792
1790
|
if arg_type == SamplePreprocessResponse:
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1791
|
+
spr_count += 1
|
|
1792
|
+
if spr_count > 1:
|
|
1793
|
+
raise Exception(
|
|
1794
|
+
f"tensorleap_custom_latent_space validation failed: only one argument of "
|
|
1795
|
+
f"'{user_function.__name__}' can be of type SamplePreprocessResponse.")
|
|
1796
|
+
spr_arg_name = sample_preprocess_response_arg_name(user_function)
|
|
1797
|
+
if spr_arg_name is not None:
|
|
1798
|
+
arg_names.remove(spr_arg_name)
|
|
1799
|
+
if not arg_names:
|
|
1800
|
+
raise Exception(
|
|
1801
|
+
f"tensorleap_custom_latent_space validation failed: '{user_function.__name__}' is "
|
|
1802
|
+
f"model-computed and expects at least one np.ndarray argument, but its signature "
|
|
1803
|
+
f"declares none.")
|
|
1799
1804
|
return arg_names
|
|
1800
1805
|
|
|
1801
1806
|
|
|
@@ -1838,6 +1843,48 @@ def _check_custom_latent_space_width(result, ls_name, reduce, n_components, chan
|
|
|
1838
1843
|
f"reduce=LatentSpaceReduction.RANDOM_PROJECTION."))
|
|
1839
1844
|
|
|
1840
1845
|
|
|
1846
|
+
_FLOAT16_MAX = float(np.finfo(np.float16).max)
|
|
1847
|
+
|
|
1848
|
+
|
|
1849
|
+
def _check_custom_latent_space_values(result: np.ndarray, ls_name: str, has_batch_axis: bool) -> None:
|
|
1850
|
+
"""Reject what no sample could store and warn about values the engine handles per sample."""
|
|
1851
|
+
if isinstance(result, np.ma.MaskedArray):
|
|
1852
|
+
raise Exception(
|
|
1853
|
+
f"tensorleap_custom_latent_space validation failed: '{ls_name}' returned a numpy masked "
|
|
1854
|
+
f"array; the mask would be ignored. Return a plain ndarray, with np.nan for a sample "
|
|
1855
|
+
f"you cannot compute.")
|
|
1856
|
+
if result.dtype.kind not in 'biuf':
|
|
1857
|
+
raise Exception(
|
|
1858
|
+
f"tensorleap_custom_latent_space validation failed: '{ls_name}' returned dtype "
|
|
1859
|
+
f"{result.dtype}. Return a real-valued numeric array (bool, int or float), with np.nan "
|
|
1860
|
+
f"for a sample you cannot compute.")
|
|
1861
|
+
dims = result.shape[1:] if has_batch_axis else result.shape
|
|
1862
|
+
if int(np.prod(dims)) == 0:
|
|
1863
|
+
raise Exception(
|
|
1864
|
+
f"tensorleap_custom_latent_space validation failed: '{ls_name}' returned shape "
|
|
1865
|
+
f"{tuple(result.shape)}, which has no features per sample.")
|
|
1866
|
+
finite = np.isfinite(result)
|
|
1867
|
+
if not finite.all():
|
|
1868
|
+
store_general_warning(
|
|
1869
|
+
key=("tensorleap_custom_latent_space_nonfinite", ls_name),
|
|
1870
|
+
message=(
|
|
1871
|
+
f"Custom latent space '{ls_name}' returned NaN or inf. Those samples are left out of "
|
|
1872
|
+
f"this latent space; if they exceed 5% of the evaluated samples the latent space is "
|
|
1873
|
+
f"dropped."))
|
|
1874
|
+
peak = 0.0
|
|
1875
|
+
if result.size and result.dtype.kind == 'f':
|
|
1876
|
+
peak = float(np.max(np.abs(result), where=finite, initial=0.0))
|
|
1877
|
+
elif result.size and result.dtype.kind in 'iu':
|
|
1878
|
+
peak = float(max(abs(int(result.min())), abs(int(result.max()))))
|
|
1879
|
+
if peak > _FLOAT16_MAX:
|
|
1880
|
+
store_general_warning(
|
|
1881
|
+
key=("tensorleap_custom_latent_space_clipped", ls_name),
|
|
1882
|
+
message=(
|
|
1883
|
+
f"Custom latent space '{ls_name}' returned values beyond +-{_FLOAT16_MAX:.0f}. Latent "
|
|
1884
|
+
f"spaces are stored as float16, so they are clipped to that range; scale or normalize "
|
|
1885
|
+
f"them inside the function to keep their relative size."))
|
|
1886
|
+
|
|
1887
|
+
|
|
1841
1888
|
def tensorleap_custom_latent_space(name: Optional[str] = None, use_ls_for_analysis: bool = False,
|
|
1842
1889
|
reduce: Optional[LatentSpaceReduction] = None,
|
|
1843
1890
|
n_components: int = 512, channel_axis: int = -1):
|
|
@@ -1859,6 +1906,7 @@ def tensorleap_custom_latent_space(name: Optional[str] = None, use_ls_for_analys
|
|
|
1859
1906
|
assert isinstance(single_result, np.ndarray), \
|
|
1860
1907
|
(f'tensorleap_custom_latent_space validation failed: '
|
|
1861
1908
|
f'The return type should be a numpy array. Got {type(single_result)}.')
|
|
1909
|
+
_check_custom_latent_space_values(single_result, ls_name, has_batch_axis=False)
|
|
1862
1910
|
if single_result.ndim > 1:
|
|
1863
1911
|
flat_dim = int(np.prod(single_result.shape))
|
|
1864
1912
|
store_general_warning(
|
|
@@ -1911,7 +1959,7 @@ def tensorleap_custom_latent_space(name: Optional[str] = None, use_ls_for_analys
|
|
|
1911
1959
|
|
|
1912
1960
|
leap_binder.set_custom_latent_space(inner_without_validate, ls_name,
|
|
1913
1961
|
use_ls_for_analysis=use_ls_for_analysis,
|
|
1914
|
-
computed_at=
|
|
1962
|
+
computed_at=CustomLatentSpaceComputedAt.DATASET, reduce=reduce,
|
|
1915
1963
|
n_components=n_components, channel_axis=channel_axis)
|
|
1916
1964
|
|
|
1917
1965
|
def inner(sample_id, preprocess_response):
|
|
@@ -1961,6 +2009,7 @@ def _decorate_model_latent_space(user_function, ls_name, use_ls_for_analysis, re
|
|
|
1961
2009
|
f"tensorleap_custom_latent_space validation failed: '{user_function.__name__}' "
|
|
1962
2010
|
f"returned shape {tuple(result.shape)}. A model-computed latent space returns "
|
|
1963
2011
|
f"(batch, d), so the result needs a batch axis and at least one feature axis.")
|
|
2012
|
+
_check_custom_latent_space_values(result, ls_name, has_batch_axis=True)
|
|
1964
2013
|
if leap_binder.batch_size_to_validate:
|
|
1965
2014
|
assert result.shape[0] == leap_binder.batch_size_to_validate, (
|
|
1966
2015
|
f"tensorleap_custom_latent_space validation failed: '{user_function.__name__}' "
|
|
@@ -1975,6 +2024,7 @@ def _decorate_model_latent_space(user_function, ls_name, use_ls_for_analysis, re
|
|
|
1975
2024
|
_called_from_inside_tl_decorator += 1
|
|
1976
2025
|
|
|
1977
2026
|
try:
|
|
2027
|
+
_require_sample_preprocess_response_supplied(user_function, args, kwargs)
|
|
1978
2028
|
result = user_function(*args, **kwargs)
|
|
1979
2029
|
finally:
|
|
1980
2030
|
_called_from_inside_tl_decorator -= 1
|
|
@@ -1985,7 +2035,7 @@ def _decorate_model_latent_space(user_function, ls_name, use_ls_for_analysis, re
|
|
|
1985
2035
|
|
|
1986
2036
|
leap_binder.set_custom_latent_space(inner_without_validate, ls_name,
|
|
1987
2037
|
use_ls_for_analysis=use_ls_for_analysis,
|
|
1988
|
-
computed_at=
|
|
2038
|
+
computed_at=CustomLatentSpaceComputedAt.MODEL, arg_names=arg_names, reduce=reduce,
|
|
1989
2039
|
n_components=n_components, channel_axis=channel_axis)
|
|
1990
2040
|
|
|
1991
2041
|
def inner(*args, **kwargs):
|
|
@@ -2046,6 +2096,7 @@ def tensorleap_instance_custom_latent_space(name: Optional[str] = None, use_ls_f
|
|
|
2046
2096
|
assert isinstance(result, np.ndarray), \
|
|
2047
2097
|
(f'tensorleap_instance_custom_latent_space validation failed: '
|
|
2048
2098
|
f'The return type should be a numpy array. Got {type(result)}.')
|
|
2099
|
+
_check_custom_latent_space_values(result, ls_name, has_batch_axis=False)
|
|
2049
2100
|
if result.ndim > 1:
|
|
2050
2101
|
flat_dim = int(np.prod(result.shape))
|
|
2051
2102
|
store_general_warning(
|
code_loader/leaploader.py
CHANGED
|
@@ -17,7 +17,8 @@ from code_loader.contract.datasetclasses import DatasetSample, DatasetBaseHandle
|
|
|
17
17
|
PredictionTypeHandler, MetadataHandler, CustomLayerHandler, MetricHandler, VisualizerHandlerData, MetricHandlerData, \
|
|
18
18
|
MetricCallableReturnType, CustomLossHandlerData, CustomLossHandler, RawInputsForHeatmap, SamplePreprocessResponse, \
|
|
19
19
|
ElementInstance, custom_latent_space_attribute, DatasetIntegrationSetup, InstanceMetricHandler, _simulation_context
|
|
20
|
-
from code_loader.contract.enums import DataStateEnum, TestingSectionEnum, DataStateType, DatasetMetadataType
|
|
20
|
+
from code_loader.contract.enums import DataStateEnum, TestingSectionEnum, DataStateType, DatasetMetadataType, \
|
|
21
|
+
CustomLatentSpaceComputedAt
|
|
21
22
|
from code_loader.contract.mapping import NodeMappingType
|
|
22
23
|
from code_loader.contract.exceptions import DatasetScriptException
|
|
23
24
|
from code_loader.contract.responsedataclasses import DatasetIntegParseResult, DatasetTestResultPayload, \
|
|
@@ -29,7 +30,8 @@ from code_loader.inner_leap_binder import global_leap_binder
|
|
|
29
30
|
from code_loader.inner_leap_binder.leapbinder import mapping_runtime_mode_env_var_mame
|
|
30
31
|
from code_loader.leaploaderbase import LeapLoaderBase
|
|
31
32
|
from code_loader.utils import get_root_exception_file_and_line_number, get_metadata_type_from_variable, \
|
|
32
|
-
validate_autoregressive_state_types, autoregressive_nests_equal, is_absent_metadata_value
|
|
33
|
+
validate_autoregressive_state_types, autoregressive_nests_equal, is_absent_metadata_value, \
|
|
34
|
+
sample_preprocess_response_arg_name
|
|
33
35
|
|
|
34
36
|
|
|
35
37
|
def _serialize_sim_bounds(bounds) -> dict:
|
|
@@ -53,6 +55,8 @@ class LeapLoader(LeapLoaderBase):
|
|
|
53
55
|
self._preprocess_result_cached = None
|
|
54
56
|
self._synthetic_lookup: Dict[str, Tuple[PreprocessResponse, Any]] = {}
|
|
55
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()
|
|
56
60
|
|
|
57
61
|
try:
|
|
58
62
|
from code_loader.mixpanel_tracker import track_code_loader_loaded
|
|
@@ -434,7 +438,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
434
438
|
def _check_model_latent_spaces(self) -> Optional[DatasetTestResultPayload]:
|
|
435
439
|
model_names = [
|
|
436
440
|
name for name, handler in global_leap_binder.setup_container.custom_latent_spaces.items()
|
|
437
|
-
if handler.computed_at ==
|
|
441
|
+
if handler.computed_at == CustomLatentSpaceComputedAt.MODEL
|
|
438
442
|
]
|
|
439
443
|
if not model_names:
|
|
440
444
|
return None
|
|
@@ -814,10 +818,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
814
818
|
@staticmethod
|
|
815
819
|
def _get_preprocess_response_arg_name(
|
|
816
820
|
func: Callable) -> Optional[str]:
|
|
817
|
-
|
|
818
|
-
if arg_type == SamplePreprocessResponse:
|
|
819
|
-
return arg_name
|
|
820
|
-
return None
|
|
821
|
+
return sample_preprocess_response_arg_name(func)
|
|
821
822
|
|
|
822
823
|
def run_custom_loss(self, custom_loss_name: str, sample_ids: np.array, state: DataStateEnum,
|
|
823
824
|
input_tensors_by_arg_name: Dict[str, npt.NDArray[np.float32]]):
|
|
@@ -1210,6 +1211,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1210
1211
|
custom_latent_spaces = {
|
|
1211
1212
|
name: self._to_grouped_list(handler.function(group_ids, preprocess_state))
|
|
1212
1213
|
for name, handler in latent_handlers.items()
|
|
1214
|
+
if name not in self._skipped_custom_latent_spaces
|
|
1213
1215
|
}
|
|
1214
1216
|
|
|
1215
1217
|
return DatasetSample(inputs=inputs, gt=gt, metadata=metadata, metadata_is_none=metadata_is_none,
|
|
@@ -1433,7 +1435,8 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1433
1435
|
instance_id: Optional[int] = None) -> Optional[Dict[str, npt.NDArray[np.float32]]]:
|
|
1434
1436
|
handlers = {handler_name: handler for handler_name, handler
|
|
1435
1437
|
in global_leap_binder.setup_container.custom_latent_spaces.items()
|
|
1436
|
-
if handler.computed_at !=
|
|
1438
|
+
if handler.computed_at != CustomLatentSpaceComputedAt.MODEL
|
|
1439
|
+
and handler_name not in self._skipped_custom_latent_spaces}
|
|
1437
1440
|
if not handlers:
|
|
1438
1441
|
return None
|
|
1439
1442
|
if preprocess.is_grouped:
|
|
@@ -1460,6 +1463,10 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1460
1463
|
self.exec_script()
|
|
1461
1464
|
return len(global_leap_binder.setup_container.custom_latent_spaces) > 0
|
|
1462
1465
|
|
|
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
|
+
|
|
1463
1470
|
@lru_cache()
|
|
1464
1471
|
def get_custom_latent_space_names(self) -> Tuple[str, ...]:
|
|
1465
1472
|
"""Names of all registered custom latent spaces, in registration order.
|
|
@@ -1475,20 +1482,14 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1475
1482
|
def get_dataset_custom_latent_space_names(self) -> Tuple[str, ...]:
|
|
1476
1483
|
self.exec_script()
|
|
1477
1484
|
return tuple(name for name, handler in global_leap_binder.setup_container.custom_latent_spaces.items()
|
|
1478
|
-
if handler.computed_at !=
|
|
1479
|
-
|
|
1480
|
-
@lru_cache()
|
|
1481
|
-
def get_model_custom_latent_space_names(self) -> Tuple[str, ...]:
|
|
1482
|
-
self.exec_script()
|
|
1483
|
-
return tuple(name for name, handler in global_leap_binder.setup_container.custom_latent_spaces.items()
|
|
1484
|
-
if handler.computed_at == 'model')
|
|
1485
|
+
if handler.computed_at != CustomLatentSpaceComputedAt.MODEL)
|
|
1485
1486
|
|
|
1486
1487
|
@lru_cache()
|
|
1487
1488
|
def get_custom_latent_space_specs(self) -> Dict[str, Dict[str, Any]]:
|
|
1488
1489
|
self.exec_script()
|
|
1489
1490
|
return {
|
|
1490
1491
|
name: {
|
|
1491
|
-
'computed_at': handler.computed_at,
|
|
1492
|
+
'computed_at': handler.computed_at.value,
|
|
1492
1493
|
'arg_names': list(handler.arg_names or []),
|
|
1493
1494
|
'reduce': handler.reduce.value if handler.reduce is not None else None,
|
|
1494
1495
|
'n_components': handler.n_components,
|
|
@@ -1498,18 +1499,19 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1498
1499
|
}
|
|
1499
1500
|
|
|
1500
1501
|
@lru_cache()
|
|
1501
|
-
def
|
|
1502
|
+
def get_model_custom_latent_space_specs(self) -> Dict[str, Dict[str, Any]]:
|
|
1502
1503
|
return {name: spec for name, spec in self.get_custom_latent_space_specs().items()
|
|
1503
1504
|
if spec['computed_at'] == 'model'}
|
|
1504
1505
|
|
|
1505
1506
|
def run_model_latent_space(self, ls_name: str, sample_ids: np.array, state: DataStateEnum,
|
|
1506
1507
|
input_tensors_by_arg_name: Dict[str, npt.NDArray[np.float32]]
|
|
1507
1508
|
) -> npt.NDArray[np.float32]:
|
|
1508
|
-
self.
|
|
1509
|
-
|
|
1509
|
+
self.exec_script()
|
|
1510
1510
|
handler = global_leap_binder.setup_container.custom_latent_spaces[ls_name]
|
|
1511
1511
|
preprocess_response_arg_name = self._get_preprocess_response_arg_name(handler.function)
|
|
1512
1512
|
|
|
1513
|
+
# Preprocess runs only when the function asks for a SamplePreprocessResponse; the metrics
|
|
1514
|
+
# pod that calls this has no other reason to pay for it.
|
|
1513
1515
|
if preprocess_response_arg_name is not None:
|
|
1514
1516
|
input_tensors_by_arg_name[preprocess_response_arg_name] = SamplePreprocessResponse(
|
|
1515
1517
|
sample_ids, self._preprocess_result()[state])
|
code_loader/leaploaderbase.py
CHANGED
|
@@ -234,20 +234,15 @@ class LeapLoaderBase:
|
|
|
234
234
|
raise NotImplementedError(f'{type(self).__name__} does not implement '
|
|
235
235
|
'get_dataset_custom_latent_space_names.')
|
|
236
236
|
|
|
237
|
-
@abstractmethod
|
|
238
|
-
def get_model_custom_latent_space_names(self) -> Tuple[str, ...]:
|
|
239
|
-
raise NotImplementedError(f'{type(self).__name__} does not implement '
|
|
240
|
-
'get_model_custom_latent_space_names.')
|
|
241
|
-
|
|
242
237
|
@abstractmethod
|
|
243
238
|
def get_custom_latent_space_specs(self) -> Dict[str, Dict[str, Any]]:
|
|
244
239
|
raise NotImplementedError(f'{type(self).__name__} does not implement '
|
|
245
240
|
'get_custom_latent_space_specs.')
|
|
246
241
|
|
|
247
242
|
@abstractmethod
|
|
248
|
-
def
|
|
243
|
+
def get_model_custom_latent_space_specs(self) -> Dict[str, Dict[str, Any]]:
|
|
249
244
|
raise NotImplementedError(f'{type(self).__name__} does not implement '
|
|
250
|
-
'
|
|
245
|
+
'get_model_custom_latent_space_specs.')
|
|
251
246
|
|
|
252
247
|
@abstractmethod
|
|
253
248
|
def run_model_latent_space(self, ls_name: str, sample_ids: np.array, state: DataStateEnum,
|
code_loader/utils.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import inspect
|
|
1
2
|
import io
|
|
2
3
|
import math
|
|
3
4
|
import os
|
|
@@ -11,7 +12,7 @@ import numpy as np
|
|
|
11
12
|
import numpy.typing as npt
|
|
12
13
|
|
|
13
14
|
from code_loader.contract.datasetclasses import SectionCallableInterface, PreprocessResponse, \
|
|
14
|
-
InstanceCallableInterface, ElementInstance
|
|
15
|
+
InstanceCallableInterface, ElementInstance, SamplePreprocessResponse
|
|
15
16
|
from code_loader.contract.enums import DatasetMetadataType
|
|
16
17
|
|
|
17
18
|
|
|
@@ -246,3 +247,11 @@ def autoregressive_nests_equal(a: Any, b: Any) -> bool:
|
|
|
246
247
|
math.isnan(a) and math.isnan(b):
|
|
247
248
|
return True
|
|
248
249
|
return bool(a == b)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def sample_preprocess_response_arg_name(func: Callable[..., Any]) -> Optional[str]:
|
|
253
|
+
# 'return' lives in annotations too and must never be mistaken for a parameter.
|
|
254
|
+
for arg_name, arg_type in inspect.getfullargspec(func).annotations.items():
|
|
255
|
+
if arg_name != 'return' and arg_type == SamplePreprocessResponse:
|
|
256
|
+
return arg_name
|
|
257
|
+
return None
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
2
2
|
code_loader/__init__.py,sha256=outxRQ0M-zMfV0QGVJmAed5qWfRmyD0TV6-goEGAzBw,406
|
|
3
3
|
code_loader/contract/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
code_loader/contract/datasetclasses.py,sha256=
|
|
5
|
-
code_loader/contract/enums.py,sha256=
|
|
4
|
+
code_loader/contract/datasetclasses.py,sha256=yNEPIyZqCO54fKBgmgbFIKEMVBzvpf4n8U2zmPhXv88,18110
|
|
5
|
+
code_loader/contract/enums.py,sha256=R4Ge9-oSO7-GYjZAKMTB8Ws5FNsxhCQAYAJruxViJxk,1886
|
|
6
6
|
code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
|
|
7
7
|
code_loader/contract/mapping.py,sha256=i-yVyFuGUITL5lchPNfYlu7bhwk-yuoHPacAeFhcYr8,1490
|
|
8
8
|
code_loader/contract/responsedataclasses.py,sha256=5AB9uP7eJt2Oaq2grMwLQeiQLiw2gj1x04HE7gVUaRU,5112
|
|
@@ -21,18 +21,18 @@ 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=
|
|
25
|
-
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=
|
|
26
|
-
code_loader/leaploader.py,sha256=
|
|
27
|
-
code_loader/leaploaderbase.py,sha256=
|
|
24
|
+
code_loader/inner_leap_binder/leapbinder.py,sha256=tvIFlSEOW4iaONJreh0EAlF_A9mpE3B13ohXhIUa1f0,63213
|
|
25
|
+
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=vPbHSw51hVWdcPe1Vwta35TpW5So4ykW-qkgSuGJq_I,209787
|
|
26
|
+
code_loader/leaploader.py,sha256=qi7Hbk-LyvEm_nGLmpioA4vLf1NEnhHeHj8U2Rq992o,97523
|
|
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
|
|
30
30
|
code_loader/plot_functions/plot_functions.py,sha256=2DC-zlVaN13P4VNx5d8csgs80C6SisaeP1-Kq2LW7iM,16075
|
|
31
31
|
code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6LznoQIvi4vpo,657
|
|
32
|
-
code_loader/utils.py,sha256=
|
|
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.
|
|
36
|
-
code_loader-1.0.208.
|
|
37
|
-
code_loader-1.0.208.
|
|
38
|
-
code_loader-1.0.208.
|
|
35
|
+
code_loader-1.0.208.dev6.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
|
|
36
|
+
code_loader-1.0.208.dev6.dist-info/METADATA,sha256=xkhqTPaPoJgUne7-cH7AtBDmKGGQ0aDZC7FbW2aGDsI,1095
|
|
37
|
+
code_loader-1.0.208.dev6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
38
|
+
code_loader-1.0.208.dev6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|