code-loader 1.0.195.dev1__py3-none-any.whl → 1.0.197.dev0__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.
@@ -149,10 +149,78 @@ class LeapLoaderBase:
149
149
  def has_custom_latent_space_decorator(self) -> bool:
150
150
  pass
151
151
 
152
+ # The autoregressive entry points raise instead of `pass`-ing like the abstract methods
153
+ # above: this class has no ABCMeta, so @abstractmethod is not enforced at runtime and an
154
+ # un-overridden `pass` body would return None — has_autoregressive_step would silently
155
+ # report False for an AR integration and the engine would skip the chain rollout with no
156
+ # error. A stale loader subclass keeps working for non-AR flows and fails loudly here the
157
+ # moment an AR flow reaches it.
158
+ @abstractmethod
152
159
  def has_autoregressive_step(self) -> bool:
153
- # Default False so existing LeapLoaderBase implementations stay valid; the concrete
154
- # loaders that can answer (LeapLoader in-process, LeapLoaderWithRedis via RPC) override.
155
- return False
160
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
161
+ 'has_autoregressive_step it must be overridden '
162
+ '(LeapLoader in-process, LeapLoaderWithRedis via RPC).')
163
+
164
+ @abstractmethod
165
+ def get_gt(self, state: DataStateEnum, sample_id: Union[int, str]
166
+ ) -> Dict[str, npt.NDArray[np.float32]]:
167
+ raise NotImplementedError(f'{type(self).__name__} does not implement get_gt.')
168
+
169
+ @abstractmethod
170
+ def get_prediction_names_in_order(self) -> List[str]:
171
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
172
+ 'get_prediction_names_in_order.')
173
+
174
+ @abstractmethod
175
+ def get_autoregressive_latent_space_aggregation(self) -> str:
176
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
177
+ 'get_autoregressive_latent_space_aggregation.')
178
+
179
+ @abstractmethod
180
+ def get_autoregressive_decorator_names(self) -> Dict[str, List[str]]:
181
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
182
+ 'get_autoregressive_decorator_names.')
183
+
184
+ @abstractmethod
185
+ def run_autoregressive_step(self, sample_id: Union[int, str],
186
+ prev_inputs: Optional[Dict[str, npt.NDArray[np.float32]]],
187
+ prev_outputs: Optional[Dict[str, npt.NDArray[np.float32]]],
188
+ chain_state: Any,
189
+ state: DataStateEnum
190
+ ) -> Tuple[Optional[Dict[str, npt.NDArray[np.float32]]], Any]:
191
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
192
+ 'run_autoregressive_step.')
193
+
194
+ @abstractmethod
195
+ def run_autoregressive_metric(self, name: str, inputs: Dict[str, npt.NDArray[np.float32]],
196
+ outputs: Dict[str, npt.NDArray[np.float32]], chain_state: Any,
197
+ wired_args: Dict[str, npt.NDArray[np.float32]]) -> Any:
198
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
199
+ 'run_autoregressive_metric.')
200
+
201
+ @abstractmethod
202
+ def run_autoregressive_loss(self, name: str, inputs: Dict[str, npt.NDArray[np.float32]],
203
+ outputs: Dict[str, npt.NDArray[np.float32]], chain_state: Any,
204
+ wired_args: Dict[str, npt.NDArray[np.float32]]) -> Any:
205
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
206
+ 'run_autoregressive_loss.')
207
+
208
+ @abstractmethod
209
+ def run_autoregressive_visualizer(self, name: str, inputs: Dict[str, npt.NDArray[np.float32]],
210
+ outputs: Dict[str, npt.NDArray[np.float32]],
211
+ chain_state: Any,
212
+ wired_args: Dict[str, npt.NDArray[np.float32]]) -> Any:
213
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
214
+ 'run_autoregressive_visualizer.')
215
+
216
+ @abstractmethod
217
+ def autoregressive_visualizer_by_name(self) -> Dict[str, VisualizerHandlerData]:
218
+ raise NotImplementedError(f'{type(self).__name__} does not implement '
219
+ 'autoregressive_visualizer_by_name.')
220
+
221
+ @abstractmethod
222
+ def get_custom_latent_space_names(self) -> Tuple[str, ...]:
223
+ pass
156
224
 
157
225
  @abstractmethod
158
226
  def get_heatmap_visualizer_raw_vis_input_arg_name(self, visualizer_name: str) -> Optional[str]:
code_loader/utils.py CHANGED
@@ -1,3 +1,6 @@
1
+ import io
2
+ import math
3
+ import pickle
1
4
  import sys
2
5
  from pathlib import Path
3
6
  from types import TracebackType
@@ -14,11 +17,6 @@ from code_loader.contract.enums import DatasetMetadataType
14
17
  def to_numpy_return_wrapper(encoder_function: SectionCallableInterface) -> SectionCallableInterface:
15
18
  def numpy_encoder_function(idx: Union[int, str], samples: PreprocessResponse) -> npt.NDArray[np.float32]:
16
19
  result = encoder_function(idx, samples)
17
- if isinstance(result, list) and len(result) > 0 and all(isinstance(sample, np.ndarray) for sample in result):
18
- # A list of per-sample arrays only comes from a grouped encoder (a flat encoder returns
19
- # a single array). Never stack it into a (B, *) batch — grouping is only a storage
20
- # read-unit; batching the group to the model's B is the engine's single responsibility.
21
- return result
22
20
  numpy_result: npt.NDArray[np.float32] = np.array(result)
23
21
  return numpy_result
24
22
 
@@ -106,3 +104,51 @@ def get_metadata_type_from_variable(variable: Union[Optional[str], int, bool, Op
106
104
  f"The return type should be one of [int, float, str, bool]. Got {metadata_type}")
107
105
  return dataset_metadata_type
108
106
 
107
+
108
+
109
+ # The platform queue transports state as pickled payloads which the engine deserializes
110
+ # WITHOUT the integration code loaded, so a class defined in the user's modules round-trips
111
+ # locally but crashes on the engine. Only modules importable on the engine may resolve.
112
+ _STATE_SAFE_PICKLE_MODULES = ('builtins', 'copyreg', 'collections', 'numpy', 'datetime')
113
+
114
+
115
+ class _EngineSafeUnpickler(pickle.Unpickler):
116
+ def find_class(self, module: str, name: str) -> Any:
117
+ if module.split('.')[0] in _STATE_SAFE_PICKLE_MODULES:
118
+ return super().find_class(module, name)
119
+ raise pickle.UnpicklingError(
120
+ f'{module}.{name} is defined in integration code, which is not importable on the '
121
+ f'platform engine')
122
+
123
+
124
+ def validate_autoregressive_state_types(value: Any, path: str = 'state') -> None:
125
+ try:
126
+ _EngineSafeUnpickler(io.BytesIO(pickle.dumps(value))).load()
127
+ except Exception as e:
128
+ raise AssertionError(
129
+ f'autoregressive state validation failed: {path} is not serializable ({e}). State '
130
+ 'is serialized to the platform queue on every chain step and deserialized without '
131
+ 'the integration code — any picklable nest of builtin/numpy values works (dicts, '
132
+ 'lists, tuples, sets, numbers, strings, arrays), but user-defined classes, lambdas '
133
+ 'and open resources do not.') from e
134
+
135
+
136
+ def autoregressive_nests_equal(a: Any, b: Any) -> bool:
137
+ if isinstance(a, dict) or isinstance(b, dict):
138
+ return isinstance(a, dict) and isinstance(b, dict) and set(a) == set(b) and \
139
+ all(autoregressive_nests_equal(a[key], b[key]) for key in a)
140
+ if isinstance(a, (list, tuple)) or isinstance(b, (list, tuple)):
141
+ return isinstance(a, (list, tuple)) and isinstance(b, (list, tuple)) and \
142
+ len(a) == len(b) and all(autoregressive_nests_equal(x, y) for x, y in zip(a, b))
143
+ if isinstance(a, np.ndarray) or isinstance(b, np.ndarray):
144
+ if not (isinstance(a, np.ndarray) and isinstance(b, np.ndarray) and a.shape == b.shape):
145
+ return False
146
+ # NaN leaves must equal themselves: this comparison backs the determinism checks, where
147
+ # NaN padding / running stats in a perfectly deterministic hook are legitimate.
148
+ if a.dtype.kind in 'fc' and b.dtype.kind in 'fc':
149
+ return bool(np.array_equal(a, b, equal_nan=True))
150
+ return bool(np.array_equal(a, b))
151
+ if isinstance(a, (float, np.floating)) and isinstance(b, (float, np.floating)) and \
152
+ math.isnan(a) and math.isnan(b):
153
+ return True
154
+ return bool(a == b)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.195.dev1
3
+ Version: 1.0.197.dev0
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -1,7 +1,7 @@
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=USxsP1ax2knqO1DXNMsmzzNCxWVdp5PtSdL1axVT330,14382
4
+ code_loader/contract/datasetclasses.py,sha256=rKitPlVyI9PZdAZHpH1q-0_s4Vs7oPg8Z659XeuAujM,13788
5
5
  code_loader/contract/enums.py,sha256=2q-IV_5g9lLE306DIbWA1c0tn5IhDtxsKxyV1x_Lreg,1671
6
6
  code_loader/contract/exceptions.py,sha256=jWqu5i7t-0IG0jGRsKF4DjJdrsdpJjIYpUkN1F4RiyQ,51
7
7
  code_loader/contract/mapping.py,sha256=sWJhpng-IkOzQnWQdMT5w2ZZ3X1Z_OOzSwCLXIS7oxE,1446
@@ -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=D-ahDW-1ZiB9wqPkiIMz8eOD6p_Z3spm5b_Mi8y0af0,48340
25
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=7hUDsG2YrRh_HgLmVidTvwi8xr4eH70r2MWmSWfY6aY,143870
26
- code_loader/leaploader.py,sha256=kYD2jousMGb0wEG9HdhzFYjRAekVYXMfZxX1S28tdns,71025
27
- code_loader/leaploaderbase.py,sha256=f6LsJeCAktTFU9U_c3NXddwOZjjchLtvbxl4eKMdwGc,6966
24
+ code_loader/inner_leap_binder/leapbinder.py,sha256=52nLuWLbOU7ljlABRRuS-e-hKscVlR5zxJTm5FPBdk8,54073
25
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=tW8QmjzkloQU37xryr958aVwyrVOm2FoSFL1LH0S8EU,176272
26
+ code_loader/leaploader.py,sha256=0YZhh2dCouQMCQAakqaPa-nRNrNn65q4rrLTwC8yjE0,68695
27
+ code_loader/leaploaderbase.py,sha256=MMuMv2014d9VM5FQgTsbUBL-9HOBJ4h6L67uF_7jhR4,10837
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=SPDQ4_f67hOIOgTfaTGlwBfbnusPrzH1OBYDLEndyr8,4413
32
+ code_loader/utils.py,sha256=gEJCKpDWf6p9_KoEz-0EGiJqxD6QfPgZN6zdKdtSAz8,6628
33
33
  code_loader/visualizers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
34
34
  code_loader/visualizers/default_visualizers.py,sha256=onRnLE_TXfgLN4o52hQIOOhUcFexGlqJ3xSpQDVLuZM,2604
35
- code_loader-1.0.195.dev1.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
- code_loader-1.0.195.dev1.dist-info/METADATA,sha256=FwRv4x1Z8Ymh7WQmu9sK_jQ6682oG2vay6K2AHbLSpU,1095
37
- code_loader-1.0.195.dev1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- code_loader-1.0.195.dev1.dist-info/RECORD,,
35
+ code_loader-1.0.197.dev0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
+ code_loader-1.0.197.dev0.dist-info/METADATA,sha256=WZ4kCsTIDPch7g1xrPJ5fy1EHEQoRGz9q_iygXHTM4s,1095
37
+ code_loader-1.0.197.dev0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
+ code_loader-1.0.197.dev0.dist-info/RECORD,,