code-loader 1.0.193.dev3__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.
@@ -299,8 +299,19 @@ def tensorleap_integration_test():
299
299
  def inner(*args, **kwargs):
300
300
  if not _call_from_tl_platform:
301
301
  set_current('tensorleap_integration_test')
302
+ # Keyword calls must work with the user function's OWN parameter names — the local
303
+ # run template calls integration_test(sample_id=..., preprocess=...) against a
304
+ # signature the user chose, not the canonical placeholder names.
305
+ expected_names = inspect.getfullargspec(integration_test_function)[0][:2]
306
+ if len(expected_names) < 2:
307
+ expected_names = ['idx', 'preprocess']
302
308
  validate_args_structure(*args, types_order=[Union[int, str], PreprocessResponse],
303
- func_name='integration_test', expected_names=["idx", "preprocess"], **kwargs)
309
+ func_name='integration_test', expected_names=expected_names,
310
+ **kwargs)
311
+ sample_id, preprocess_response = (
312
+ args[i] if i < len(args) else kwargs[name]
313
+ for i, name in enumerate(expected_names))
314
+ args, kwargs = (sample_id, preprocess_response), {}
304
315
  _validate_input_args(*args, **kwargs)
305
316
 
306
317
  global _called_from_inside_tl_integration_test_decorator, _integration_test_started
@@ -433,7 +444,7 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
433
444
  pass
434
445
 
435
446
  @lru_cache()
436
- def inner(*args, **kwargs):
447
+ def _cached_inner(*args, **kwargs):
437
448
  if not _call_from_tl_platform:
438
449
  set_current('tensorleap_load_model')
439
450
  validate_args_structure(*args, types_order=[],
@@ -587,12 +598,20 @@ def tensorleap_load_model(prediction_types: Optional[List[PredictionTypeHandler]
587
598
  return self.model.get_inputs()
588
599
 
589
600
  model_placeholder = ModelPlaceholder(prediction_types)
590
- global _last_loaded_model
591
- _last_loaded_model = model_placeholder
592
601
  if not _call_from_tl_platform:
593
602
  update_env_params_func("tensorleap_load_model", "v")
594
603
  return model_placeholder
595
604
 
605
+ def inner(*args, **kwargs):
606
+ model_placeholder = _cached_inner(*args, **kwargs)
607
+ # Re-assert on every call, outside the cache: each mapping rerun's load_model
608
+ # overwrites this global with its mapping placeholder, and on a cache hit the
609
+ # body above never runs — a second integration test would otherwise fail the
610
+ # model loop's identity check against the stale mapping placeholder.
611
+ global _last_loaded_model
612
+ _last_loaded_model = model_placeholder
613
+ return model_placeholder
614
+
596
615
  def mapping_inner():
597
616
  class ModelOutputPlaceholder:
598
617
  def __init__(self):
@@ -1711,6 +1730,8 @@ def _ndarray_leaves(value):
1711
1730
 
1712
1731
 
1713
1732
  def _squeeze_leading_batch_axis(tensors_dict):
1733
+ if tensors_dict is None:
1734
+ return None
1714
1735
  squeezed = {}
1715
1736
  for key, value in tensors_dict.items():
1716
1737
  if isinstance(value, np.ndarray) and value.ndim > 0 and value.shape[0] == 1:
@@ -2058,21 +2079,6 @@ def tensorleap_autoregressive_step(latent_space_aggregation: str = 'last_step'):
2058
2079
  assert _nest_equal(value, second_inputs[key]), error_message
2059
2080
  assert _nest_equal(first_state, second_state), error_message
2060
2081
 
2061
- def _squeeze_test_batch_dim(tensors_dict):
2062
- # Inside the integration test the model works on batch-1 tensors (this wrapper adds the
2063
- # batch axis to returned inputs, and model outputs come back batched). The user's hook
2064
- # body must see the same unbatched per-sample tensors it will see at engine runtime, so
2065
- # strip the leading batch-1 axis before calling it.
2066
- if tensors_dict is None:
2067
- return None
2068
- squeezed = {}
2069
- for key, value in tensors_dict.items():
2070
- if isinstance(value, np.ndarray) and value.ndim > 0 and value.shape[0] == 1:
2071
- squeezed[key] = value[0]
2072
- else:
2073
- squeezed[key] = value
2074
- return squeezed
2075
-
2076
2082
  def inner_without_validate(sample_id, prev_inputs, prev_outputs, state, preprocess_response):
2077
2083
  global _called_from_inside_tl_decorator
2078
2084
  _called_from_inside_tl_decorator += 1
@@ -2110,8 +2116,11 @@ def tensorleap_autoregressive_step(latent_space_aggregation: str = 'last_step'):
2110
2116
  loop_context.on_hook_call(sample_id, prev_inputs, prev_outputs, state,
2111
2117
  preprocess_response)
2112
2118
  if is_top_level_in_test:
2113
- prev_inputs = _squeeze_test_batch_dim(prev_inputs)
2114
- prev_outputs = _squeeze_test_batch_dim(prev_outputs)
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)
2115
2124
 
2116
2125
  _validate_input_args(sample_id, prev_inputs, prev_outputs, state, preprocess_response)
2117
2126
 
@@ -3376,6 +3385,12 @@ def tensorleap_status_table():
3376
3385
  if not started_from("leap_integration.py"):
3377
3386
  return
3378
3387
 
3388
+ if leap_binder.setup_container.autoregressive_step is not None:
3389
+ # Input encoders are forbidden in autoregressive integrations — the step hook is
3390
+ # the sole source of model inputs — so the row is not applicable: it must not be
3391
+ # printed, gate readiness, or be recommended as a next step.
3392
+ table[:] = [row for row in table if row["name"] != "tensorleap_input_encoder"]
3393
+
3379
3394
  ready_mess = "\nAll parts have been successfully set. If no errors accured, you can now push the project to the Tensorleap system."
3380
3395
  not_ready_mess = "\nSome mandatory components have not yet been added to the Integration test. Recommended next interface to add is: "
3381
3396
  mandatory_ready_mess = "\nAll mandatory parts have been successfully set. If no errors accured, you can now push the project to the Tensorleap system or continue to the next optional reccomeded interface,adding: "
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 = {name: np.stack(arrays) for name, arrays in per_encoder.items()}
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()
@@ -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
- # type: (str, Optional[Dict[str, Any]], int, int, Optional[List[str]]) -> Dict[str, Any]
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:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.193.dev3
3
+ Version: 1.0.194
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -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=EMg6o1wDl3HMFm8n6kEjyprXUX1UKgcOZjNJQCBSu_I,174865
26
- code_loader/leaploader.py,sha256=sx-BzeVG3qt54S2uF5VbBi2xL0x70AIFN1to6OtjBYU,66979
27
- code_loader/leaploaderbase.py,sha256=ncKEWsVv_1Vhtgl8Dqgt4ampxTzOj5nVitGJwQQtTc4,10561
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.193.dev3.dist-info/LICENSE,sha256=qIwWjdspQeSMTtnFZBC8MuT-95L02FPvzRUdWFxrwJY,1067
36
- code_loader-1.0.193.dev3.dist-info/METADATA,sha256=3rGLwq82vR91AHkFJXYOaCCe_KRiwDBVWlkZYqWMKk4,1095
37
- code_loader-1.0.193.dev3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
38
- code_loader-1.0.193.dev3.dist-info/RECORD,,
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,,