code-loader 1.0.193.dev4__py3-none-any.whl → 1.0.194__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/inner_leap_binder/leapbinder_decorators.py +7 -17
- code_loader/leaploader.py +33 -9
- code_loader/leaploaderbase.py +7 -2
- {code_loader-1.0.193.dev4.dist-info → code_loader-1.0.194.dist-info}/METADATA +1 -1
- {code_loader-1.0.193.dev4.dist-info → code_loader-1.0.194.dist-info}/RECORD +7 -7
- {code_loader-1.0.193.dev4.dist-info → code_loader-1.0.194.dist-info}/LICENSE +0 -0
- {code_loader-1.0.193.dev4.dist-info → code_loader-1.0.194.dist-info}/WHEEL +0 -0
|
@@ -1730,6 +1730,8 @@ def _ndarray_leaves(value):
|
|
|
1730
1730
|
|
|
1731
1731
|
|
|
1732
1732
|
def _squeeze_leading_batch_axis(tensors_dict):
|
|
1733
|
+
if tensors_dict is None:
|
|
1734
|
+
return None
|
|
1733
1735
|
squeezed = {}
|
|
1734
1736
|
for key, value in tensors_dict.items():
|
|
1735
1737
|
if isinstance(value, np.ndarray) and value.ndim > 0 and value.shape[0] == 1:
|
|
@@ -2077,21 +2079,6 @@ def tensorleap_autoregressive_step(latent_space_aggregation: str = 'last_step'):
|
|
|
2077
2079
|
assert _nest_equal(value, second_inputs[key]), error_message
|
|
2078
2080
|
assert _nest_equal(first_state, second_state), error_message
|
|
2079
2081
|
|
|
2080
|
-
def _squeeze_test_batch_dim(tensors_dict):
|
|
2081
|
-
# Inside the integration test the model works on batch-1 tensors (this wrapper adds the
|
|
2082
|
-
# batch axis to returned inputs, and model outputs come back batched). The user's hook
|
|
2083
|
-
# body must see the same unbatched per-sample tensors it will see at engine runtime, so
|
|
2084
|
-
# strip the leading batch-1 axis before calling it.
|
|
2085
|
-
if tensors_dict is None:
|
|
2086
|
-
return None
|
|
2087
|
-
squeezed = {}
|
|
2088
|
-
for key, value in tensors_dict.items():
|
|
2089
|
-
if isinstance(value, np.ndarray) and value.ndim > 0 and value.shape[0] == 1:
|
|
2090
|
-
squeezed[key] = value[0]
|
|
2091
|
-
else:
|
|
2092
|
-
squeezed[key] = value
|
|
2093
|
-
return squeezed
|
|
2094
|
-
|
|
2095
2082
|
def inner_without_validate(sample_id, prev_inputs, prev_outputs, state, preprocess_response):
|
|
2096
2083
|
global _called_from_inside_tl_decorator
|
|
2097
2084
|
_called_from_inside_tl_decorator += 1
|
|
@@ -2129,8 +2116,11 @@ def tensorleap_autoregressive_step(latent_space_aggregation: str = 'last_step'):
|
|
|
2129
2116
|
loop_context.on_hook_call(sample_id, prev_inputs, prev_outputs, state,
|
|
2130
2117
|
preprocess_response)
|
|
2131
2118
|
if is_top_level_in_test:
|
|
2132
|
-
|
|
2133
|
-
|
|
2119
|
+
# The wrapper adds the batch axis to returned inputs and model outputs come back
|
|
2120
|
+
# batched; the hook body must see the same unbatched per-sample tensors it will
|
|
2121
|
+
# see at engine runtime.
|
|
2122
|
+
prev_inputs = _squeeze_leading_batch_axis(prev_inputs)
|
|
2123
|
+
prev_outputs = _squeeze_leading_batch_axis(prev_outputs)
|
|
2134
2124
|
|
|
2135
2125
|
_validate_input_args(sample_id, prev_inputs, prev_outputs, state, preprocess_response)
|
|
2136
2126
|
|
code_loader/leaploader.py
CHANGED
|
@@ -581,8 +581,8 @@ class LeapLoader(LeapLoaderBase):
|
|
|
581
581
|
return handler.input_shapes
|
|
582
582
|
|
|
583
583
|
def run_simulation(self, sim_name, params=None, n_samples=1, seed=0,
|
|
584
|
-
sample_ids=None, extend_preprocess=True):
|
|
585
|
-
# type: (str, Optional[Dict[str, Any]], int, int, Optional[List[str]], bool) -> Dict[str, Any]
|
|
584
|
+
sample_ids=None, extend_preprocess=True, allow_partial=False):
|
|
585
|
+
# type: (str, Optional[Dict[str, Any]], int, int, Optional[List[str]], bool, bool) -> Dict[str, Any]
|
|
586
586
|
# extend_preprocess=True (default): also extend preprocess_result[additional] with the
|
|
587
587
|
# new synthetic sample_ids (producer-side behavior — synthetic worker needs this for
|
|
588
588
|
# enumeration / data_length tracking). Pass False from consumer-side populators that
|
|
@@ -609,19 +609,30 @@ class LeapLoader(LeapLoaderBase):
|
|
|
609
609
|
for sample_id in original_sample_ids:
|
|
610
610
|
for handler in global_leap_binder.setup_container.inputs:
|
|
611
611
|
per_encoder[handler.name].append(handler.function(sample_id, sim_preprocess))
|
|
612
|
-
encoded = {
|
|
612
|
+
encoded = {
|
|
613
|
+
name: np.stack(arrays) if arrays else np.empty((0,), dtype=np.float32)
|
|
614
|
+
for name, arrays in per_encoder.items()
|
|
615
|
+
}
|
|
613
616
|
if sample_ids is not None:
|
|
614
|
-
if len(sample_ids) != len(original_sample_ids):
|
|
615
|
-
raise ValueError(
|
|
616
|
-
"sample_ids length ({}) does not match simulation output length ({})".format(
|
|
617
|
-
len(sample_ids), len(original_sample_ids)
|
|
618
|
-
)
|
|
619
|
-
)
|
|
620
617
|
for sid in sample_ids:
|
|
621
618
|
if not isinstance(sid, str):
|
|
622
619
|
raise TypeError(
|
|
623
620
|
"All sample_ids must be of type str. Got: {}".format(type(sid))
|
|
624
621
|
)
|
|
622
|
+
if len(sample_ids) != len(original_sample_ids):
|
|
623
|
+
if not allow_partial:
|
|
624
|
+
raise ValueError(
|
|
625
|
+
"sample_ids length ({}) does not match simulation output length ({})".format(
|
|
626
|
+
len(sample_ids), len(original_sample_ids)
|
|
627
|
+
)
|
|
628
|
+
)
|
|
629
|
+
n_bound = min(len(sample_ids), len(original_sample_ids))
|
|
630
|
+
sample_ids = list(sample_ids)[:n_bound]
|
|
631
|
+
original_sample_ids = original_sample_ids[:n_bound]
|
|
632
|
+
# Over-generation trims sample_ids/original_sample_ids above but encoded was
|
|
633
|
+
# stacked from the full simulation output; slice it too so the encoded batch dim
|
|
634
|
+
# stays 1:1 with the returned sample_ids.
|
|
635
|
+
encoded = {name: arr[:n_bound] for name, arr in encoded.items()}
|
|
625
636
|
for synth_id, original_local_id in zip(sample_ids, original_sample_ids):
|
|
626
637
|
self._synthetic_lookup[synth_id] = (sim_preprocess, original_local_id)
|
|
627
638
|
if extend_preprocess:
|
|
@@ -631,6 +642,19 @@ class LeapLoader(LeapLoaderBase):
|
|
|
631
642
|
returned_sample_ids = original_sample_ids
|
|
632
643
|
return {"encoded": encoded, "sample_ids": returned_sample_ids}
|
|
633
644
|
|
|
645
|
+
def prune_synthetic_lookup(self, keep_ids):
|
|
646
|
+
# type: (List[str]) -> None
|
|
647
|
+
# Keep only the given synthetic sample_ids in the in-memory lookup and
|
|
648
|
+
# drop the rest, so preprocess responses don't accumulate across many
|
|
649
|
+
# run_simulation calls (e.g. a synthetic calibration loop keeps only its
|
|
650
|
+
# running top-K trials). Keep-set semantics (rather than evict-list) so
|
|
651
|
+
# the caller can bound the lookup to a known-good set each iteration
|
|
652
|
+
# without tracking everything it ever generated.
|
|
653
|
+
keep = set(keep_ids)
|
|
654
|
+
self._synthetic_lookup = {
|
|
655
|
+
sid: entry for sid, entry in self._synthetic_lookup.items() if sid in keep
|
|
656
|
+
}
|
|
657
|
+
|
|
634
658
|
def _extend_additional_preprocess(self, new_sample_ids: List[str]) -> None:
|
|
635
659
|
if self._preprocess_result_cached is None:
|
|
636
660
|
self._preprocess_result()
|
code_loader/leaploaderbase.py
CHANGED
|
@@ -223,8 +223,13 @@ class LeapLoaderBase:
|
|
|
223
223
|
pass
|
|
224
224
|
|
|
225
225
|
@abstractmethod
|
|
226
|
-
def run_simulation(self, sim_name, params=None, n_samples=1, seed=0, sample_ids=None
|
|
227
|
-
|
|
226
|
+
def run_simulation(self, sim_name, params=None, n_samples=1, seed=0, sample_ids=None,
|
|
227
|
+
extend_preprocess=True, allow_partial=False):
|
|
228
|
+
# type: (str, Optional[Dict[str, Any]], int, int, Optional[List[str]], bool, bool) -> Dict[str, Any]
|
|
229
|
+
pass
|
|
230
|
+
|
|
231
|
+
def prune_synthetic_lookup(self, keep_ids):
|
|
232
|
+
# type: (List[str]) -> None
|
|
228
233
|
pass
|
|
229
234
|
|
|
230
235
|
def is_custom_latent_space(self) -> bool:
|
|
@@ -22,9 +22,9 @@ 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=
|
|
26
|
-
code_loader/leaploader.py,sha256=
|
|
27
|
-
code_loader/leaploaderbase.py,sha256=
|
|
25
|
+
code_loader/inner_leap_binder/leapbinder_decorators.py,sha256=72VAtRItuIqLlOruPX5i6ZD8q8adljDJWgMfMYG5ZGM,175995
|
|
26
|
+
code_loader/leaploader.py,sha256=ME1Ypq9VV3o9XXOCV6voDWWVP0gB4Z0LoJh6u79qDYY,68370
|
|
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
|
|
@@ -32,7 +32,7 @@ code_loader/plot_functions/visualize.py,sha256=gsBAYYkwMh7jIpJeDMPS8G4CW-pxwx6Lz
|
|
|
32
32
|
code_loader/utils.py,sha256=1XLY5hNQaOsqXeUIooGs6KXV0E1edeiQyxAdnG3eiy0,6338
|
|
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.
|
|
36
|
-
code_loader-1.0.
|
|
37
|
-
code_loader-1.0.
|
|
38
|
-
code_loader-1.0.
|
|
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,,
|
|
File without changes
|
|
File without changes
|