code-loader 1.0.208.dev7__tar.gz → 1.0.209__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.
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/PKG-INFO +4 -3
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/inner_leap_binder/leapbinder.py +11 -5
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/inner_leap_binder/leapbinder_decorators.py +54 -21
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/leaploader.py +85 -15
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/utils.py +4 -4
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/pyproject.toml +1 -1
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/LICENSE +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/README.md +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/__init__.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/__init__.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/datasetclasses.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/enums.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/exceptions.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/mapping.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/responsedataclasses.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/sim_config.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/visualizer_classes.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/default_losses.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/default_metrics.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/__init__.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/api.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/cli_config_utils.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/client.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/epoch.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/experiment.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/experiment_context.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/types.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/utils.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/inner_leap_binder/__init__.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/leaploaderbase.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/mixpanel_tracker.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/plot_functions/__init__.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/plot_functions/plot_functions.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/plot_functions/visualize.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/visualizers/__init__.py +0 -0
- {code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/visualizers/default_visualizers.py +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: code-loader
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.209
|
|
4
4
|
Summary:
|
|
5
|
-
Home-page: https://github.com/tensorleap/code-loader
|
|
6
5
|
License: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
7
|
Author: dorhar
|
|
8
8
|
Author-email: doron.harnoy@tensorleap.ai
|
|
9
9
|
Requires-Python: >=3.8,<3.13
|
|
@@ -20,6 +20,7 @@ Requires-Dist: numpy (>=2.3.2,<3.0.0) ; python_version >= "3.11" and python_vers
|
|
|
20
20
|
Requires-Dist: psutil (>=5.9.5,<6.0.0)
|
|
21
21
|
Requires-Dist: pyyaml (>=6.0.2,<7.0.0)
|
|
22
22
|
Requires-Dist: requests (>=2.32.3,<3.0.0)
|
|
23
|
+
Project-URL: Homepage, https://github.com/tensorleap/code-loader
|
|
23
24
|
Project-URL: Repository, https://github.com/tensorleap/code-loader
|
|
24
25
|
Description-Content-Type: text/markdown
|
|
25
26
|
|
{code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/inner_leap_binder/leapbinder.py
RENAMED
|
@@ -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
|
|
|
@@ -116,6 +111,10 @@ class LeapBinder:
|
|
|
116
111
|
|
|
117
112
|
self.mapping_connections: List[NodeConnection] = []
|
|
118
113
|
self.integration_test_func: Optional[Callable[[str, PreprocessResponse], Any]] = None
|
|
114
|
+
# Set by LeapLoader.exec_script when running the dataset script failed, because that
|
|
115
|
+
# also resets setup_container: an empty container after a failure means "the script
|
|
116
|
+
# crashed", not "the user forgot to register". See get_preprocess_result.
|
|
117
|
+
self.previous_script_failure: Optional[BaseException] = None
|
|
119
118
|
|
|
120
119
|
self.batch_size_to_validate: Optional[int] = None
|
|
121
120
|
self.leap_analysis_configuration = LeapAnalysisConfiguration()
|
|
@@ -808,6 +807,13 @@ class LeapBinder:
|
|
|
808
807
|
def get_preprocess_result(self) -> Dict[DataStateEnum, PreprocessResponse]:
|
|
809
808
|
preprocess = self.setup_container.preprocess
|
|
810
809
|
if preprocess is None:
|
|
810
|
+
if self.previous_script_failure is not None:
|
|
811
|
+
# Running the dataset script already failed once, and that reset the
|
|
812
|
+
# registrations (LeapLoader.exec_script). Blaming a missing
|
|
813
|
+
# set_preprocess call here would hide the actual crash.
|
|
814
|
+
raise Exception(
|
|
815
|
+
f"The dataset script failed before registering its handlers: "
|
|
816
|
+
f"{self.previous_script_failure}") from self.previous_script_failure
|
|
811
817
|
raise Exception("Please make sure you call the leap_binder.set_preprocess method")
|
|
812
818
|
preprocess_results = preprocess.function()
|
|
813
819
|
preprocess_result_dict = {}
|
|
@@ -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
|
-
|
|
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,41 @@ 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
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
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
|
+
try:
|
|
1766
|
+
hints = typing.get_type_hints(user_function)
|
|
1767
|
+
except NameError as e:
|
|
1768
|
+
raise Exception(
|
|
1769
|
+
f"tensorleap_custom_latent_space validation failed: could not resolve the type "
|
|
1770
|
+
f"annotations of '{user_function.__name__}' ({e}). Tensorleap reads them to tell a "
|
|
1771
|
+
f"dataset-computed latent space from a model-computed one, so every annotation, the "
|
|
1772
|
+
f"return type included, must be resolvable when the function is decorated. Import the "
|
|
1773
|
+
f"annotated types at module level (not only under TYPE_CHECKING) or remove the "
|
|
1774
|
+
f"annotation.") from e
|
|
1775
|
+
preprocess_params = [p.name for p in params if _is_preprocess_response_type(hints.get(p.name))]
|
|
1776
|
+
if preprocess_params:
|
|
1777
|
+
positional = [p.name for p in params
|
|
1778
|
+
if p.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD)]
|
|
1779
|
+
if positional[1:2] != preprocess_params[:1] or len(preprocess_params) > 1:
|
|
1780
|
+
raise Exception(
|
|
1781
|
+
f"tensorleap_custom_latent_space validation failed: '{user_function.__name__}' is "
|
|
1782
|
+
f"dataset-computed (it takes a PreprocessResponse), so it is called as "
|
|
1783
|
+
f"{user_function.__name__}(sample_id, preprocess) and its PreprocessResponse must be "
|
|
1784
|
+
f"the second positional parameter, and the only one. Got parameters "
|
|
1785
|
+
f"{[p.name for p in params]} with PreprocessResponse on {preprocess_params}.")
|
|
1786
|
+
return 'dataset'
|
|
1787
|
+
|
|
1788
|
+
if len(params) == 2 and params[1].name not in hints:
|
|
1789
|
+
first, second = params[0].name, params[1].name
|
|
1763
1790
|
raise Exception(
|
|
1764
1791
|
f"tensorleap_custom_latent_space validation failed: '{user_function.__name__}' has "
|
|
1765
1792
|
f"exactly two parameters ('{first}', '{second}') and '{second}' has no type "
|
|
@@ -1771,23 +1798,29 @@ def _classify_custom_latent_space_signature(user_function) -> str:
|
|
|
1771
1798
|
f"If you are upgrading an existing project, this signature used to be accepted "
|
|
1772
1799
|
f"unannotated as dataset-computed; add ': PreprocessResponse' to '{second}' to keep "
|
|
1773
1800
|
f"the previous behavior.")
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1801
|
+
if len(params) > 2 and not any(p.name in hints for p in params):
|
|
1802
|
+
names = [p.name for p in params]
|
|
1803
|
+
raise Exception(
|
|
1804
|
+
f"tensorleap_custom_latent_space validation failed: '{user_function.__name__}' has "
|
|
1805
|
+
f"parameters {names} and none of them has a type annotation, so Tensorleap cannot "
|
|
1806
|
+
f"tell whether this is a dataset-computed latent space (one sample at a time) or a "
|
|
1807
|
+
f"model-computed one (a batch of model tensors). Please annotate them:\n"
|
|
1808
|
+
f" dataset-computed: def {user_function.__name__}({names[0]}, {names[1]}: PreprocessResponse, ...) -> (d,)\n"
|
|
1809
|
+
f" model-computed: def {user_function.__name__}({names[0]}: np.ndarray, {names[1]}: np.ndarray, ...) -> (batch, d)")
|
|
1779
1810
|
return 'model'
|
|
1780
1811
|
|
|
1781
1812
|
|
|
1782
1813
|
def _model_latent_space_arg_names(user_function) -> List[str]:
|
|
1783
|
-
|
|
1784
|
-
|
|
1814
|
+
# inspect.signature follows functools.wraps' __wrapped__, as the classifier does.
|
|
1815
|
+
params = inspect.signature(user_function).parameters.values()
|
|
1816
|
+
arg_names = [p.name for p in params
|
|
1817
|
+
if p.kind in (inspect.Parameter.POSITIONAL_ONLY, inspect.Parameter.POSITIONAL_OR_KEYWORD)]
|
|
1785
1818
|
spr_count = 0
|
|
1786
|
-
for
|
|
1787
|
-
if
|
|
1819
|
+
for param in params:
|
|
1820
|
+
if param.annotation is inspect.Parameter.empty:
|
|
1788
1821
|
continue
|
|
1789
|
-
_reject_stringized_sample_preprocess_response(user_function,
|
|
1790
|
-
if
|
|
1822
|
+
_reject_stringized_sample_preprocess_response(user_function, param.name, param.annotation)
|
|
1823
|
+
if param.annotation == SamplePreprocessResponse:
|
|
1791
1824
|
spr_count += 1
|
|
1792
1825
|
if spr_count > 1:
|
|
1793
1826
|
raise Exception(
|
|
@@ -1869,7 +1902,7 @@ def _check_custom_latent_space_values(result: np.ndarray, ls_name: str, has_batc
|
|
|
1869
1902
|
key=("tensorleap_custom_latent_space_nonfinite", ls_name),
|
|
1870
1903
|
message=(
|
|
1871
1904
|
f"Custom latent space '{ls_name}' returned NaN or inf. Those samples are left out of "
|
|
1872
|
-
f"this latent space; if they exceed
|
|
1905
|
+
f"this latent space; if they exceed 15% of the evaluated samples the latent space is "
|
|
1873
1906
|
f"dropped."))
|
|
1874
1907
|
peak = 0.0
|
|
1875
1908
|
if result.size and result.dtype.kind == 'f':
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# mypy: ignore-errors
|
|
2
|
+
import copy
|
|
2
3
|
import importlib.util
|
|
3
4
|
import inspect
|
|
4
5
|
import io
|
|
@@ -7,6 +8,7 @@ import sys
|
|
|
7
8
|
from contextlib import redirect_stdout
|
|
8
9
|
from functools import lru_cache
|
|
9
10
|
from pathlib import Path
|
|
11
|
+
from types import TracebackType
|
|
10
12
|
from typing import Dict, List, Iterable, Set, FrozenSet, Union, Any, Type, Optional, Callable, Tuple
|
|
11
13
|
|
|
12
14
|
import numpy as np
|
|
@@ -33,6 +35,44 @@ from code_loader.utils import get_root_exception_file_and_line_number, get_metad
|
|
|
33
35
|
validate_autoregressive_state_types, autoregressive_nests_equal, is_absent_metadata_value, \
|
|
34
36
|
sample_preprocess_response_arg_name
|
|
35
37
|
|
|
38
|
+
_code_loader_dir = str(Path(__file__).parent)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _innermost_frame_outside_code_loader(e: BaseException) -> Optional[TracebackType]:
|
|
42
|
+
"""The deepest traceback frame that is not code_loader's own code, if any.
|
|
43
|
+
|
|
44
|
+
That is the line the user can go and look at. The deepest frame overall is often
|
|
45
|
+
ours — a validation that raises, or a builtin we wrapped — and "raised at
|
|
46
|
+
leapbinder.py" tells the user nothing about their script.
|
|
47
|
+
"""
|
|
48
|
+
frame_in_user_code = None
|
|
49
|
+
_traceback = e.__traceback__
|
|
50
|
+
while _traceback is not None:
|
|
51
|
+
if not _traceback.tb_frame.f_code.co_filename.startswith(_code_loader_dir):
|
|
52
|
+
frame_in_user_code = _traceback
|
|
53
|
+
_traceback = _traceback.tb_next
|
|
54
|
+
return frame_in_user_code
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def describe_script_exception(e: BaseException) -> str:
|
|
58
|
+
"""One line describing a failure raised by user code: its type, its message and where it happened.
|
|
59
|
+
|
|
60
|
+
``repr(e)`` on its own throws away what the user needs most: ``repr`` of an OSError
|
|
61
|
+
drops the filename (``FileNotFoundError(2, 'No such file or directory')`` — but not
|
|
62
|
+
*which* file), and no ``repr`` says which line of the integration script raised. Both
|
|
63
|
+
are what turns "the dataset script crashed" into an error the user can act on.
|
|
64
|
+
"""
|
|
65
|
+
message = getattr(e, 'message', None)
|
|
66
|
+
if not isinstance(message, str) or not message:
|
|
67
|
+
message = str(e)
|
|
68
|
+
description = f'{type(e).__name__}: {message}' if message else repr(e)
|
|
69
|
+
|
|
70
|
+
frame_in_user_code = _innermost_frame_outside_code_loader(e)
|
|
71
|
+
if frame_in_user_code is not None:
|
|
72
|
+
file_name = Path(frame_in_user_code.tb_frame.f_code.co_filename).name
|
|
73
|
+
description = f'{description} (raised at {file_name}, line {frame_in_user_code.tb_lineno})'
|
|
74
|
+
return description
|
|
75
|
+
|
|
36
76
|
|
|
37
77
|
def _serialize_sim_bounds(bounds) -> dict:
|
|
38
78
|
if isinstance(bounds, (FloatBounds, IntBounds)):
|
|
@@ -55,8 +95,8 @@ class LeapLoader(LeapLoaderBase):
|
|
|
55
95
|
self._preprocess_result_cached = None
|
|
56
96
|
self._synthetic_lookup: Dict[str, Tuple[PreprocessResponse, Any]] = {}
|
|
57
97
|
self._synthetic_populator: Optional[Callable[[str], None]] = None
|
|
58
|
-
#
|
|
59
|
-
self.
|
|
98
|
+
# The first exec_script failure, re-raised by every later call. See exec_script.
|
|
99
|
+
self._exec_script_error: Optional[BaseException] = None
|
|
60
100
|
|
|
61
101
|
try:
|
|
62
102
|
from code_loader.mixpanel_tracker import track_code_loader_loaded
|
|
@@ -68,9 +108,33 @@ class LeapLoader(LeapLoaderBase):
|
|
|
68
108
|
except Exception:
|
|
69
109
|
pass
|
|
70
110
|
|
|
111
|
+
def _remember_exec_script_error(self, error: BaseException) -> BaseException:
|
|
112
|
+
# Also recorded on the binder: the failure handlers below wipe its setup_container,
|
|
113
|
+
# so anything that reaches the binder afterwards (another LeapLoader in the same
|
|
114
|
+
# process, say) can report the real failure instead of an empty container.
|
|
115
|
+
global_leap_binder.previous_script_failure = error
|
|
116
|
+
self._exec_script_error = error
|
|
117
|
+
return error
|
|
118
|
+
|
|
71
119
|
@lru_cache()
|
|
72
120
|
def exec_script(self) -> None:
|
|
73
121
|
from code_loader.inner_leap_binder import leapbinder_decorators as _leap_dec
|
|
122
|
+
|
|
123
|
+
# A failed exec_script is sticky. lru_cache does not cache exceptions, so without
|
|
124
|
+
# this every later caller re-ran the script — and the re-run reports the WRONG
|
|
125
|
+
# error: the handlers below reset global_leap_binder.setup_container, while
|
|
126
|
+
# re-importing the entry file does not re-register handlers that live in modules
|
|
127
|
+
# already in sys.modules. The second run therefore raised "Please make sure you
|
|
128
|
+
# call the leap_binder.set_preprocess method", burying the real cause (a missing
|
|
129
|
+
# file, a bad path, a typo'd import). Callers do retry — the engine's samples
|
|
130
|
+
# generator calls this once per loop iteration — so the real error was logged once
|
|
131
|
+
# and then drowned in generic repeats.
|
|
132
|
+
if self._exec_script_error is not None:
|
|
133
|
+
# A fresh copy each time: re-raising the stored object would append this call's
|
|
134
|
+
# frames to its __traceback__, so a caller retrying in a loop grows it (and keeps
|
|
135
|
+
# every retry's frames alive) without bound.
|
|
136
|
+
error = self._exec_script_error
|
|
137
|
+
raise copy.copy(error) from error.__cause__
|
|
74
138
|
try:
|
|
75
139
|
os.environ[mapping_runtime_mode_env_var_mame] = 'TRUE'
|
|
76
140
|
self.evaluate_module()
|
|
@@ -100,16 +164,19 @@ class LeapLoader(LeapLoaderBase):
|
|
|
100
164
|
if is_grouped else
|
|
101
165
|
PreprocessResponse(state=DataStateType.training, length=0))
|
|
102
166
|
global_leap_binder.integration_test_func(None, mapping_preprocess)
|
|
167
|
+
global_leap_binder.previous_script_failure = None
|
|
103
168
|
except TypeError as e:
|
|
104
169
|
import traceback
|
|
105
170
|
global_leap_binder.setup_container = DatasetIntegrationSetup()
|
|
106
171
|
if "leap_binder.set_metadata(" in traceback.format_exc(5):
|
|
107
|
-
raise DeprecationWarning(
|
|
108
|
-
"Please remove the metadata_type on leap_binder.set_metadata in your dataset script")
|
|
109
|
-
raise
|
|
172
|
+
raise self._remember_exec_script_error(DeprecationWarning(
|
|
173
|
+
"Please remove the metadata_type on leap_binder.set_metadata in your dataset script"))
|
|
174
|
+
raise self._remember_exec_script_error(
|
|
175
|
+
DatasetScriptException(describe_script_exception(e))) from e
|
|
110
176
|
except Exception as e:
|
|
111
177
|
global_leap_binder.setup_container = DatasetIntegrationSetup()
|
|
112
|
-
raise
|
|
178
|
+
raise self._remember_exec_script_error(
|
|
179
|
+
DatasetScriptException(describe_script_exception(e))) from e
|
|
113
180
|
finally:
|
|
114
181
|
# ensure that the environment variable is removed after the script execution
|
|
115
182
|
_leap_dec._mapping_dataset_is_grouped = False
|
|
@@ -1208,10 +1275,17 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1208
1275
|
if any(handler.instance_aware for handler in latent_handlers.values()):
|
|
1209
1276
|
raise Exception(
|
|
1210
1277
|
"instance-aware custom latent spaces are not supported with grouped preprocess responses")
|
|
1278
|
+
# TODO: support model-computed custom latent spaces on grouped datasets (skip them here,
|
|
1279
|
+
# as the per-sample path does, once the grouped metrics path is verified to compute them).
|
|
1280
|
+
model_ls_names = [name for name, handler in latent_handlers.items()
|
|
1281
|
+
if handler.computed_at == CustomLatentSpaceComputedAt.MODEL]
|
|
1282
|
+
if model_ls_names:
|
|
1283
|
+
raise Exception(
|
|
1284
|
+
f"model-computed custom latent spaces {model_ls_names} are not supported with "
|
|
1285
|
+
f"grouped preprocess responses yet")
|
|
1211
1286
|
custom_latent_spaces = {
|
|
1212
1287
|
name: self._to_grouped_list(handler.function(group_ids, preprocess_state))
|
|
1213
1288
|
for name, handler in latent_handlers.items()
|
|
1214
|
-
if name not in self._skipped_custom_latent_spaces
|
|
1215
1289
|
}
|
|
1216
1290
|
|
|
1217
1291
|
return DatasetSample(inputs=inputs, gt=gt, metadata=metadata, metadata_is_none=metadata_is_none,
|
|
@@ -1435,8 +1509,7 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1435
1509
|
instance_id: Optional[int] = None) -> Optional[Dict[str, npt.NDArray[np.float32]]]:
|
|
1436
1510
|
handlers = {handler_name: handler for handler_name, handler
|
|
1437
1511
|
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}
|
|
1512
|
+
if handler.computed_at != CustomLatentSpaceComputedAt.MODEL}
|
|
1440
1513
|
if not handlers:
|
|
1441
1514
|
return None
|
|
1442
1515
|
if preprocess.is_grouped:
|
|
@@ -1463,10 +1536,6 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1463
1536
|
self.exec_script()
|
|
1464
1537
|
return len(global_leap_binder.setup_container.custom_latent_spaces) > 0
|
|
1465
1538
|
|
|
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
1539
|
@lru_cache()
|
|
1471
1540
|
def get_custom_latent_space_names(self) -> Tuple[str, ...]:
|
|
1472
1541
|
"""Names of all registered custom latent spaces, in registration order.
|
|
@@ -1513,8 +1582,9 @@ class LeapLoader(LeapLoaderBase):
|
|
|
1513
1582
|
# Preprocess runs only when the function asks for a SamplePreprocessResponse; the metrics
|
|
1514
1583
|
# pod that calls this has no other reason to pay for it.
|
|
1515
1584
|
if preprocess_response_arg_name is not None:
|
|
1516
|
-
input_tensors_by_arg_name
|
|
1517
|
-
|
|
1585
|
+
input_tensors_by_arg_name = {
|
|
1586
|
+
**input_tensors_by_arg_name,
|
|
1587
|
+
preprocess_response_arg_name: SamplePreprocessResponse(sample_ids, self._preprocess_result()[state])}
|
|
1518
1588
|
|
|
1519
1589
|
return handler.function(**input_tensors_by_arg_name)
|
|
1520
1590
|
|
|
@@ -250,8 +250,8 @@ def autoregressive_nests_equal(a: Any, b: Any) -> bool:
|
|
|
250
250
|
|
|
251
251
|
|
|
252
252
|
def sample_preprocess_response_arg_name(func: Callable[..., Any]) -> Optional[str]:
|
|
253
|
-
#
|
|
254
|
-
for
|
|
255
|
-
if
|
|
256
|
-
return
|
|
253
|
+
# inspect.signature follows functools.wraps' __wrapped__; getfullargspec does not.
|
|
254
|
+
for param in inspect.signature(func).parameters.values():
|
|
255
|
+
if param.annotation == SamplePreprocessResponse:
|
|
256
|
+
return param.name
|
|
257
257
|
return None
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/contract/responsedataclasses.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/cli_config_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/experiment_api/experiment_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/plot_functions/plot_functions.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{code_loader-1.0.208.dev7 → code_loader-1.0.209}/code_loader/visualizers/default_visualizers.py
RENAMED
|
File without changes
|