wandb 0.16.5__py3-none-any.whl → 0.17.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. package_readme.md +95 -0
  2. wandb/__init__.py +2 -3
  3. wandb/agents/pyagent.py +0 -1
  4. wandb/analytics/sentry.py +2 -1
  5. wandb/apis/importers/internals/internal.py +0 -1
  6. wandb/apis/importers/internals/protocols.py +30 -56
  7. wandb/apis/importers/mlflow.py +13 -26
  8. wandb/apis/importers/wandb.py +8 -14
  9. wandb/apis/internal.py +0 -3
  10. wandb/apis/public/api.py +55 -3
  11. wandb/apis/public/artifacts.py +1 -0
  12. wandb/apis/public/files.py +1 -0
  13. wandb/apis/public/history.py +1 -0
  14. wandb/apis/public/jobs.py +17 -4
  15. wandb/apis/public/projects.py +1 -0
  16. wandb/apis/public/reports.py +1 -0
  17. wandb/apis/public/runs.py +15 -17
  18. wandb/apis/public/sweeps.py +1 -0
  19. wandb/apis/public/teams.py +1 -0
  20. wandb/apis/public/users.py +1 -0
  21. wandb/apis/reports/v1/_blocks.py +3 -7
  22. wandb/apis/reports/v2/gql.py +1 -0
  23. wandb/apis/reports/v2/interface.py +3 -4
  24. wandb/apis/reports/v2/internal.py +5 -8
  25. wandb/cli/cli.py +95 -22
  26. wandb/data_types.py +9 -6
  27. wandb/docker/__init__.py +1 -1
  28. wandb/env.py +38 -8
  29. wandb/errors/__init__.py +5 -0
  30. wandb/errors/term.py +10 -2
  31. wandb/filesync/step_checksum.py +1 -4
  32. wandb/filesync/step_prepare.py +4 -24
  33. wandb/filesync/step_upload.py +4 -106
  34. wandb/filesync/upload_job.py +0 -76
  35. wandb/integration/catboost/catboost.py +1 -1
  36. wandb/integration/fastai/__init__.py +1 -0
  37. wandb/integration/huggingface/resolver.py +2 -2
  38. wandb/integration/keras/__init__.py +1 -0
  39. wandb/integration/keras/callbacks/metrics_logger.py +1 -1
  40. wandb/integration/keras/keras.py +7 -7
  41. wandb/integration/langchain/wandb_tracer.py +1 -0
  42. wandb/integration/lightning/fabric/logger.py +1 -3
  43. wandb/integration/metaflow/metaflow.py +41 -6
  44. wandb/integration/openai/fine_tuning.py +77 -40
  45. wandb/integration/prodigy/prodigy.py +1 -1
  46. wandb/old/summary.py +1 -1
  47. wandb/plot/confusion_matrix.py +1 -1
  48. wandb/plot/pr_curve.py +2 -1
  49. wandb/plot/roc_curve.py +2 -1
  50. wandb/{plots → plot}/utils.py +13 -25
  51. wandb/proto/v3/wandb_internal_pb2.py +364 -332
  52. wandb/proto/v3/wandb_settings_pb2.py +2 -2
  53. wandb/proto/v3/wandb_telemetry_pb2.py +10 -10
  54. wandb/proto/v4/wandb_internal_pb2.py +322 -316
  55. wandb/proto/v4/wandb_settings_pb2.py +2 -2
  56. wandb/proto/v4/wandb_telemetry_pb2.py +10 -10
  57. wandb/proto/wandb_deprecated.py +7 -1
  58. wandb/proto/wandb_internal_codegen.py +3 -29
  59. wandb/sdk/artifacts/artifact.py +51 -20
  60. wandb/sdk/artifacts/artifact_download_logger.py +1 -0
  61. wandb/sdk/artifacts/artifact_file_cache.py +18 -4
  62. wandb/sdk/artifacts/artifact_instance_cache.py +1 -0
  63. wandb/sdk/artifacts/artifact_manifest.py +1 -0
  64. wandb/sdk/artifacts/artifact_manifest_entry.py +7 -3
  65. wandb/sdk/artifacts/artifact_manifests/artifact_manifest_v1.py +1 -0
  66. wandb/sdk/artifacts/artifact_saver.py +18 -27
  67. wandb/sdk/artifacts/artifact_state.py +1 -0
  68. wandb/sdk/artifacts/artifact_ttl.py +1 -0
  69. wandb/sdk/artifacts/exceptions.py +1 -0
  70. wandb/sdk/artifacts/storage_handlers/azure_handler.py +1 -0
  71. wandb/sdk/artifacts/storage_handlers/gcs_handler.py +13 -18
  72. wandb/sdk/artifacts/storage_handlers/http_handler.py +1 -0
  73. wandb/sdk/artifacts/storage_handlers/local_file_handler.py +1 -0
  74. wandb/sdk/artifacts/storage_handlers/multi_handler.py +1 -0
  75. wandb/sdk/artifacts/storage_handlers/s3_handler.py +5 -3
  76. wandb/sdk/artifacts/storage_handlers/tracking_handler.py +1 -0
  77. wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +1 -0
  78. wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +1 -0
  79. wandb/sdk/artifacts/storage_policies/wandb_storage_policy.py +3 -42
  80. wandb/sdk/artifacts/storage_policy.py +2 -12
  81. wandb/sdk/data_types/_dtypes.py +8 -8
  82. wandb/sdk/data_types/base_types/media.py +3 -6
  83. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +3 -1
  84. wandb/sdk/data_types/image.py +1 -1
  85. wandb/sdk/data_types/video.py +1 -1
  86. wandb/sdk/integration_utils/auto_logging.py +5 -6
  87. wandb/sdk/integration_utils/data_logging.py +10 -6
  88. wandb/sdk/interface/interface.py +86 -38
  89. wandb/sdk/interface/interface_shared.py +7 -13
  90. wandb/sdk/internal/datastore.py +1 -1
  91. wandb/sdk/internal/file_pusher.py +2 -5
  92. wandb/sdk/internal/file_stream.py +5 -18
  93. wandb/sdk/internal/handler.py +18 -2
  94. wandb/sdk/internal/internal.py +0 -1
  95. wandb/sdk/internal/internal_api.py +1 -129
  96. wandb/sdk/internal/internal_util.py +0 -1
  97. wandb/sdk/internal/job_builder.py +159 -45
  98. wandb/sdk/internal/profiler.py +1 -0
  99. wandb/sdk/internal/progress.py +0 -28
  100. wandb/sdk/internal/run.py +1 -0
  101. wandb/sdk/internal/sender.py +1 -2
  102. wandb/sdk/internal/system/assets/gpu_amd.py +44 -44
  103. wandb/sdk/internal/system/assets/gpu_apple.py +56 -11
  104. wandb/sdk/internal/system/assets/interfaces.py +6 -8
  105. wandb/sdk/internal/system/assets/open_metrics.py +2 -2
  106. wandb/sdk/internal/system/assets/trainium.py +1 -3
  107. wandb/sdk/launch/__init__.py +9 -1
  108. wandb/sdk/launch/_launch.py +9 -24
  109. wandb/sdk/launch/_launch_add.py +1 -3
  110. wandb/sdk/launch/_project_spec.py +188 -241
  111. wandb/sdk/launch/agent/agent.py +115 -48
  112. wandb/sdk/launch/agent/config.py +80 -14
  113. wandb/sdk/launch/builder/abstract.py +69 -1
  114. wandb/sdk/launch/builder/build.py +156 -555
  115. wandb/sdk/launch/builder/context_manager.py +235 -0
  116. wandb/sdk/launch/builder/docker_builder.py +8 -23
  117. wandb/sdk/launch/builder/kaniko_builder.py +161 -159
  118. wandb/sdk/launch/builder/noop.py +1 -0
  119. wandb/sdk/launch/builder/templates/dockerfile.py +92 -0
  120. wandb/sdk/launch/create_job.py +68 -63
  121. wandb/sdk/launch/environment/abstract.py +1 -0
  122. wandb/sdk/launch/environment/gcp_environment.py +1 -0
  123. wandb/sdk/launch/environment/local_environment.py +1 -0
  124. wandb/sdk/launch/inputs/files.py +148 -0
  125. wandb/sdk/launch/inputs/internal.py +217 -0
  126. wandb/sdk/launch/inputs/manage.py +95 -0
  127. wandb/sdk/launch/loader.py +1 -0
  128. wandb/sdk/launch/registry/abstract.py +1 -0
  129. wandb/sdk/launch/registry/azure_container_registry.py +1 -0
  130. wandb/sdk/launch/registry/elastic_container_registry.py +1 -0
  131. wandb/sdk/launch/registry/google_artifact_registry.py +2 -1
  132. wandb/sdk/launch/registry/local_registry.py +1 -0
  133. wandb/sdk/launch/runner/abstract.py +1 -0
  134. wandb/sdk/launch/runner/kubernetes_monitor.py +4 -1
  135. wandb/sdk/launch/runner/kubernetes_runner.py +9 -10
  136. wandb/sdk/launch/runner/local_container.py +2 -3
  137. wandb/sdk/launch/runner/local_process.py +8 -29
  138. wandb/sdk/launch/runner/sagemaker_runner.py +21 -20
  139. wandb/sdk/launch/runner/vertex_runner.py +8 -7
  140. wandb/sdk/launch/sweeps/scheduler.py +7 -4
  141. wandb/sdk/launch/sweeps/scheduler_sweep.py +2 -1
  142. wandb/sdk/launch/sweeps/utils.py +3 -3
  143. wandb/sdk/launch/utils.py +33 -140
  144. wandb/sdk/lib/_settings_toposort_generated.py +1 -5
  145. wandb/sdk/lib/fsm.py +8 -12
  146. wandb/sdk/lib/gitlib.py +4 -4
  147. wandb/sdk/lib/import_hooks.py +1 -1
  148. wandb/sdk/lib/lazyloader.py +0 -1
  149. wandb/sdk/lib/proto_util.py +23 -2
  150. wandb/sdk/lib/redirect.py +19 -14
  151. wandb/sdk/lib/retry.py +3 -2
  152. wandb/sdk/lib/run_moment.py +7 -1
  153. wandb/sdk/lib/tracelog.py +1 -1
  154. wandb/sdk/service/service.py +19 -16
  155. wandb/sdk/verify/verify.py +2 -1
  156. wandb/sdk/wandb_init.py +16 -63
  157. wandb/sdk/wandb_manager.py +2 -2
  158. wandb/sdk/wandb_require.py +5 -0
  159. wandb/sdk/wandb_run.py +164 -90
  160. wandb/sdk/wandb_settings.py +2 -48
  161. wandb/sdk/wandb_setup.py +1 -1
  162. wandb/sklearn/__init__.py +1 -0
  163. wandb/sklearn/plot/__init__.py +1 -0
  164. wandb/sklearn/plot/classifier.py +11 -12
  165. wandb/sklearn/plot/clusterer.py +2 -1
  166. wandb/sklearn/plot/regressor.py +1 -0
  167. wandb/sklearn/plot/shared.py +1 -0
  168. wandb/sklearn/utils.py +1 -0
  169. wandb/testing/relay.py +4 -4
  170. wandb/trigger.py +1 -0
  171. wandb/util.py +67 -54
  172. wandb/wandb_controller.py +2 -3
  173. wandb/wandb_torch.py +1 -2
  174. {wandb-0.16.5.dist-info → wandb-0.17.0.dist-info}/METADATA +67 -70
  175. {wandb-0.16.5.dist-info → wandb-0.17.0.dist-info}/RECORD +178 -188
  176. {wandb-0.16.5.dist-info → wandb-0.17.0.dist-info}/WHEEL +1 -2
  177. wandb/bin/apple_gpu_stats +0 -0
  178. wandb/catboost/__init__.py +0 -9
  179. wandb/fastai/__init__.py +0 -9
  180. wandb/keras/__init__.py +0 -18
  181. wandb/lightgbm/__init__.py +0 -9
  182. wandb/plots/__init__.py +0 -6
  183. wandb/plots/explain_text.py +0 -36
  184. wandb/plots/heatmap.py +0 -81
  185. wandb/plots/named_entity.py +0 -43
  186. wandb/plots/part_of_speech.py +0 -50
  187. wandb/plots/plot_definitions.py +0 -768
  188. wandb/plots/precision_recall.py +0 -121
  189. wandb/plots/roc.py +0 -103
  190. wandb/sacred/__init__.py +0 -3
  191. wandb/xgboost/__init__.py +0 -9
  192. wandb-0.16.5.dist-info/top_level.txt +0 -1
  193. {wandb-0.16.5.dist-info → wandb-0.17.0.dist-info}/entry_points.txt +0 -0
  194. {wandb-0.16.5.dist-info → wandb-0.17.0.dist-info/licenses}/LICENSE +0 -0
@@ -298,7 +298,6 @@ class SettingsData:
298
298
 
299
299
  _args: Sequence[str]
300
300
  _aws_lambda: bool
301
- _async_upload_concurrency_limit: int
302
301
  _cli_only_mode: bool # Avoid running any code specific for runs
303
302
  _code_path_local: str
304
303
  _colab: bool
@@ -310,9 +309,9 @@ class SettingsData:
310
309
  )
311
310
  _disable_setproctitle: bool # Do not use setproctitle on internal process
312
311
  _disable_stats: bool # Do not collect system metrics
312
+ _disable_update_check: bool # Disable version check
313
313
  _disable_viewer: bool # Prevent early viewer query
314
314
  _disable_machine_info: bool # Disable automatic machine info collection
315
- _except_exit: bool
316
315
  _executable: str
317
316
  _extra_http_headers: Mapping[str, str]
318
317
  # file stream retry client configuration
@@ -424,7 +423,6 @@ class SettingsData:
424
423
  # magic: Union[str, bool, dict] # never used in code, deprecated
425
424
  mode: str
426
425
  notebook_name: str
427
- problem: str
428
426
  program: str
429
427
  program_abspath: str
430
428
  program_relpath: str
@@ -620,10 +618,6 @@ class Settings(SettingsData):
620
618
  Note that key names must be the same as the class attribute names.
621
619
  """
622
620
  props: Dict[str, Dict[str, Any]] = dict(
623
- _async_upload_concurrency_limit={
624
- "preprocessor": int,
625
- "validator": self._validate__async_upload_concurrency_limit,
626
- },
627
621
  _aws_lambda={
628
622
  "hook": lambda _: is_aws_lambda(),
629
623
  "auto_hook": True,
@@ -656,6 +650,7 @@ class Settings(SettingsData):
656
650
  "preprocessor": _str_as_bool,
657
651
  "hook": lambda x: self._disable_machine_info or x,
658
652
  },
653
+ _disable_update_check={"preprocessor": _str_as_bool},
659
654
  _disable_viewer={"preprocessor": _str_as_bool},
660
655
  _extra_http_headers={"preprocessor": _str_as_json},
661
656
  # Retry filestream requests for 2 hours before dropping chunk (how do we recover?)
@@ -860,7 +855,6 @@ class Settings(SettingsData):
860
855
  },
861
856
  login_timeout={"preprocessor": lambda x: float(x)},
862
857
  mode={"value": "online", "validator": self._validate_mode},
863
- problem={"value": "fatal", "validator": self._validate_problem},
864
858
  program={
865
859
  "hook": lambda x: self._get_program(x),
866
860
  },
@@ -1023,13 +1017,6 @@ class Settings(SettingsData):
1023
1017
  raise UsageError(f"Settings field `console`: {value!r} not in {choices}")
1024
1018
  return True
1025
1019
 
1026
- @staticmethod
1027
- def _validate_problem(value: str) -> bool:
1028
- choices: Set[str] = {"fatal", "warn", "silent"}
1029
- if value not in choices:
1030
- raise UsageError(f"Settings field `problem`: {value!r} not in {choices}")
1031
- return True
1032
-
1033
1020
  @staticmethod
1034
1021
  def _validate_anonymous(value: str) -> bool:
1035
1022
  choices: Set[str] = {"allow", "must", "never", "false", "true"}
@@ -1177,35 +1164,6 @@ class Settings(SettingsData):
1177
1164
  raise UsageError("_stats_samples_to_average must be between 1 and 30")
1178
1165
  return True
1179
1166
 
1180
- @staticmethod
1181
- def _validate__async_upload_concurrency_limit(value: int) -> bool:
1182
- if value <= 0:
1183
- raise UsageError("_async_upload_concurrency_limit must be positive")
1184
-
1185
- try:
1186
- import resource # not always available on Windows
1187
-
1188
- file_limit = resource.getrlimit(resource.RLIMIT_NOFILE)[0]
1189
- except Exception:
1190
- # Couldn't get the open-file-limit for some reason,
1191
- # probably very platform-specific. Not a problem,
1192
- # we just won't use it to cap the concurrency.
1193
- pass
1194
- else:
1195
- if value > file_limit:
1196
- wandb.termwarn(
1197
- (
1198
- "_async_upload_concurrency_limit setting of"
1199
- f" {value} exceeds this process's limit"
1200
- f" on open files ({file_limit}); may cause file-upload failures."
1201
- " Try decreasing _async_upload_concurrency_limit,"
1202
- " or increasing your file limit with `ulimit -n`."
1203
- ),
1204
- repeat=False,
1205
- )
1206
-
1207
- return True
1208
-
1209
1167
  @staticmethod
1210
1168
  def _validate_job_source(value: str) -> bool:
1211
1169
  valid_sources = ["repo", "artifact", "image"]
@@ -1673,7 +1631,6 @@ class Settings(SettingsData):
1673
1631
  "WANDB_TRACELOG": "_tracelog",
1674
1632
  "WANDB_DISABLE_SERVICE": "_disable_service",
1675
1633
  "WANDB_SERVICE_TRANSPORT": "_service_transport",
1676
- "WANDB_REQUIRE_CORE": "_require_core",
1677
1634
  "WANDB_DIR": "root_dir",
1678
1635
  "WANDB_NAME": "run_name",
1679
1636
  "WANDB_NOTES": "run_notes",
@@ -1782,9 +1739,6 @@ class Settings(SettingsData):
1782
1739
  settings["_args"] = sys.argv[1:]
1783
1740
  settings["_os"] = platform.platform(aliased=True)
1784
1741
  settings["_python"] = platform.python_version()
1785
- # hack to make sure we don't hang on windows
1786
- if self._windows and self._except_exit is None:
1787
- settings["_except_exit"] = True # type: ignore
1788
1742
 
1789
1743
  if _logger is not None:
1790
1744
  _logger.info(
wandb/sdk/wandb_setup.py CHANGED
@@ -1,7 +1,7 @@
1
1
  #
2
2
  """Setup wandb session.
3
3
 
4
- This module configures a wandb session which can extend to mutiple wandb runs.
4
+ This module configures a wandb session which can extend to multiple wandb runs.
5
5
 
6
6
  Functions:
7
7
  setup(): Configure wandb session.
wandb/sklearn/__init__.py CHANGED
@@ -1,4 +1,5 @@
1
1
  """Create informative charts for scikit-learn models and log them to W&B."""
2
+
2
3
  from .plot import (
3
4
  plot_calibration_curve,
4
5
  plot_class_proportions,
@@ -1,4 +1,5 @@
1
1
  """Create and logs charts introspecting models built with scikit-learn to W&B."""
2
+
2
3
  from .classifier import calibration_curve as plot_calibration_curve
3
4
  from .classifier import class_proportions as plot_class_proportions
4
5
  from .classifier import classifier as plot_classifier
@@ -1,11 +1,12 @@
1
1
  """Define plots for classification models built with scikit-learn."""
2
+
2
3
  from warnings import simplefilter
3
4
 
4
5
  import numpy as np
5
6
  from sklearn import naive_bayes
6
7
 
7
8
  import wandb
8
- import wandb.plots
9
+ import wandb.plot
9
10
  from wandb.sklearn import calculate, utils
10
11
 
11
12
  from . import shared
@@ -32,9 +33,9 @@ def classifier(
32
33
 
33
34
  The following plots are generated:
34
35
  feature importances, confusion matrix, summary metrics,
35
- class propotions, calibration curve, roc curve, precision-recall curve.
36
+ class proportions, calibration curve, roc curve, precision-recall curve.
36
37
 
37
- Should only be called with a fitted classifer (otherwise an error is thrown).
38
+ Should only be called with a fitted classifier (otherwise an error is thrown).
38
39
 
39
40
  Arguments:
40
41
  model: (classifier) Takes in a fitted classifier.
@@ -44,7 +45,7 @@ def classifier(
44
45
  y_test: (arr) Test set labels.
45
46
  y_pred: (arr) Test set predictions by the model passed.
46
47
  y_probas: (arr) Test set predicted probabilities by the model passed.
47
- labels: (list) Named labels for target varible (y). Makes plots easier to
48
+ labels: (list) Named labels for target variable (y). Makes plots easier to
48
49
  read by replacing target values with corresponding index.
49
50
  For example if `labels=['dog', 'cat', 'owl']` all 0s are
50
51
  replaced by dog, 1s by cat.
@@ -133,9 +134,7 @@ def roc(
133
134
  wandb.sklearn.plot_roc(y_true, y_probas, labels)
134
135
  ```
135
136
  """
136
- roc_chart = wandb.plots.roc.roc(
137
- y_true, y_probas, labels, plot_micro, plot_macro, classes_to_plot
138
- )
137
+ roc_chart = wandb.plot.roc_curve(y_true, y_probas, labels, classes_to_plot)
139
138
  wandb.log({"roc": roc_chart})
140
139
 
141
140
 
@@ -212,8 +211,8 @@ def precision_recall(
212
211
  wandb.sklearn.plot_precision_recall(y_true, y_probas, labels)
213
212
  ```
214
213
  """
215
- precision_recall_chart = wandb.plots.precision_recall(
216
- y_true, y_probas, labels, plot_micro, classes_to_plot
214
+ precision_recall_chart = wandb.plot.pr_curve(
215
+ y_true, y_probas, labels, classes_to_plot
217
216
  )
218
217
 
219
218
  wandb.log({"precision_recall": precision_recall_chart})
@@ -224,7 +223,7 @@ def feature_importances(
224
223
  ):
225
224
  """Log a plot depicting the relative importance of each feature for a classifier's decisions.
226
225
 
227
- Should only be called with a fitted classifer (otherwise an error is thrown).
226
+ Should only be called with a fitted classifier (otherwise an error is thrown).
228
227
  Only works with classifiers that have a feature_importances_ attribute, like trees.
229
228
 
230
229
  Arguments:
@@ -251,7 +250,7 @@ def feature_importances(
251
250
 
252
251
 
253
252
  def class_proportions(y_train=None, y_test=None, labels=None):
254
- """Plot the distribution of target classses in training and test sets.
253
+ """Plot the distribution of target classes in training and test sets.
255
254
 
256
255
  Useful for detecting imbalanced classes.
257
256
 
@@ -295,7 +294,7 @@ def calibration_curve(clf=None, X=None, y=None, clf_name="Classifier"):
295
294
  if so which calibration (sigmoid or isotonic) might help fix this.
296
295
  For more details, see https://scikit-learn.org/stable/auto_examples/calibration/plot_calibration_curve.html.
297
296
 
298
- Should only be called with a fitted classifer (otherwise an error is thrown).
297
+ Should only be called with a fitted classifier (otherwise an error is thrown).
299
298
 
300
299
  Please note this function fits variations of the model on the training set when called.
301
300
 
@@ -1,4 +1,5 @@
1
1
  """Define plots for clustering models built with scikit-learn."""
2
+
2
3
  from warnings import simplefilter
3
4
 
4
5
  import pandas as pd
@@ -24,7 +25,7 @@ def clusterer(model, X_train, cluster_labels, labels=None, model_name="Clusterer
24
25
  X_train: (arr) Training set features.
25
26
  cluster_labels: (list) Names for cluster labels. Makes plots easier to read
26
27
  by replacing cluster indexes with corresponding names.
27
- labels: (list) Named labels for target varible (y). Makes plots easier to
28
+ labels: (list) Named labels for target variable (y). Makes plots easier to
28
29
  read by replacing target values with corresponding index.
29
30
  For example if `labels=['dog', 'cat', 'owl']` all 0s are
30
31
  replaced by dog, 1s by cat.
@@ -1,4 +1,5 @@
1
1
  """Define plots for regression models built with scikit-learn."""
2
+
2
3
  from warnings import simplefilter
3
4
 
4
5
  import numpy as np
@@ -1,4 +1,5 @@
1
1
  """Define plots used by multiple sklearn model classes."""
2
+
2
3
  from warnings import simplefilter
3
4
 
4
5
  import numpy as np
wandb/sklearn/utils.py CHANGED
@@ -1,4 +1,5 @@
1
1
  """Shared utilities for the modules in wandb.sklearn."""
2
+
2
3
  from collections.abc import Iterable, Sequence
3
4
 
4
5
  import numpy as np
wandb/testing/relay.py CHANGED
@@ -586,11 +586,11 @@ class InjectedResponse:
586
586
 
587
587
 
588
588
  class RelayControlProtocol(Protocol):
589
- def process(self, request: "flask.Request") -> None:
590
- ... # pragma: no cover
589
+ def process(self, request: "flask.Request") -> None: ... # pragma: no cover
591
590
 
592
- def control(self, request: "flask.Request") -> Mapping[str, str]:
593
- ... # pragma: no cover
591
+ def control(
592
+ self, request: "flask.Request"
593
+ ) -> Mapping[str, str]: ... # pragma: no cover
594
594
 
595
595
 
596
596
  class RelayServer:
wandb/trigger.py CHANGED
@@ -6,6 +6,7 @@ Usage:
6
6
  trigger.call('on_something', *args, **kwargs)
7
7
  trigger.unregister('on_something', func)
8
8
  """
9
+
9
10
  from typing import Any, Callable
10
11
 
11
12
  _triggers = {}
wandb/util.py CHANGED
@@ -11,6 +11,7 @@ import logging
11
11
  import math
12
12
  import numbers
13
13
  import os
14
+ import pathlib
14
15
  import platform
15
16
  import queue
16
17
  import random
@@ -43,7 +44,6 @@ from typing import (
43
44
  Mapping,
44
45
  Optional,
45
46
  Sequence,
46
- Set,
47
47
  TextIO,
48
48
  Tuple,
49
49
  TypeVar,
@@ -55,7 +55,13 @@ import yaml
55
55
 
56
56
  import wandb
57
57
  import wandb.env
58
- from wandb.errors import AuthenticationError, CommError, UsageError, term
58
+ from wandb.errors import (
59
+ AuthenticationError,
60
+ CommError,
61
+ UsageError,
62
+ WandbCoreNotAvailableError,
63
+ term,
64
+ )
59
65
  from wandb.sdk.internal.thread_local_settings import _thread_local_api_settings
60
66
  from wandb.sdk.lib import filesystem, runid
61
67
  from wandb.sdk.lib.json_util import dump, dumps
@@ -537,50 +543,41 @@ def _numpy_generic_convert(obj: Any) -> Any:
537
543
  return obj
538
544
 
539
545
 
540
- def _find_all_matching_keys(
546
+ def _sanitize_numpy_keys(
541
547
  d: Dict,
542
- match_fn: Callable[[Any], bool],
543
- visited: Optional[Set[int]] = None,
544
- key_path: Tuple[Any, ...] = (),
545
- ) -> Generator[Tuple[Tuple[Any, ...], Any], None, None]:
546
- """Recursively find all keys that satisfies a match function.
548
+ visited: Optional[Dict[int, Dict]] = None,
549
+ ) -> Tuple[Dict, bool]:
550
+ """Returns a dictionary where all NumPy keys are converted.
547
551
 
548
552
  Args:
549
- d: The dict to search.
550
- match_fn: The function to determine if the key is a match.
551
- visited: Keep track of visited nodes so we dont recurse forever.
552
- key_path: Keep track of all the keys to get to the current node.
553
+ d: The dictionary to sanitize.
553
554
 
554
- Yields:
555
- (key_path, key): The location where the key was found, and the key
555
+ Returns:
556
+ A sanitized dictionary, and a boolean indicating whether anything was
557
+ changed.
556
558
  """
559
+ out: Dict[Any, Any] = dict()
560
+ converted = False
561
+
562
+ # Work with recursive dictionaries: if a dictionary has already been
563
+ # converted, reuse its converted value to retain the recursive structure
564
+ # of the input.
557
565
  if visited is None:
558
- visited = set()
559
- me = id(d)
560
- if me not in visited:
561
- visited.add(me)
562
- for key, value in d.items():
563
- if match_fn(key):
564
- yield key_path, key
565
- if isinstance(value, dict):
566
- yield from _find_all_matching_keys(
567
- value,
568
- match_fn,
569
- visited=visited,
570
- key_path=tuple(list(key_path) + [key]),
571
- )
566
+ visited = {id(d): out}
567
+ elif id(d) in visited:
568
+ return visited[id(d)], False
569
+ visited[id(d)] = out
572
570
 
571
+ for key, value in d.items():
572
+ if isinstance(value, dict):
573
+ value, converted_value = _sanitize_numpy_keys(value, visited)
574
+ converted |= converted_value
575
+ if isinstance(key, np.generic):
576
+ key = _numpy_generic_convert(key)
577
+ converted = True
578
+ out[key] = value
573
579
 
574
- def _sanitize_numpy_keys(d: Dict) -> Tuple[Dict, bool]:
575
- np_keys = list(_find_all_matching_keys(d, lambda k: isinstance(k, np.generic)))
576
- if not np_keys:
577
- return d, False
578
- for key_path, key in np_keys:
579
- ptr = d
580
- for k in key_path:
581
- ptr = ptr[k]
582
- ptr[_numpy_generic_convert(key)] = ptr.pop(key)
583
- return d, True
580
+ return out, converted
584
581
 
585
582
 
586
583
  def json_friendly( # noqa: C901
@@ -1842,15 +1839,6 @@ def sample_with_exponential_decay_weights(
1842
1839
  return sampled_xs, sampled_ys, sampled_keys
1843
1840
 
1844
1841
 
1845
- def get_core_path() -> str:
1846
- core_path: str = os.environ.get("_WANDB_CORE_PATH", "")
1847
- wandb_core = get_module("wandb_core")
1848
- if not core_path and wandb_core:
1849
- _check_wandb_core_version_compatibility(wandb_core.__version__)
1850
- core_path = wandb_core.get_core_path()
1851
- return core_path
1852
-
1853
-
1854
1842
  @dataclasses.dataclass(frozen=True)
1855
1843
  class InstalledDistribution:
1856
1844
  """An installed distribution.
@@ -1888,15 +1876,40 @@ def parse_version(version: str) -> "packaging.version.Version":
1888
1876
  try:
1889
1877
  from packaging.version import parse as parse_version # type: ignore
1890
1878
  except ImportError:
1891
- from pkg_resources import parse_version
1879
+ from pkg_resources import parse_version # type: ignore[assignment]
1892
1880
 
1893
1881
  return parse_version(version)
1894
1882
 
1895
1883
 
1896
- def _check_wandb_core_version_compatibility(core_version: str) -> None:
1897
- """Checks if the installed wandb-core version is compatible with the wandb version."""
1898
- if parse_version(core_version) < parse_version(wandb._minimum_core_version):
1899
- raise ImportError(
1900
- f"Requires wandb-core version {wandb._minimum_core_version} or later, "
1901
- f"but you have {core_version}. Run `pip install --upgrade wandb-core` to upgrade."
1884
+ def get_core_path() -> str:
1885
+ """Returns the path to the wandb-core binary.
1886
+
1887
+ The path can be set explicitly via the _WANDB_CORE_PATH environment
1888
+ variable. Otherwise, the path to the binary in the current package
1889
+ is returned.
1890
+
1891
+ Returns:
1892
+ str: The path to the wandb-core package.
1893
+
1894
+ Raises:
1895
+ WandbCoreNotAvailableError: If wandb-core was not built for the current system.
1896
+ """
1897
+ # NOTE: Environment variable _WANDB_CORE_PATH is a temporary development feature
1898
+ # to assist in running the core service from a live development directory.
1899
+ path_from_env: str = os.environ.get("_WANDB_CORE_PATH", "")
1900
+ if path_from_env:
1901
+ wandb.termwarn(
1902
+ f"Using wandb-core from path `_WANDB_CORE_PATH={path_from_env}`. "
1903
+ "This is a development feature and may not work as expected."
1902
1904
  )
1905
+ return path_from_env
1906
+
1907
+ bin_path = pathlib.Path(__file__).parent / "bin" / "wandb-core"
1908
+ if not bin_path.exists():
1909
+ raise WandbCoreNotAvailableError(
1910
+ f"Looks like wandb-core is not compiled for your system ({platform.platform()}):"
1911
+ " Please contact support at support@wandb.com to request `wandb-core`"
1912
+ " support for your system."
1913
+ )
1914
+
1915
+ return str(bin_path)
wandb/wandb_controller.py CHANGED
@@ -20,7 +20,7 @@ Example:
20
20
  tuner = wandb.controller()
21
21
  tuner.configure(sweep_config)
22
22
  tuner.create()
23
- # (3) create by constructing progamatic sweep configuration
23
+ # (3) create by constructing programmatic sweep configuration
24
24
  tuner = wandb.controller()
25
25
  tuner.configure_search('random')
26
26
  tuner.configure_program('train-dummy.py')
@@ -47,7 +47,6 @@ Example:
47
47
  tuner.stop_runs(runs)
48
48
  """
49
49
 
50
-
51
50
  import json
52
51
  import os
53
52
  import random
@@ -128,7 +127,7 @@ class _WandbController:
128
127
  """
129
128
 
130
129
  def __init__(self, sweep_id_or_config=None, entity=None, project=None):
131
- # sweep id configured in constuctor
130
+ # sweep id configured in constructor
132
131
  self._sweep_id: Optional[str] = None
133
132
 
134
133
  # configured parameters
wandb/wandb_torch.py CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env python
2
2
 
3
- """PyTorch-specific functionality
4
- """
3
+ """PyTorch-specific functionality"""
5
4
 
6
5
  import itertools
7
6
  from functools import reduce