code-loader 1.0.194__py3-none-any.whl → 1.0.195.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.
@@ -1933,9 +1933,10 @@ def tensorleap_autoregressive_step(latent_space_aggregation: str = 'last_step'):
1933
1933
  state returned by the previous call, and return the next step's full input dict together with
1934
1934
  the updated state; returning (None, state) ends the chain — the terminating call still
1935
1935
  returns state, so the final step participates in state aggregation. State is never fed to
1936
- the model; it may be any nest of dicts/lists holding numpy arrays, numbers, strings or bools,
1937
- and it rides the platform queue on every step accumulate reductions, not raw per-step
1938
- tensors. The hook must be stateless and deterministically seeded (seed stochasticity from
1936
+ the model; any picklable nest of builtin/numpy values works (dicts, lists, tuples, sets,
1937
+ numbers, strings, arrays not user-defined classes, lambdas or open resources, since the
1938
+ platform deserializes state without the integration code), and it rides the platform queue
1939
+ on every step — accumulate reductions, not raw per-step tensors. The hook must be stateless and deterministically seeded (seed stochasticity from
1939
1940
  sample_id) — the engine replays steps after crash recovery and relies on identical results.
1940
1941
 
1941
1942
  latent_space_aggregation ('last_step' | 'mean') declares how the chain's latent-space
code_loader/utils.py CHANGED
@@ -1,4 +1,6 @@
1
+ import io
1
2
  import math
3
+ import pickle
2
4
  import sys
3
5
  from pathlib import Path
4
6
  from types import TracebackType
@@ -104,27 +106,31 @@ def get_metadata_type_from_variable(variable: Union[Optional[str], int, bool, Op
104
106
 
105
107
 
106
108
 
107
- AUTOREGRESSIVE_STATE_LEAF_TYPES = (np.ndarray, np.generic, int, float, str, bool, type(None))
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')
108
122
 
109
123
 
110
124
  def validate_autoregressive_state_types(value: Any, path: str = 'state') -> None:
111
- if isinstance(value, dict):
112
- for key, item in value.items():
113
- if not isinstance(key, str):
114
- raise AssertionError(
115
- f'autoregressive state validation failed: dict key {key!r} at {path} must be '
116
- f'a string. Got {type(key).__name__}.')
117
- validate_autoregressive_state_types(item, f'{path}[{key!r}]')
118
- return
119
- if isinstance(value, (list, tuple)):
120
- for i, item in enumerate(value):
121
- validate_autoregressive_state_types(item, f'{path}[{i}]')
122
- return
123
- if not isinstance(value, AUTOREGRESSIVE_STATE_LEAF_TYPES):
125
+ try:
126
+ _EngineSafeUnpickler(io.BytesIO(pickle.dumps(value))).load()
127
+ except Exception as e:
124
128
  raise AssertionError(
125
- f'autoregressive state validation failed: {path} holds a {type(value).__name__}. '
126
- f'State must be built only from numpy arrays, numbers, strings, bools and nests of '
127
- f'dicts/lists of thoseit is serialized to the platform queue on every chain step.')
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 codeany 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
128
134
 
129
135
 
130
136
  def autoregressive_nests_equal(a: Any, b: Any) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.194
3
+ Version: 1.0.195.dev0
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -22,17 +22,17 @@ 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=4cbSEbN6vVwjFUMxDEksxk1VSCip2ntLB32RxA81_JE,53194
25
- code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=72VAtRItuIqLlOruPX5i6ZD8q8adljDJWgMfMYG5ZGM,175995
25
+ code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=eHdSRCYtfkHtq7NSlS4bF92TU8RGRzZ1gbb3ULeEV2c,176145
26
26
  code_loader/leaploader.py,sha256=ME1Ypq9VV3o9XXOCV6voDWWVP0gB4Z0LoJh6u79qDYY,68370
27
27
  code_loader/leaploaderbase.py,sha256=PvBU_2OQqBfJLDMsbK1s372954eYr4Y3O4r18y5S7uY,10739
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=1XLY5hNQaOsqXeUIooGs6KXV0E1edeiQyxAdnG3eiy0,6338
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.194.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
- code_loader-1.0.194.dist-info/METADATA,sha256=gST9jxDkW0k5K19MNBwKNE_6FkoTHUPAyspZ1YZiJbA,1090
37
- code_loader-1.0.194.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- code_loader-1.0.194.dist-info/RECORD,,
35
+ code_loader-1.0.195.dev0.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
+ code_loader-1.0.195.dev0.dist-info/METADATA,sha256=q8UczKAxuYThEseqP4aXcS5ET0DfpjPaRmIy4aKDl1I,1095
37
+ code_loader-1.0.195.dev0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
+ code_loader-1.0.195.dev0.dist-info/RECORD,,