code-loader 1.0.165.dev2__tar.gz → 1.0.165.dev3__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.
Files changed (36) hide show
  1. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/PKG-INFO +1 -1
  2. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/inner_leap_binder/leapbinder_decorators.py +103 -39
  3. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/pyproject.toml +1 -1
  4. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/LICENSE +0 -0
  5. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/README.md +0 -0
  6. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/__init__.py +0 -0
  7. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/contract/__init__.py +0 -0
  8. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/contract/datasetclasses.py +0 -0
  9. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/contract/enums.py +0 -0
  10. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/contract/exceptions.py +0 -0
  11. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/contract/mapping.py +0 -0
  12. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/contract/responsedataclasses.py +0 -0
  13. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/contract/visualizer_classes.py +0 -0
  14. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/default_losses.py +0 -0
  15. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/default_metrics.py +0 -0
  16. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/__init__.py +0 -0
  17. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/api.py +0 -0
  18. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/cli_config_utils.py +0 -0
  19. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/client.py +0 -0
  20. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/epoch.py +0 -0
  21. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/experiment.py +0 -0
  22. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/experiment_context.py +0 -0
  23. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/types.py +0 -0
  24. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/utils.py +0 -0
  25. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/experiment_api/workingspace_config_utils.py +0 -0
  26. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/inner_leap_binder/__init__.py +0 -0
  27. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/inner_leap_binder/leapbinder.py +0 -0
  28. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/leaploader.py +0 -0
  29. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/leaploaderbase.py +0 -0
  30. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/mixpanel_tracker.py +0 -0
  31. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/plot_functions/__init__.py +0 -0
  32. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/plot_functions/plot_functions.py +0 -0
  33. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/plot_functions/visualize.py +0 -0
  34. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/utils.py +0 -0
  35. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/visualizers/__init__.py +0 -0
  36. {code_loader-1.0.165.dev2 → code_loader-1.0.165.dev3}/code_loader/visualizers/default_visualizers.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: code-loader
3
- Version: 1.0.165.dev2
3
+ Version: 1.0.165.dev3
4
4
  Summary:
5
5
  Home-page: https://github.com/tensorleap/code-loader
6
6
  License: MIT
@@ -45,6 +45,7 @@ _PARAM_DEFAULT_FUNCS: DefaultDict[str, Set[str]] = defaultdict(set)
45
45
  # param_name -> default_value used (repr-able)
46
46
  _PARAM_DEFAULT_VALUE: Dict[str, Any] = {}
47
47
  _PARAM_DEFAULT_DOCS: Dict[str, str] = {}
48
+ _PARAM_DEFAULT_MESSAGES: DefaultDict[str, Set[str]] = defaultdict(set)
48
49
 
49
50
 
50
51
  def get_entry_script_path() -> str:
@@ -67,6 +68,7 @@ def store_warning_by_param(
67
68
  user_func_name: str,
68
69
  default_value: Any,
69
70
  link_to_docs: str = None,
71
+ custom_message: Optional[str] = None,
70
72
  ) -> None:
71
73
  _PARAM_DEFAULT_FUNCS[param_name].add(user_func_name)
72
74
 
@@ -76,6 +78,9 @@ def store_warning_by_param(
76
78
  if link_to_docs and param_name not in _PARAM_DEFAULT_DOCS:
77
79
  _PARAM_DEFAULT_DOCS[param_name] = link_to_docs
78
80
 
81
+ if custom_message:
82
+ _PARAM_DEFAULT_MESSAGES[param_name].add(custom_message)
83
+
79
84
 
80
85
  def _get_param_default_warnings() -> Dict[str, Dict[str, Any]]:
81
86
  out: Dict[str, Dict[str, Any]] = {}
@@ -84,6 +89,7 @@ def _get_param_default_warnings() -> Dict[str, Dict[str, Any]]:
84
89
  "default_value": _PARAM_DEFAULT_VALUE.get(p, None),
85
90
  "funcs": set(funcs),
86
91
  "link_to_docs": _PARAM_DEFAULT_DOCS.get(p),
92
+ "messages": sorted(_PARAM_DEFAULT_MESSAGES.get(p, set())),
87
93
  }
88
94
  return out
89
95
 
@@ -530,8 +536,6 @@ def tensorleap_custom_metric(name: str,
530
536
  ConfusionMatrixCallableInterfaceMultiArgs]):
531
537
  nonlocal direction
532
538
 
533
- direction_was_provided = direction is not _UNSET
534
-
535
539
  def _validate_decorators_signature():
536
540
  err_message = f"{user_function.__name__} validation failed.\n"
537
541
  if not isinstance(name, str):
@@ -678,28 +682,38 @@ def tensorleap_custom_metric(name: str,
678
682
  (f'{user_function.__name__}() validation failed: '
679
683
  f'Keys in the return dict should be of type str. Got {type(key)}.')
680
684
 
681
- assert direction is _UNSET or isinstance(direction, dict), \
682
- (f'{user_function.__name__}() validation failed: '
683
- f'direction should be a dict when using dict results. Got {type(direction)}.') #TODO - remove this assertion so a single value would controll all directions
684
-
685
685
  if isinstance(direction, dict):
686
686
  for direction_key in direction:
687
687
  assert direction_key in result, \
688
688
  (f'{user_function.__name__}() validation failed: '
689
689
  f'Keys in the direction mapping should be part of result keys. Got key {direction_key}.')
690
690
 
691
- if compute_insights is not None:
692
- assert isinstance(compute_insights, dict), \
693
- (f'{user_function.__name__}() validation failed: '
694
- f'compute_insights should be dict if using the dict results. Got {type(compute_insights)}.') #TODO - remove this assertion so a single value would controll all compute_insights
691
+ if isinstance(compute_insights, dict):
692
+ for ci_key in compute_insights:
693
+ assert ci_key in result, \
694
+ (f'{user_function.__name__}() validation failed: '
695
+ f'Keys in the compute_insights mapping should be part of result keys. Got key {ci_key}.')
695
696
 
696
- if isinstance(compute_insights, dict):
697
- for ci_key in compute_insights:
698
- assert ci_key in result, \
699
- (f'{user_function.__name__}() validation failed: '
700
- f'Keys in the compute_insights mapping should be part of result keys. Got key {ci_key}.')
697
+ if direction is _UNSET:
698
+ effective_direction = {}
699
+ elif isinstance(direction, dict):
700
+ effective_direction = direction
701
+ else:
702
+ effective_direction = {}
703
+ if not _call_from_tl_platform:
704
+ # TODO- remove this warning when engine supports high level direction setting for all submetrics
705
+ store_warning_by_param(
706
+ param_name="direction",
707
+ user_func_name=user_function.__name__,
708
+ default_value=MetricDirection.Downward,
709
+ link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/custom-metrics",
710
+ custom_message=(
711
+ f"'direction': expected Dict[str, MetricDirection] for dict output, "
712
+ f"got {type(direction).__name__}; reverted to default per sub-metric "
713
+ f"({MetricDirection.Downward.name})."
714
+ )
715
+ )
701
716
 
702
- effective_direction = {} if direction is _UNSET else direction
703
717
  defaulted_direction_keys = result_keys.difference(effective_direction.keys())
704
718
 
705
719
  if defaulted_direction_keys:
@@ -708,38 +722,88 @@ def tensorleap_custom_metric(name: str,
708
722
  leap_binder.setup_container.metrics[-1].metric_handler_data.direction = effective_direction
709
723
 
710
724
  if defaulted_direction_keys and not _call_from_tl_platform:
711
- effective_compute_insights = compute_insights or {}
725
+ if compute_insights is None:
726
+ effective_compute_insights = {}
727
+ elif isinstance(compute_insights, dict):
728
+ effective_compute_insights = compute_insights
729
+ else:
730
+ effective_compute_insights = {}
712
731
  warning_keys = {key for key in defaulted_direction_keys if effective_compute_insights.get(key, True)}
713
732
  if warning_keys:
714
733
  store_warning_by_param(
715
- param_name=f"direction[{warning_keys}]",
734
+ param_name=f"direction[{sorted(warning_keys)}]",
716
735
  user_func_name=user_function.__name__,
717
736
  default_value=MetricDirection.Downward,
718
737
  link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/custom-metrics"
719
738
  )
720
739
 
740
+ if compute_insights is not None and not isinstance(compute_insights, dict) and not _call_from_tl_platform:
741
+ # TODO- remove this warning when engine supports high level compute_insights setting for all submetrics
742
+ store_warning_by_param(
743
+ param_name="compute_insights",
744
+ user_func_name=user_function.__name__,
745
+ default_value=None,
746
+ link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/custom-metrics",
747
+ custom_message=(
748
+ f"'compute_insights': expected Dict[str, bool] for dict output, "
749
+ f"got {type(compute_insights).__name__}; reverted to default (None)."
750
+ )
751
+ )
752
+
753
+ if compute_insights is None:
754
+ effective_compute_insights_for_handler = None
755
+ elif isinstance(compute_insights, dict):
756
+ effective_compute_insights_for_handler = compute_insights
757
+ else:
758
+ effective_compute_insights_for_handler = None
759
+ leap_binder.setup_container.metrics[-1].metric_handler_data.compute_insights = effective_compute_insights_for_handler
760
+
721
761
  else:
722
762
  _validate_single_metric(result)
723
763
 
724
- if compute_insights is not None:
725
- assert isinstance(compute_insights, bool), \
726
- (f'{user_function.__name__}() validation failed: '
727
- f'compute_insights should be boolean. Got {type(compute_insights)}.')
728
- if direction is not _UNSET:
729
- assert isinstance(direction, MetricDirection), \
730
- (f'{user_function.__name__}() validation failed: '
731
- f'direction should be a MetricDirection when using a single result. Got {type(direction)}.')
732
-
764
+ if compute_insights is None or isinstance(compute_insights, bool):
765
+ effective_single_compute_insights = compute_insights
733
766
  else:
734
- direction = MetricDirection.Downward
735
- leap_binder.setup_container.metrics[-1].metric_handler_data.direction = direction
736
- if not _call_from_tl_platform and compute_insights is not False:
767
+ effective_single_compute_insights = None
768
+ if not _call_from_tl_platform:
769
+ store_warning_by_param(
770
+ param_name="compute_insights",
771
+ user_func_name=user_function.__name__,
772
+ default_value=None,
773
+ link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/custom-metrics",
774
+ custom_message=(
775
+ f"'compute_insights': expected bool for single-valued output, "
776
+ f"got {type(compute_insights).__name__}; reverted to default (None)."
777
+ )
778
+ )
779
+
780
+ if direction is _UNSET:
781
+ effective_single_direction = MetricDirection.Downward
782
+ if not _call_from_tl_platform and effective_single_compute_insights is not False:
737
783
  store_warning_by_param(
738
784
  param_name="direction",
739
785
  user_func_name=user_function.__name__,
740
- default_value=direction,
786
+ default_value=effective_single_direction,
741
787
  link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/custom-metrics"
742
788
  )
789
+ elif isinstance(direction, MetricDirection):
790
+ effective_single_direction = direction
791
+ else:
792
+ effective_single_direction = MetricDirection.Downward
793
+ if not _call_from_tl_platform and effective_single_compute_insights is not False:
794
+ store_warning_by_param(
795
+ param_name="direction",
796
+ user_func_name=user_function.__name__,
797
+ default_value=effective_single_direction,
798
+ link_to_docs="https://docs.tensorleap.ai/tensorleap-integration/writing-integration-code/custom-metrics",
799
+ custom_message=(
800
+ f"'direction': expected MetricDirection for single-valued output, "
801
+ f"got {type(direction).__name__}; reverted to default ({MetricDirection.Downward.name})."
802
+ )
803
+ )
804
+
805
+ leap_binder.setup_container.metrics[-1].metric_handler_data.direction = effective_single_direction
806
+ leap_binder.setup_container.metrics[-1].metric_handler_data.compute_insights = effective_single_compute_insights
743
807
 
744
808
  @functools.wraps(user_function)
745
809
  def inner_without_validate(*args, **kwargs):
@@ -1700,12 +1764,17 @@ def tensorleap_status_table():
1700
1764
  default_value = data[param_name]["default_value"]
1701
1765
  funcs = ", ".join(sorted(data[param_name]["funcs"]))
1702
1766
  dv = _format_default_value(default_value)
1767
+ messages = data[param_name].get("messages", [])
1703
1768
 
1704
1769
  docs_link = data[param_name].get("link_to_docs")
1705
1770
  docs_part = f" {_link(docs_link)}" if docs_link else ""
1706
- print(
1707
- f" ⚠️ Parameter '{param_name}' defaults to {dv} in the following functions: [{funcs}]. "
1708
- f"For more information, check {docs_part}")
1771
+ if messages:
1772
+ for msg in messages:
1773
+ print(f" ⚠️ {msg} (functions: [{funcs}]).")
1774
+ else:
1775
+ print(
1776
+ f" ⚠️ Parameter '{param_name}' defaults to {dv} in the following functions: [{funcs}]. "
1777
+ f"For more information, check {docs_part}")
1709
1778
  print("\nIf this isn’t the intended behaviour, set them explicitly.")
1710
1779
 
1711
1780
  def _print_table():
@@ -1795,8 +1864,3 @@ def tensorleap_status_table():
1795
1864
 
1796
1865
  if not _call_from_tl_platform:
1797
1866
  set_current, update_env_params_func = tensorleap_status_table()
1798
-
1799
-
1800
-
1801
-
1802
-
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "code-loader"
3
- version = "1.0.165.dev2"
3
+ version = "1.0.165.dev3"
4
4
  description = ""
5
5
  authors = ["dorhar <doron.harnoy@tensorleap.ai>"]
6
6
  license = "MIT"