wandb 0.21.0__py3-none-macosx_11_0_arm64.whl → 0.21.1__py3-none-macosx_11_0_arm64.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.
Files changed (97) hide show
  1. wandb/__init__.py +16 -14
  2. wandb/__init__.pyi +427 -450
  3. wandb/agents/pyagent.py +41 -12
  4. wandb/analytics/sentry.py +7 -2
  5. wandb/apis/importers/mlflow.py +1 -1
  6. wandb/apis/public/__init__.py +1 -1
  7. wandb/apis/public/api.py +526 -360
  8. wandb/apis/public/artifacts.py +204 -8
  9. wandb/apis/public/automations.py +19 -3
  10. wandb/apis/public/files.py +172 -33
  11. wandb/apis/public/history.py +67 -15
  12. wandb/apis/public/integrations.py +25 -2
  13. wandb/apis/public/jobs.py +90 -2
  14. wandb/apis/public/projects.py +130 -79
  15. wandb/apis/public/query_generator.py +11 -1
  16. wandb/apis/public/registries/registries_search.py +7 -15
  17. wandb/apis/public/reports.py +83 -5
  18. wandb/apis/public/runs.py +299 -105
  19. wandb/apis/public/sweeps.py +222 -22
  20. wandb/apis/public/teams.py +41 -4
  21. wandb/apis/public/users.py +45 -4
  22. wandb/beta/workflows.py +66 -30
  23. wandb/bin/gpu_stats +0 -0
  24. wandb/bin/wandb-core +0 -0
  25. wandb/cli/cli.py +80 -1
  26. wandb/env.py +8 -0
  27. wandb/errors/errors.py +4 -1
  28. wandb/integration/lightning/fabric/logger.py +3 -4
  29. wandb/integration/metaflow/__init__.py +6 -0
  30. wandb/integration/metaflow/data_pandas.py +74 -0
  31. wandb/integration/metaflow/errors.py +13 -0
  32. wandb/integration/metaflow/metaflow.py +205 -190
  33. wandb/integration/openai/fine_tuning.py +1 -2
  34. wandb/jupyter.py +5 -5
  35. wandb/plot/custom_chart.py +30 -7
  36. wandb/proto/v3/wandb_internal_pb2.py +280 -280
  37. wandb/proto/v3/wandb_telemetry_pb2.py +4 -4
  38. wandb/proto/v4/wandb_internal_pb2.py +280 -280
  39. wandb/proto/v4/wandb_telemetry_pb2.py +4 -4
  40. wandb/proto/v5/wandb_internal_pb2.py +280 -280
  41. wandb/proto/v5/wandb_telemetry_pb2.py +4 -4
  42. wandb/proto/v6/wandb_internal_pb2.py +280 -280
  43. wandb/proto/v6/wandb_telemetry_pb2.py +4 -4
  44. wandb/proto/wandb_deprecated.py +6 -0
  45. wandb/sdk/artifacts/_internal_artifact.py +19 -8
  46. wandb/sdk/artifacts/_validators.py +8 -0
  47. wandb/sdk/artifacts/artifact.py +106 -75
  48. wandb/sdk/data_types/audio.py +38 -10
  49. wandb/sdk/data_types/base_types/media.py +6 -56
  50. wandb/sdk/data_types/graph.py +48 -14
  51. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +1 -3
  52. wandb/sdk/data_types/helper_types/image_mask.py +1 -3
  53. wandb/sdk/data_types/histogram.py +34 -21
  54. wandb/sdk/data_types/html.py +35 -12
  55. wandb/sdk/data_types/image.py +104 -68
  56. wandb/sdk/data_types/molecule.py +32 -19
  57. wandb/sdk/data_types/object_3d.py +36 -17
  58. wandb/sdk/data_types/plotly.py +18 -5
  59. wandb/sdk/data_types/saved_model.py +4 -6
  60. wandb/sdk/data_types/table.py +59 -30
  61. wandb/sdk/data_types/video.py +53 -26
  62. wandb/sdk/integration_utils/auto_logging.py +2 -2
  63. wandb/sdk/internal/internal_api.py +6 -0
  64. wandb/sdk/internal/job_builder.py +6 -0
  65. wandb/sdk/launch/agent/agent.py +8 -1
  66. wandb/sdk/launch/agent/run_queue_item_file_saver.py +2 -2
  67. wandb/sdk/launch/create_job.py +3 -1
  68. wandb/sdk/launch/inputs/internal.py +3 -4
  69. wandb/sdk/launch/inputs/schema.py +1 -0
  70. wandb/sdk/launch/runner/kubernetes_monitor.py +1 -0
  71. wandb/sdk/launch/runner/kubernetes_runner.py +328 -1
  72. wandb/sdk/launch/sweeps/scheduler.py +2 -3
  73. wandb/sdk/lib/asyncio_compat.py +3 -0
  74. wandb/sdk/lib/deprecate.py +1 -7
  75. wandb/sdk/lib/disabled.py +1 -1
  76. wandb/sdk/lib/hashutil.py +14 -1
  77. wandb/sdk/lib/module.py +7 -13
  78. wandb/sdk/lib/progress.py +0 -19
  79. wandb/sdk/lib/sock_client.py +0 -4
  80. wandb/sdk/wandb_init.py +66 -91
  81. wandb/sdk/wandb_login.py +18 -14
  82. wandb/sdk/wandb_metric.py +2 -0
  83. wandb/sdk/wandb_run.py +406 -414
  84. wandb/sdk/wandb_settings.py +130 -2
  85. wandb/sdk/wandb_setup.py +28 -28
  86. wandb/sdk/wandb_sweep.py +14 -13
  87. wandb/sdk/wandb_watch.py +4 -6
  88. wandb/sync/sync.py +10 -0
  89. wandb/util.py +57 -0
  90. wandb/wandb_run.py +1 -2
  91. {wandb-0.21.0.dist-info → wandb-0.21.1.dist-info}/METADATA +1 -1
  92. {wandb-0.21.0.dist-info → wandb-0.21.1.dist-info}/RECORD +95 -95
  93. wandb/vendor/pynvml/__init__.py +0 -0
  94. wandb/vendor/pynvml/pynvml.py +0 -4779
  95. {wandb-0.21.0.dist-info → wandb-0.21.1.dist-info}/WHEEL +0 -0
  96. {wandb-0.21.0.dist-info → wandb-0.21.1.dist-info}/entry_points.txt +0 -0
  97. {wandb-0.21.0.dist-info → wandb-0.21.1.dist-info}/licenses/LICENSE +0 -0
wandb/sdk/wandb_run.py CHANGED
@@ -131,6 +131,7 @@ if TYPE_CHECKING:
131
131
  input_types: dict[str, Any]
132
132
  output_types: dict[str, Any]
133
133
  runtime: str | None
134
+ services: dict[str, str]
134
135
 
135
136
 
136
137
  logger = logging.getLogger("wandb")
@@ -474,62 +475,47 @@ class RunStatus:
474
475
 
475
476
 
476
477
  class Run:
477
- """A unit of computation logged by wandb. Typically, this is an ML experiment.
478
+ """A unit of computation logged by W&B. Typically, this is an ML experiment.
478
479
 
479
- Create a run with `wandb.init()`:
480
- ```python
481
- import wandb
480
+ Call [`wandb.init()`](https://docs.wandb.ai/ref/python/init/) to create a
481
+ new run. `wandb.init()` starts a new run and returns a `wandb.Run` object.
482
+ Each run is associated with a unique ID (run ID). W&B recommends using
483
+ a context (`with` statement) manager to automatically finish the run.
482
484
 
483
- run = wandb.init()
484
- ```
485
+ For distributed training experiments, you can either track each process
486
+ separately using one run per process or track all processes to a single run.
487
+ See [Log distributed training experiments](https://docs.wandb.ai/guides/track/log/distributed-training)
488
+ for more information.
485
489
 
486
- There is only ever at most one active `wandb.Run` in any process,
487
- and it is accessible as `wandb.run`:
488
- ```python
489
- import wandb
490
+ You can log data to a run with `wandb.Run.log()`. Anything you log using
491
+ `wandb.Run.log()` is sent to that run. See
492
+ [Create an experiment](https://docs.wandb.ai/guides/track/launch) or
493
+ [`wandb.init`](https://docs.wandb.ai/ref/python/init/) API reference page
494
+ or more information.
490
495
 
491
- assert wandb.run is None
496
+ There is a another `Run` object in the
497
+ [`wandb.apis.public`](https://docs.wandb.ai/ref/python/public-api/api/)
498
+ namespace. Use this object is to interact with runs that have already been
499
+ created.
492
500
 
493
- wandb.init()
501
+ Attributes:
502
+ summary: (Summary) A summary of the run, which is a dictionary-like
503
+ object. For more information, see
504
+ [Log summary metrics](https://docs.wandb.ai/guides/track/log/log-summary/).
494
505
 
495
- assert wandb.run is not None
496
- ```
497
- anything you log with `wandb.log` will be sent to that run.
506
+ Examples:
507
+ Create a run with `wandb.init()`:
498
508
 
499
- If you want to start more runs in the same script or notebook, you'll need to
500
- finish the run that is in-flight. Runs can be finished with `wandb.finish` or
501
- by using them in a `with` block:
502
509
  ```python
503
510
  import wandb
504
511
 
505
- wandb.init()
506
- wandb.finish()
507
-
508
- assert wandb.run is None
509
-
510
- with wandb.init() as run:
511
- pass # log data here
512
-
513
- assert wandb.run is None
512
+ # Start a new run and log some data
513
+ # Use context manager (`with` statement) to automatically finish the run
514
+ with wandb.init(entity="entity", project="project") as run:
515
+ run.log({"accuracy": acc, "loss": loss})
514
516
  ```
515
517
 
516
- See the documentation for `wandb.init` for more on creating runs, or check out
517
- [our guide to `wandb.init`](https://docs.wandb.ai/guides/track/launch).
518
-
519
- In distributed training, you can either create a single run in the rank 0 process
520
- and then log information only from that process, or you can create a run in each process,
521
- logging from each separately, and group the results together with the `group` argument
522
- to `wandb.init`. For more details on distributed training with W&B, check out
523
- [our guide](https://docs.wandb.ai/guides/track/log/distributed-training).
524
-
525
- Currently, there is a parallel `Run` object in the `wandb.Api`. Eventually these
526
- two objects will be merged.
527
-
528
- Attributes:
529
- summary: (Summary) Single values set for each `wandb.log()` key. By
530
- default, summary is set to the last value logged. You can manually
531
- set summary to the best value, like max accuracy, instead of the
532
- final value.
518
+ <!-- lazydoc-ignore-init: internal -->
533
519
  """
534
520
 
535
521
  _telemetry_obj: telemetry.TelemetryRecord
@@ -850,6 +836,7 @@ class Run:
850
836
  @_log_to_run
851
837
  @_attach
852
838
  def config_static(self) -> wandb_config.ConfigStatic:
839
+ """Static config object associated with this run."""
853
840
  return wandb_config.ConfigStatic(self._config)
854
841
 
855
842
  @property
@@ -957,7 +944,10 @@ class Run:
957
944
  @_log_to_run
958
945
  @_attach
959
946
  def starting_step(self) -> int:
960
- """The first step of the run."""
947
+ """The first step of the run.
948
+
949
+ <!-- lazydoc-ignore: internal -->
950
+ """
961
951
  return self._starting_step
962
952
 
963
953
  @property
@@ -973,7 +963,9 @@ class Run:
973
963
  def step(self) -> int:
974
964
  """Current value of the step.
975
965
 
976
- This counter is incremented by `wandb.log`.
966
+ This counter is incremented by `wandb.Run.log()`.
967
+
968
+ <!-- lazydoc-ignore: internal -->
977
969
  """
978
970
  return self._step
979
971
 
@@ -981,26 +973,30 @@ class Run:
981
973
  @_log_to_run
982
974
  @_attach
983
975
  def offline(self) -> bool:
976
+ """True if the run is offline, False otherwise."""
984
977
  return self._settings._offline
985
978
 
986
979
  @property
987
980
  @_log_to_run
988
981
  @_attach
989
982
  def disabled(self) -> bool:
983
+ """True if the run is disabled, False otherwise."""
990
984
  return self._settings._noop
991
985
 
992
986
  @property
993
987
  @_log_to_run
994
988
  @_attach
995
989
  def group(self) -> str:
996
- """Name of the group associated with the run.
990
+ """Returns the name of the group associated with this run.
997
991
 
998
- Setting a group helps the W&B UI organize runs in a sensible way.
992
+ Grouping runs together allows related experiments to be organized and
993
+ visualized collectively in the W&B UI. This is especially useful for
994
+ scenarios such as distributed training or cross-validation, where
995
+ multiple runs should be viewed and managed as a unified experiment.
999
996
 
1000
- If you are doing a distributed training you should give all of the
1001
- runs in the training the same group.
1002
- If you are doing cross-validation you should give all the cross-validation
1003
- folds the same group.
997
+ In shared mode, where all processes share the same run object,
998
+ setting a group is usually unnecessary, since there is only one
999
+ run and no grouping is required.
1004
1000
  """
1005
1001
  return self._settings.run_group or ""
1006
1002
 
@@ -1008,13 +1004,24 @@ class Run:
1008
1004
  @_log_to_run
1009
1005
  @_attach
1010
1006
  def job_type(self) -> str:
1007
+ """Name of the job type associated with the run.
1008
+
1009
+ View a run's job type in the run's Overview page in the W&B App.
1010
+
1011
+ You can use this to categorize runs by their job type, such as
1012
+ "training", "evaluation", or "inference". This is useful for organizing
1013
+ and filtering runs in the W&B UI, especially when you have multiple
1014
+ runs with different job types in the same project. For more
1015
+ information, see [Organize runs](https://docs.wandb.ai/guides/runs/#organize-runs).
1016
+ """
1011
1017
  return self._settings.run_job_type or ""
1012
1018
 
1013
1019
  def project_name(self) -> str:
1014
- """Name of the W&B project associated with the run.
1020
+ """This method is deprecated and will be removed in a future release. Use `run.project` instead.
1021
+
1022
+ Name of the W&B project associated with the run.
1015
1023
 
1016
- Note: this method is deprecated and will be removed in a future release.
1017
- Please use `run.project` instead.
1024
+ <!-- lazydoc-ignore: internal -->
1018
1025
  """
1019
1026
  deprecate.deprecate(
1020
1027
  field_name=Deprecated.run__project_name,
@@ -1035,12 +1042,12 @@ class Run:
1035
1042
 
1036
1043
  @_log_to_run
1037
1044
  def get_project_url(self) -> str | None:
1038
- """URL of the W&B project associated with the run, if there is one.
1045
+ """This method is deprecated and will be removed in a future release. Use `run.project_url` instead.
1039
1046
 
1047
+ URL of the W&B project associated with the run, if there is one.
1040
1048
  Offline runs do not have a project URL.
1041
1049
 
1042
- Note: this method is deprecated and will be removed in a future release.
1043
- Please use `run.project_url` instead.
1050
+ <!-- lazydoc-ignore: internal -->
1044
1051
  """
1045
1052
  deprecate.deprecate(
1046
1053
  field_name=Deprecated.run__get_project_url,
@@ -1087,28 +1094,36 @@ class Run:
1087
1094
  many runs to share the same artifact. Specifying name allows you to achieve that.
1088
1095
  include_fn: A callable that accepts a file path and (optionally) root path and
1089
1096
  returns True when it should be included and False otherwise. This
1090
- defaults to: `lambda path, root: path.endswith(".py")`
1097
+ defaults to `lambda path, root: path.endswith(".py")`.
1091
1098
  exclude_fn: A callable that accepts a file path and (optionally) root path and
1092
1099
  returns `True` when it should be excluded and `False` otherwise. This
1093
1100
  defaults to a function that excludes all files within `<root>/.wandb/`
1094
1101
  and `<root>/wandb/` directories.
1095
1102
 
1096
1103
  Examples:
1097
- Basic usage
1098
- ```python
1104
+ Basic usage
1105
+
1106
+ ```python
1107
+ import wandb
1108
+
1109
+ with wandb.init() as run:
1099
1110
  run.log_code()
1100
- ```
1111
+ ```
1101
1112
 
1102
- Advanced usage
1103
- ```python
1113
+ Advanced usage
1114
+
1115
+ ```python
1116
+ import wandb
1117
+
1118
+ with wandb.init() as run:
1104
1119
  run.log_code(
1105
- "../",
1120
+ root="../",
1106
1121
  include_fn=lambda path: path.endswith(".py") or path.endswith(".ipynb"),
1107
1122
  exclude_fn=lambda path, root: os.path.relpath(path, root).startswith(
1108
1123
  "cache/"
1109
1124
  ),
1110
1125
  )
1111
- ```
1126
+ ```
1112
1127
 
1113
1128
  Returns:
1114
1129
  An `Artifact` object if code was logged
@@ -1161,12 +1176,12 @@ class Run:
1161
1176
 
1162
1177
  @_log_to_run
1163
1178
  def get_sweep_url(self) -> str | None:
1164
- """The URL of the sweep associated with the run, if there is one.
1179
+ """This method is deprecated and will be removed in a future release. Use `run.sweep_url` instead.
1165
1180
 
1181
+ The URL of the sweep associated with the run, if there is one.
1166
1182
  Offline runs do not have a sweep URL.
1167
1183
 
1168
- Note: this method is deprecated and will be removed in a future release.
1169
- Please use `run.sweep_url` instead.
1184
+ <!-- lazydoc-ignore: internal -->
1170
1185
  """
1171
1186
  deprecate.deprecate(
1172
1187
  field_name=Deprecated.run__get_sweep_url,
@@ -1191,12 +1206,11 @@ class Run:
1191
1206
 
1192
1207
  @_log_to_run
1193
1208
  def get_url(self) -> str | None:
1194
- """URL of the W&B run, if there is one.
1209
+ """This method is deprecated and will be removed in a future release. Use `run.url` instead.
1195
1210
 
1196
- Offline runs do not have a URL.
1211
+ URL of the W&B run, if there is one. Offline runs do not have a URL.
1197
1212
 
1198
- Note: this method is deprecated and will be removed in a future release.
1199
- Please use `run.url` instead.
1213
+ <!-- lazydoc-ignore: internal -->
1200
1214
  """
1201
1215
  deprecate.deprecate(
1202
1216
  field_name=Deprecated.run__get_url,
@@ -1319,7 +1333,7 @@ class Run:
1319
1333
  @_log_to_run
1320
1334
  @_attach
1321
1335
  def display(self, height: int = 420, hidden: bool = False) -> bool:
1322
- """Display this run in jupyter."""
1336
+ """Display this run in Jupyter."""
1323
1337
  if self._settings.silent:
1324
1338
  return False
1325
1339
 
@@ -1338,7 +1352,10 @@ class Run:
1338
1352
  @_log_to_run
1339
1353
  @_attach
1340
1354
  def to_html(self, height: int = 420, hidden: bool = False) -> str:
1341
- """Generate HTML containing an iframe displaying the current run."""
1355
+ """Generate HTML containing an iframe displaying the current run.
1356
+
1357
+ <!-- lazydoc-ignore: internal -->
1358
+ """
1342
1359
  url = self._settings.run_url + "?jupyter=true"
1343
1360
  style = f"border:none;width:100%;height:{height}px;"
1344
1361
  prefix = ""
@@ -1489,7 +1506,7 @@ class Run:
1489
1506
  ) -> dict[str, Any]:
1490
1507
  """Process and replace chart objects with their underlying table values.
1491
1508
 
1492
- This processes the chart objects passed to `run.log()`, replacing their entries
1509
+ This processes the chart objects passed to `wandb.Run.log()`, replacing their entries
1493
1510
  in the given dictionary (which is saved to the run's history) and adding them
1494
1511
  to the run's config.
1495
1512
 
@@ -1745,91 +1762,94 @@ class Run:
1745
1762
  """Upload run data.
1746
1763
 
1747
1764
  Use `log` to log data from runs, such as scalars, images, video,
1748
- histograms, plots, and tables.
1765
+ histograms, plots, and tables. See [Log objects and media](https://docs.wandb.ai/guides/track/log) for
1766
+ code snippets, best practices, and more.
1749
1767
 
1750
- See our [guides to logging](https://docs.wandb.ai/guides/track/log) for
1751
- live examples, code snippets, best practices, and more.
1768
+ Basic usage:
1752
1769
 
1753
- The most basic usage is `run.log({"train-loss": 0.5, "accuracy": 0.9})`.
1754
- This will save the loss and accuracy to the run's history and update
1755
- the summary values for these metrics.
1770
+ ```python
1771
+ import wandb
1756
1772
 
1757
- Visualize logged data in the workspace at [wandb.ai](https://wandb.ai),
1773
+ with wandb.init() as run:
1774
+ run.log({"train-loss": 0.5, "accuracy": 0.9})
1775
+ ```
1776
+
1777
+ The previous code snippet saves the loss and accuracy to the run's
1778
+ history and updates the summary values for these metrics.
1779
+
1780
+ Visualize logged data in a workspace at [wandb.ai](https://wandb.ai),
1758
1781
  or locally on a [self-hosted instance](https://docs.wandb.ai/guides/hosting)
1759
- of the W&B app, or export data to visualize and explore locally, e.g. in
1760
- Jupyter notebooks, with [our API](https://docs.wandb.ai/guides/track/public-api-guide).
1761
-
1762
- Logged values don't have to be scalars. Logging any wandb object is supported.
1763
- For example `run.log({"example": wandb.Image("myimage.jpg")})` will log an
1764
- example image which will be displayed nicely in the W&B UI.
1765
- See the [reference documentation](https://docs.wandb.com/ref/python/data-types)
1766
- for all of the different supported types or check out our
1767
- [guides to logging](https://docs.wandb.ai/guides/track/log) for examples,
1768
- from 3D molecular structures and segmentation masks to PR curves and histograms.
1769
- You can use `wandb.Table` to log structured data. See our
1770
- [guide to logging tables](https://docs.wandb.ai/guides/models/tables/tables-walkthrough)
1771
- for details.
1772
-
1773
- The W&B UI organizes metrics with a forward slash (`/`) in their name
1782
+ of the W&B app, or export data to visualize and explore locally, such as in a
1783
+ Jupyter notebook, with the [Public API](https://docs.wandb.ai/guides/track/public-api-guide).
1784
+
1785
+ Logged values don't have to be scalars. You can log any
1786
+ [W&B supported Data Type](https://docs.wandb.ai/ref/python/data-types/)
1787
+ such as images, audio, video, and more. For example, you can use
1788
+ `wandb.Table` to log structured data. See
1789
+ [Log tables, visualize and query data](https://docs.wandb.ai/guides/models/tables/tables-walkthrough)
1790
+ tutorial for more details.
1791
+
1792
+ W&B organizes metrics with a forward slash (`/`) in their name
1774
1793
  into sections named using the text before the final slash. For example,
1775
1794
  the following results in two sections named "train" and "validate":
1776
1795
 
1777
- ```
1778
- run.log(
1779
- {
1780
- "train/accuracy": 0.9,
1781
- "train/loss": 30,
1782
- "validate/accuracy": 0.8,
1783
- "validate/loss": 20,
1784
- }
1785
- )
1796
+ ```python
1797
+ with wandb.init() as run:
1798
+ # Log metrics in the "train" section.
1799
+ run.log(
1800
+ {
1801
+ "train/accuracy": 0.9,
1802
+ "train/loss": 30,
1803
+ "validate/accuracy": 0.8,
1804
+ "validate/loss": 20,
1805
+ }
1806
+ )
1786
1807
  ```
1787
1808
 
1788
1809
  Only one level of nesting is supported; `run.log({"a/b/c": 1})`
1789
1810
  produces a section named "a/b".
1790
1811
 
1791
- `run.log` is not intended to be called more than a few times per second.
1812
+ `run.log()` is not intended to be called more than a few times per second.
1792
1813
  For optimal performance, limit your logging to once every N iterations,
1793
1814
  or collect data over multiple iterations and log it in a single step.
1794
1815
 
1795
- ### The W&B step
1796
-
1797
- With basic usage, each call to `log` creates a new "step".
1816
+ By default, each call to `log` creates a new "step".
1798
1817
  The step must always increase, and it is not possible to log
1799
- to a previous step.
1818
+ to a previous step. You can use any metric as the X axis in charts.
1819
+ See [Custom log axes](https://docs.wandb.ai/guides/track/log/customize-logging-axes/)
1820
+ for more details.
1800
1821
 
1801
- Note that you can use any metric as the X axis in charts.
1802
1822
  In many cases, it is better to treat the W&B step like
1803
1823
  you'd treat a timestamp rather than a training step.
1804
1824
 
1825
+ ```python
1826
+ with wandb.init() as run:
1827
+ # Example: log an "epoch" metric for use as an X axis.
1828
+ run.log({"epoch": 40, "train-loss": 0.5})
1805
1829
  ```
1806
- # Example: log an "epoch" metric for use as an X axis.
1807
- run.log({"epoch": 40, "train-loss": 0.5})
1808
- ```
1809
-
1810
- See also [define_metric](https://docs.wandb.ai/ref/python/run#define_metric).
1811
1830
 
1812
- It is possible to use multiple `log` invocations to log to
1831
+ It is possible to use multiple `wandb.Run.log()` invocations to log to
1813
1832
  the same step with the `step` and `commit` parameters.
1814
1833
  The following are all equivalent:
1815
1834
 
1816
- ```
1817
- # Normal usage:
1818
- run.log({"train-loss": 0.5, "accuracy": 0.8})
1819
- run.log({"train-loss": 0.4, "accuracy": 0.9})
1820
-
1821
- # Implicit step without auto-incrementing:
1822
- run.log({"train-loss": 0.5}, commit=False)
1823
- run.log({"accuracy": 0.8})
1824
- run.log({"train-loss": 0.4}, commit=False)
1825
- run.log({"accuracy": 0.9})
1826
-
1827
- # Explicit step:
1828
- run.log({"train-loss": 0.5}, step=current_step)
1829
- run.log({"accuracy": 0.8}, step=current_step)
1830
- current_step += 1
1831
- run.log({"train-loss": 0.4}, step=current_step)
1832
- run.log({"accuracy": 0.9}, step=current_step)
1835
+ ```python
1836
+ with wandb.init() as run:
1837
+ # Normal usage:
1838
+ run.log({"train-loss": 0.5, "accuracy": 0.8})
1839
+ run.log({"train-loss": 0.4, "accuracy": 0.9})
1840
+
1841
+ # Implicit step without auto-incrementing:
1842
+ run.log({"train-loss": 0.5}, commit=False)
1843
+ run.log({"accuracy": 0.8})
1844
+ run.log({"train-loss": 0.4}, commit=False)
1845
+ run.log({"accuracy": 0.9})
1846
+
1847
+ # Explicit step:
1848
+ run.log({"train-loss": 0.5}, step=current_step)
1849
+ run.log({"accuracy": 0.8}, step=current_step)
1850
+ current_step += 1
1851
+ run.log({"train-loss": 0.4}, step=current_step)
1852
+ run.log({"accuracy": 0.9}, step=current_step)
1833
1853
  ```
1834
1854
 
1835
1855
  Args:
@@ -1847,59 +1867,64 @@ class Run:
1847
1867
  otherwise, the default is `commit=False`.
1848
1868
 
1849
1869
  Examples:
1850
- For more and more detailed examples, see
1851
- [our guides to logging](https://docs.wandb.com/guides/track/log).
1870
+ For more and more detailed examples, see
1871
+ [our guides to logging](https://docs.wandb.com/guides/track/log).
1872
+
1873
+ Basic usage
1852
1874
 
1853
- ### Basic usage
1854
- ```python
1855
- import wandb
1875
+ ```python
1876
+ import wandb
1877
+
1878
+ with wandb.init() as run:
1879
+ run.log({"train-loss": 0.5, "accuracy": 0.9
1880
+ ```
1856
1881
 
1857
- run = wandb.init()
1858
- run.log({"accuracy": 0.9, "epoch": 5})
1859
- ```
1882
+ Incremental logging
1860
1883
 
1861
- ### Incremental logging
1862
- ```python
1863
- import wandb
1884
+ ```python
1885
+ import wandb
1864
1886
 
1865
- run = wandb.init()
1887
+ with wandb.init() as run:
1866
1888
  run.log({"loss": 0.2}, commit=False)
1867
1889
  # Somewhere else when I'm ready to report this step:
1868
1890
  run.log({"accuracy": 0.8})
1869
- ```
1891
+ ```
1892
+
1893
+ Histogram
1870
1894
 
1871
- ### Histogram
1872
- ```python
1873
- import numpy as np
1874
- import wandb
1895
+ ```python
1896
+ import numpy as np
1897
+ import wandb
1875
1898
 
1876
- # sample gradients at random from normal distribution
1877
- gradients = np.random.randn(100, 100)
1878
- run = wandb.init()
1899
+ # sample gradients at random from normal distribution
1900
+ gradients = np.random.randn(100, 100)
1901
+ with wandb.init() as run:
1879
1902
  run.log({"gradients": wandb.Histogram(gradients)})
1880
- ```
1903
+ ```
1881
1904
 
1882
- ### Image from numpy
1883
- ```python
1884
- import numpy as np
1885
- import wandb
1905
+ Image from NumPy
1886
1906
 
1887
- run = wandb.init()
1907
+ ```python
1908
+ import numpy as np
1909
+ import wandb
1910
+
1911
+ with wandb.init() as run:
1888
1912
  examples = []
1889
1913
  for i in range(3):
1890
1914
  pixels = np.random.randint(low=0, high=256, size=(100, 100, 3))
1891
1915
  image = wandb.Image(pixels, caption=f"random field {i}")
1892
1916
  examples.append(image)
1893
1917
  run.log({"examples": examples})
1894
- ```
1918
+ ```
1895
1919
 
1896
- ### Image from PIL
1897
- ```python
1898
- import numpy as np
1899
- from PIL import Image as PILImage
1900
- import wandb
1920
+ Image from PIL
1901
1921
 
1902
- run = wandb.init()
1922
+ ```python
1923
+ import numpy as np
1924
+ from PIL import Image as PILImage
1925
+ import wandb
1926
+
1927
+ with wandb.init() as run:
1903
1928
  examples = []
1904
1929
  for i in range(3):
1905
1930
  pixels = np.random.randint(
@@ -1912,14 +1937,15 @@ class Run:
1912
1937
  image = wandb.Image(pil_image, caption=f"random field {i}")
1913
1938
  examples.append(image)
1914
1939
  run.log({"examples": examples})
1915
- ```
1940
+ ```
1941
+
1942
+ Video from NumPy
1916
1943
 
1917
- ### Video from numpy
1918
- ```python
1919
- import numpy as np
1920
- import wandb
1944
+ ```python
1945
+ import numpy as np
1946
+ import wandb
1921
1947
 
1922
- run = wandb.init()
1948
+ with wandb.init() as run:
1923
1949
  # axes are (time, channel, height, width)
1924
1950
  frames = np.random.randint(
1925
1951
  low=0,
@@ -1928,35 +1954,38 @@ class Run:
1928
1954
  dtype=np.uint8,
1929
1955
  )
1930
1956
  run.log({"video": wandb.Video(frames, fps=4)})
1931
- ```
1957
+ ```
1958
+
1959
+ Matplotlib plot
1932
1960
 
1933
- ### Matplotlib Plot
1934
- ```python
1935
- from matplotlib import pyplot as plt
1936
- import numpy as np
1937
- import wandb
1961
+ ```python
1962
+ from matplotlib import pyplot as plt
1963
+ import numpy as np
1964
+ import wandb
1938
1965
 
1939
- run = wandb.init()
1966
+ with wandb.init() as run:
1940
1967
  fig, ax = plt.subplots()
1941
1968
  x = np.linspace(0, 10)
1942
1969
  y = x * x
1943
1970
  ax.plot(x, y) # plot y = x^2
1944
1971
  run.log({"chart": fig})
1945
- ```
1972
+ ```
1973
+
1974
+ PR Curve
1946
1975
 
1947
- ### PR Curve
1948
- ```python
1949
- import wandb
1976
+ ```python
1977
+ import wandb
1950
1978
 
1951
- run = wandb.init()
1979
+ with wandb.init() as run:
1952
1980
  run.log({"pr": wandb.plot.pr_curve(y_test, y_probas, labels)})
1953
- ```
1981
+ ```
1954
1982
 
1955
- ### 3D Object
1956
- ```python
1957
- import wandb
1983
+ 3D Object
1958
1984
 
1959
- run = wandb.init()
1985
+ ```python
1986
+ import wandb
1987
+
1988
+ with wandb.init() as run:
1960
1989
  run.log(
1961
1990
  {
1962
1991
  "generated_samples": [
@@ -1966,11 +1995,11 @@ class Run:
1966
1995
  ]
1967
1996
  }
1968
1997
  )
1969
- ```
1998
+ ```
1970
1999
 
1971
2000
  Raises:
1972
- wandb.Error: if called before `wandb.init`
1973
- ValueError: if invalid data is passed
2001
+ wandb.Error: If called before `wandb.init()`.
2002
+ ValueError: If invalid data is passed.
1974
2003
 
1975
2004
  """
1976
2005
  if step is not None:
@@ -2005,42 +2034,48 @@ class Run:
2005
2034
 
2006
2035
  A `base_path` may be provided to control the directory structure of
2007
2036
  uploaded files. It should be a prefix of `glob_str`, and the directory
2008
- structure beneath it is preserved. It's best understood through
2009
- examples:
2037
+ structure beneath it is preserved.
2010
2038
 
2011
- ```
2012
- wandb.save("these/are/myfiles/*")
2013
- # => Saves files in a "these/are/myfiles/" folder in the run.
2014
-
2015
- wandb.save("these/are/myfiles/*", base_path="these")
2016
- # => Saves files in an "are/myfiles/" folder in the run.
2017
-
2018
- wandb.save("/User/username/Documents/run123/*.txt")
2019
- # => Saves files in a "run123/" folder in the run. See note below.
2020
-
2021
- wandb.save("/User/username/Documents/run123/*.txt", base_path="/User")
2022
- # => Saves files in a "username/Documents/run123/" folder in the run.
2023
-
2024
- wandb.save("files/*/saveme.txt")
2025
- # => Saves each "saveme.txt" file in an appropriate subdirectory
2026
- # of "files/".
2027
- ```
2028
-
2029
- Note: when given an absolute path or glob and no `base_path`, one
2039
+ When given an absolute path or glob and no `base_path`, one
2030
2040
  directory level is preserved as in the example above.
2031
2041
 
2032
2042
  Args:
2033
2043
  glob_str: A relative or absolute path or Unix glob.
2034
2044
  base_path: A path to use to infer a directory structure; see examples.
2035
2045
  policy: One of `live`, `now`, or `end`.
2036
- * live: upload the file as it changes, overwriting the previous version
2037
- * now: upload the file once now
2038
- * end: upload file when the run ends
2046
+ - live: upload the file as it changes, overwriting the previous version
2047
+ - now: upload the file once now
2048
+ - end: upload file when the run ends
2039
2049
 
2040
2050
  Returns:
2041
2051
  Paths to the symlinks created for the matched files.
2042
2052
 
2043
2053
  For historical reasons, this may return a boolean in legacy code.
2054
+
2055
+ ```python
2056
+ import wandb
2057
+
2058
+ run = wandb.init()
2059
+
2060
+ run.save("these/are/myfiles/*")
2061
+ # => Saves files in a "these/are/myfiles/" folder in the run.
2062
+
2063
+ run.save("these/are/myfiles/*", base_path="these")
2064
+ # => Saves files in an "are/myfiles/" folder in the run.
2065
+
2066
+ run.save("/User/username/Documents/run123/*.txt")
2067
+ # => Saves files in a "run123/" folder in the run. See note below.
2068
+
2069
+ run.save("/User/username/Documents/run123/*.txt", base_path="/User")
2070
+ # => Saves files in a "username/Documents/run123/" folder in the run.
2071
+
2072
+ run.save("files/*/saveme.txt")
2073
+ # => Saves each "saveme.txt" file in an appropriate subdirectory
2074
+ # of "files/".
2075
+
2076
+ # Explicitly finish the run since a context manager is not used.
2077
+ run.finish()
2078
+ ```
2044
2079
  """
2045
2080
  if isinstance(glob_str, bytes):
2046
2081
  # Preserved for backward compatibility: allow bytes inputs.
@@ -2194,6 +2229,7 @@ class Run:
2194
2229
  - Crashed: Run that stopped sending heartbeats unexpectedly.
2195
2230
  - Finished: Run completed successfully (`exit_code=0`) with all data synced.
2196
2231
  - Failed: Run completed with errors (`exit_code!=0`).
2232
+ - Killed: Run was forcibly stopped before it could finish.
2197
2233
 
2198
2234
  Args:
2199
2235
  exit_code: Integer indicating the run's exit status. Use 0 for success,
@@ -2694,15 +2730,10 @@ class Run:
2694
2730
  ),
2695
2731
  )
2696
2732
 
2697
- # Print some final statistics.
2698
2733
  poll_exit_handle = self._backend.interface.deliver_poll_exit()
2699
2734
  result = poll_exit_handle.wait_or(timeout=None)
2700
- progress.print_sync_dedupe_stats(
2701
- self._printer,
2702
- result.response.poll_exit_response,
2703
- )
2704
-
2705
2735
  self._poll_exit_response = result.response.poll_exit_response
2736
+
2706
2737
  internal_messages_handle = self._backend.interface.deliver_internal_messages()
2707
2738
  result = internal_messages_handle.wait_or(timeout=None)
2708
2739
  self._internal_messages_response = result.response.internal_messages_response
@@ -2748,23 +2779,26 @@ class Run:
2748
2779
  goal: str | None = None,
2749
2780
  overwrite: bool | None = None,
2750
2781
  ) -> wandb_metric.Metric:
2751
- """Customize metrics logged with `wandb.log()`.
2782
+ """Customize metrics logged with `wandb.Run.log()`.
2752
2783
 
2753
2784
  Args:
2754
2785
  name: The name of the metric to customize.
2755
2786
  step_metric: The name of another metric to serve as the X-axis
2756
2787
  for this metric in automatically generated charts.
2757
2788
  step_sync: Automatically insert the last value of step_metric into
2758
- `run.log()` if it is not provided explicitly. Defaults to True
2789
+ `wandb.Run.log()` if it is not provided explicitly. Defaults to True
2759
2790
  if step_metric is specified.
2760
2791
  hidden: Hide this metric from automatic plots.
2761
2792
  summary: Specify aggregate metrics added to summary.
2762
2793
  Supported aggregations include "min", "max", "mean", "last",
2763
- "best", "copy" and "none". "best" is used together with the
2764
- goal parameter. "none" prevents a summary from being generated.
2765
- "copy" is deprecated and should not be used.
2794
+ "first", "best", "copy" and "none". "none" prevents a summary
2795
+ from being generated. "best" is used together with the goal
2796
+ parameter, "best" is deprecated and should not be used, use
2797
+ "min" or "max" instead. "copy" is deprecated and should not be
2798
+ used.
2766
2799
  goal: Specify how to interpret the "best" summary type.
2767
- Supported options are "minimize" and "maximize".
2800
+ Supported options are "minimize" and "maximize". "goal" is
2801
+ deprecated and should not be used, use "min" or "max" instead.
2768
2802
  overwrite: If false, then this call is merged with previous
2769
2803
  `define_metric` calls for the same metric by using their
2770
2804
  values for any unspecified parameters. If true, then
@@ -2837,7 +2871,7 @@ class Run:
2837
2871
  if summary:
2838
2872
  summary_items = [s.lower() for s in summary.split(",")]
2839
2873
  summary_ops = []
2840
- valid = {"min", "max", "mean", "best", "last", "copy", "none"}
2874
+ valid = {"min", "max", "mean", "best", "last", "copy", "none", "first"}
2841
2875
  # TODO: deprecate copy and best
2842
2876
  for i in summary_items:
2843
2877
  if i not in valid:
@@ -2888,29 +2922,22 @@ class Run:
2888
2922
  idx: int | None = None,
2889
2923
  log_graph: bool = False,
2890
2924
  ) -> None:
2891
- """Hooks into the given PyTorch model(s) to monitor gradients and the model's computational graph.
2925
+ """Hook into given PyTorch model to monitor gradients and the model's computational graph.
2892
2926
 
2893
- This function can track parameters, gradients, or both during training. It should be
2894
- extended to support arbitrary machine learning models in the future.
2927
+ This function can track parameters, gradients, or both during training.
2895
2928
 
2896
2929
  Args:
2897
- models (Union[torch.nn.Module, Sequence[torch.nn.Module]]):
2898
- A single model or a sequence of models to be monitored.
2899
- criterion (Optional[torch.F]):
2900
- The loss function being optimized (optional).
2901
- log (Optional[Literal["gradients", "parameters", "all"]]):
2902
- Specifies whether to log "gradients", "parameters", or "all".
2903
- Set to None to disable logging. (default="gradients")
2904
- log_freq (int):
2905
- Frequency (in batches) to log gradients and parameters. (default=1000)
2906
- idx (Optional[int]):
2907
- Index used when tracking multiple models with `wandb.watch`. (default=None)
2908
- log_graph (bool):
2909
- Whether to log the model's computational graph. (default=False)
2930
+ models: A single model or a sequence of models to be monitored.
2931
+ criterion: The loss function being optimized (optional).
2932
+ log: Specifies whether to log "gradients", "parameters", or "all".
2933
+ Set to None to disable logging. (default="gradients").
2934
+ log_freq: Frequency (in batches) to log gradients and parameters. (default=1000)
2935
+ idx: Index used when tracking multiple models with `wandb.watch`. (default=None)
2936
+ log_graph: Whether to log the model's computational graph. (default=False)
2910
2937
 
2911
2938
  Raises:
2912
2939
  ValueError:
2913
- If `wandb.init` has not been called or if any of the models are not instances
2940
+ If `wandb.init()` has not been called or if any of the models are not instances
2914
2941
  of `torch.nn.Module`.
2915
2942
  """
2916
2943
  wandb.sdk._watch(self, models, criterion, log, log_freq, idx, log_graph)
@@ -2923,8 +2950,7 @@ class Run:
2923
2950
  """Remove pytorch model topology, gradient and parameter hooks.
2924
2951
 
2925
2952
  Args:
2926
- models (torch.nn.Module | Sequence[torch.nn.Module]):
2927
- Optional list of pytorch models that have had watch called on them
2953
+ models: Optional list of pytorch models that have had watch called on them.
2928
2954
  """
2929
2955
  wandb.sdk._unwatch(self, models=models)
2930
2956
 
@@ -2939,7 +2965,7 @@ class Run:
2939
2965
  ) -> Artifact | None:
2940
2966
  """Link the given artifact to a portfolio (a promoted collection of artifacts).
2941
2967
 
2942
- The linked artifact will be visible in the UI for the specified portfolio.
2968
+ Linked artifacts are visible in the UI for the specified portfolio.
2943
2969
 
2944
2970
  Args:
2945
2971
  artifact: the (public or local) artifact which will be linked
@@ -2987,19 +3013,46 @@ class Run:
2987
3013
  Call `download` or `file` on the returned object to get the contents locally.
2988
3014
 
2989
3015
  Args:
2990
- artifact_or_name: (str or Artifact) An artifact name.
2991
- May be prefixed with project/ or entity/project/.
2992
- If no entity is specified in the name, the Run or API setting's entity is used.
2993
- Valid names can be in the following forms:
2994
- - name:version
2995
- - name:alias
2996
- You can also pass an Artifact object created by calling `wandb.Artifact`
2997
- type: (str, optional) The type of artifact to use.
2998
- aliases: (list, optional) Aliases to apply to this artifact
3016
+ artifact_or_name: The name of the artifact to use. May be prefixed
3017
+ with the name of the project the artifact was logged to
3018
+ ("<entity>" or "<entity>/<project>"). If no
3019
+ entity is specified in the name, the Run or API setting's entity is used.
3020
+ Valid names can be in the following forms
3021
+ - name:version
3022
+ - name:alias
3023
+ type: The type of artifact to use.
3024
+ aliases: Aliases to apply to this artifact
2999
3025
  use_as: This argument is deprecated and does nothing.
3000
3026
 
3001
3027
  Returns:
3002
3028
  An `Artifact` object.
3029
+
3030
+ Examples:
3031
+ ```python
3032
+ import wandb
3033
+
3034
+ run = wandb.init(project="<example>")
3035
+
3036
+ # Use an artifact by name and alias
3037
+ artifact_a = run.use_artifact(artifact_or_name="<name>:<alias>")
3038
+
3039
+ # Use an artifact by name and version
3040
+ artifact_b = run.use_artifact(artifact_or_name="<name>:v<version>")
3041
+
3042
+ # Use an artifact by entity/project/name:alias
3043
+ artifact_c = run.use_artifact(
3044
+ artifact_or_name="<entity>/<project>/<name>:<alias>"
3045
+ )
3046
+
3047
+ # Use an artifact by entity/project/name:version
3048
+ artifact_d = run.use_artifact(
3049
+ artifact_or_name="<entity>/<project>/<name>:v<version>"
3050
+ )
3051
+
3052
+ # Explicitly finish the run since a context manager is not used.
3053
+ run.finish()
3054
+ ```
3055
+
3003
3056
  """
3004
3057
  if self._settings._offline:
3005
3058
  raise TypeError("Cannot use artifact when in offline mode.")
@@ -3128,24 +3181,20 @@ class Run:
3128
3181
  This is useful when distributed jobs need to all contribute to the same artifact.
3129
3182
 
3130
3183
  Args:
3131
- artifact_or_path: (str or Artifact) A path to the contents of this artifact,
3184
+ artifact_or_path: A path to the contents of this artifact,
3132
3185
  can be in the following forms:
3133
- - `/local/directory`
3134
- - `/local/directory/file.txt`
3135
- - `s3://bucket/path`
3136
- You can also pass an Artifact object created by calling
3137
- `wandb.Artifact`.
3138
- name: (str, optional) An artifact name. May be prefixed with entity/project.
3139
- Valid names can be in the following forms:
3140
- - name:version
3141
- - name:alias
3142
- - digest
3143
- This will default to the basename of the path prepended with the current
3144
- run id if not specified.
3145
- type: (str) The type of artifact to log, examples include `dataset`, `model`
3146
- aliases: (list, optional) Aliases to apply to this artifact,
3147
- defaults to `["latest"]`
3148
- distributed_id: (string, optional) Unique string that all distributed jobs share. If None,
3186
+ - `/local/directory`
3187
+ - `/local/directory/file.txt`
3188
+ - `s3://bucket/path`
3189
+ name: An artifact name. May be prefixed with "entity/project". Defaults
3190
+ to the basename of the path prepended with the current run ID
3191
+ if not specified. Valid names can be in the following forms:
3192
+ - name:version
3193
+ - name:alias
3194
+ - digest
3195
+ type: The type of artifact to log. Common examples include `dataset`, `model`.
3196
+ aliases: Aliases to apply to this artifact, defaults to `["latest"]`.
3197
+ distributed_id: Unique string that all distributed jobs share. If None,
3149
3198
  defaults to the run's group name.
3150
3199
 
3151
3200
  Returns:
@@ -3182,24 +3231,24 @@ class Run:
3182
3231
  Subsequent "upserts" with the same distributed ID will result in a new version.
3183
3232
 
3184
3233
  Args:
3185
- artifact_or_path: (str or Artifact) A path to the contents of this artifact,
3234
+ artifact_or_path: A path to the contents of this artifact,
3186
3235
  can be in the following forms:
3187
3236
  - `/local/directory`
3188
3237
  - `/local/directory/file.txt`
3189
3238
  - `s3://bucket/path`
3190
3239
  You can also pass an Artifact object created by calling
3191
3240
  `wandb.Artifact`.
3192
- name: (str, optional) An artifact name. May be prefixed with entity/project.
3241
+ name: An artifact name. May be prefixed with entity/project.
3193
3242
  Valid names can be in the following forms:
3194
3243
  - name:version
3195
3244
  - name:alias
3196
3245
  - digest
3197
3246
  This will default to the basename of the path prepended with the current
3198
3247
  run id if not specified.
3199
- type: (str) The type of artifact to log, examples include `dataset`, `model`
3200
- aliases: (list, optional) Aliases to apply to this artifact,
3248
+ type: The type of artifact to log, examples include `dataset`, `model`
3249
+ aliases: Aliases to apply to this artifact,
3201
3250
  defaults to `["latest"]`
3202
- distributed_id: (string, optional) Unique string that all distributed jobs share. If None,
3251
+ distributed_id: Unique string that all distributed jobs share. If None,
3203
3252
  defaults to the run's group name.
3204
3253
 
3205
3254
  Returns:
@@ -3379,39 +3428,24 @@ class Run:
3379
3428
  ) -> None:
3380
3429
  """Logs a model artifact containing the contents inside the 'path' to a run and marks it as an output to this run.
3381
3430
 
3431
+ The name of model artifact can only contain alphanumeric characters,
3432
+ underscores, and hyphens.
3433
+
3382
3434
  Args:
3383
3435
  path: (str) A path to the contents of this model,
3384
3436
  can be in the following forms:
3385
3437
  - `/local/directory`
3386
3438
  - `/local/directory/file.txt`
3387
3439
  - `s3://bucket/path`
3388
- name: (str, optional) A name to assign to the model artifact that the file contents will be added to.
3389
- The string must contain only the following alphanumeric characters: dashes, underscores, and dots.
3390
- This will default to the basename of the path prepended with the current
3391
- run id if not specified.
3392
- aliases: (list, optional) Aliases to apply to the created model artifact,
3440
+ name: A name to assign to the model artifact that
3441
+ the file contents will be added to. This will default to the
3442
+ basename of the path prepended with the current run id if
3443
+ not specified.
3444
+ aliases: Aliases to apply to the created model artifact,
3393
3445
  defaults to `["latest"]`
3394
3446
 
3395
- Examples:
3396
- ```python
3397
- run.log_model(
3398
- path="/local/directory",
3399
- name="my_model_artifact",
3400
- aliases=["production"],
3401
- )
3402
- ```
3403
-
3404
- Invalid usage
3405
- ```python
3406
- run.log_model(
3407
- path="/local/directory",
3408
- name="my_entity/my_project/my_model_artifact",
3409
- aliases=["production"],
3410
- )
3411
- ```
3412
-
3413
3447
  Raises:
3414
- ValueError: if name has invalid special characters
3448
+ ValueError: If name has invalid special characters.
3415
3449
 
3416
3450
  Returns:
3417
3451
  None
@@ -3427,40 +3461,18 @@ class Run:
3427
3461
  """Download the files logged in a model artifact 'name'.
3428
3462
 
3429
3463
  Args:
3430
- name: (str) A model artifact name. 'name' must match the name of an existing logged
3431
- model artifact.
3432
- May be prefixed with entity/project/. Valid names
3433
- can be in the following forms:
3434
- - model_artifact_name:version
3435
- - model_artifact_name:alias
3436
-
3437
- Examples:
3438
- ```python
3439
- run.use_model(
3440
- name="my_model_artifact:latest",
3441
- )
3464
+ name: A model artifact name. 'name' must match the name of an existing logged
3465
+ model artifact. May be prefixed with `entity/project/`. Valid names
3466
+ can be in the following forms
3467
+ - model_artifact_name:version
3468
+ - model_artifact_name:alias
3442
3469
 
3443
- run.use_model(
3444
- name="my_project/my_model_artifact:v0",
3445
- )
3446
-
3447
- run.use_model(
3448
- name="my_entity/my_project/my_model_artifact:<digest>",
3449
- )
3450
- ```
3451
-
3452
- Invalid usage
3453
- ```python
3454
- run.use_model(
3455
- name="my_entity/my_project/my_model_artifact",
3456
- )
3457
- ```
3470
+ Returns:
3471
+ path (str): Path to downloaded model artifact file(s).
3458
3472
 
3459
3473
  Raises:
3460
- AssertionError: if model artifact 'name' is of a type that does not contain the substring 'model'.
3461
-
3462
- Returns:
3463
- path: (str) path to downloaded model artifact file(s).
3474
+ AssertionError: If model artifact 'name' is of a type that does
3475
+ not contain the substring 'model'.
3464
3476
  """
3465
3477
  if self._settings._offline:
3466
3478
  # Downloading artifacts is not supported when offline.
@@ -3494,66 +3506,43 @@ class Run:
3494
3506
  ) -> Artifact | None:
3495
3507
  """Log a model artifact version and link it to a registered model in the model registry.
3496
3508
 
3497
- The linked model version will be visible in the UI for the specified registered model.
3509
+ Linked model versions are visible in the UI for the specified registered model.
3498
3510
 
3499
- Steps:
3500
- - Check if 'name' model artifact has been logged. If so, use the artifact version that matches the files
3501
- located at 'path' or log a new version. Otherwise log files under 'path' as a new model artifact, 'name'
3502
- of type 'model'.
3503
- - Check if registered model with name 'registered_model_name' exists in the 'model-registry' project.
3504
- If not, create a new registered model with name 'registered_model_name'.
3505
- - Link version of model artifact 'name' to registered model, 'registered_model_name'.
3506
- - Attach aliases from 'aliases' list to the newly linked model artifact version.
3511
+ This method will:
3512
+ - Check if 'name' model artifact has been logged. If so, use the artifact version that matches the files
3513
+ located at 'path' or log a new version. Otherwise log files under 'path' as a new model artifact, 'name'
3514
+ of type 'model'.
3515
+ - Check if registered model with name 'registered_model_name' exists in the 'model-registry' project.
3516
+ If not, create a new registered model with name 'registered_model_name'.
3517
+ - Link version of model artifact 'name' to registered model, 'registered_model_name'.
3518
+ - Attach aliases from 'aliases' list to the newly linked model artifact version.
3507
3519
 
3508
3520
  Args:
3509
- path: (str) A path to the contents of this model,
3510
- can be in the following forms:
3511
- - `/local/directory`
3512
- - `/local/directory/file.txt`
3513
- - `s3://bucket/path`
3514
- registered_model_name: (str) - the name of the registered model that the model is to be linked to.
3515
- A registered model is a collection of model versions linked to the model registry, typically representing a
3516
- team's specific ML Task. The entity that this registered model belongs to will be derived from the run
3517
- name: (str, optional) - the name of the model artifact that files in 'path' will be logged to. This will
3518
- default to the basename of the path prepended with the current run id if not specified.
3519
- aliases: (List[str], optional) - alias(es) that will only be applied on this linked artifact
3520
- inside the registered model.
3521
- The alias "latest" will always be applied to the latest version of an artifact that is linked.
3522
-
3523
- Examples:
3524
- ```python
3525
- run.link_model(
3526
- path="/local/directory",
3527
- registered_model_name="my_reg_model",
3528
- name="my_model_artifact",
3529
- aliases=["production"],
3530
- )
3531
- ```
3532
-
3533
- Invalid usage
3534
- ```python
3535
- run.link_model(
3536
- path="/local/directory",
3537
- registered_model_name="my_entity/my_project/my_reg_model",
3538
- name="my_model_artifact",
3539
- aliases=["production"],
3540
- )
3541
-
3542
- run.link_model(
3543
- path="/local/directory",
3544
- registered_model_name="my_reg_model",
3545
- name="my_entity/my_project/my_model_artifact",
3546
- aliases=["production"],
3547
- )
3548
- ```
3521
+ path: (str) A path to the contents of this model, can be in the
3522
+ following forms:
3523
+ - `/local/directory`
3524
+ - `/local/directory/file.txt`
3525
+ - `s3://bucket/path`
3526
+ registered_model_name: The name of the registered model that the
3527
+ model is to be linked to. A registered model is a collection of
3528
+ model versions linked to the model registry, typically
3529
+ representing a team's specific ML Task. The entity that this
3530
+ registered model belongs to will be derived from the run.
3531
+ name: The name of the model artifact that files in 'path' will be
3532
+ logged to. This will default to the basename of the path
3533
+ prepended with the current run id if not specified.
3534
+ aliases: Aliases that will only be applied on this linked artifact
3535
+ inside the registered model. The alias "latest" will always be
3536
+ applied to the latest version of an artifact that is linked.
3549
3537
 
3550
3538
  Raises:
3551
- AssertionError: if registered_model_name is a path or
3552
- if model artifact 'name' is of a type that does not contain the substring 'model'
3553
- ValueError: if name has invalid special characters
3539
+ AssertionError: If registered_model_name is a path or
3540
+ if model artifact 'name' is of a type that does not contain
3541
+ the substring 'model'.
3542
+ ValueError: If name has invalid special characters.
3554
3543
 
3555
3544
  Returns:
3556
- The linked artifact if linking was successful, otherwise None.
3545
+ The linked artifact if linking was successful, otherwise `None`.
3557
3546
  """
3558
3547
  name_parts = registered_model_name.split("/")
3559
3548
  if len(name_parts) != 1:
@@ -3596,13 +3585,13 @@ class Run:
3596
3585
  level: str | AlertLevel | None = None,
3597
3586
  wait_duration: int | float | timedelta | None = None,
3598
3587
  ) -> None:
3599
- """Launch an alert with the given title and text.
3588
+ """Create an alert with the given title and text.
3600
3589
 
3601
3590
  Args:
3602
- title: (str) The title of the alert, must be less than 64 characters long.
3603
- text: (str) The text body of the alert.
3604
- level: (str or AlertLevel, optional) The alert level to use, either: `INFO`, `WARN`, or `ERROR`.
3605
- wait_duration: (int, float, or timedelta, optional) The time to wait (in seconds) before sending another
3591
+ title: The title of the alert, must be less than 64 characters long.
3592
+ text: The text body of the alert.
3593
+ level: The alert level to use, either: `INFO`, `WARN`, or `ERROR`.
3594
+ wait_duration: The time to wait (in seconds) before sending another
3606
3595
  alert with this title.
3607
3596
  """
3608
3597
  level = level or AlertLevel.INFO
@@ -3714,24 +3703,27 @@ class Run:
3714
3703
  self._printer.display(f"Tracking run with wandb version {wandb.__version__}")
3715
3704
 
3716
3705
  def _header_sync_info(self) -> None:
3706
+ sync_location_msg = f"Run data is saved locally in {self._printer.files(self._settings.sync_dir)}"
3707
+
3717
3708
  if self._settings._offline:
3718
- self._printer.display(
3719
- [
3720
- f"W&B syncing is set to {self._printer.code('`offline`')}"
3721
- f" in this directory. Run {self._printer.code('`wandb online`')}"
3722
- f" or set {self._printer.code('WANDB_MODE=online')}"
3723
- " to enable cloud syncing.",
3724
- ]
3709
+ offline_warning = (
3710
+ f"W&B syncing is set to {self._printer.code('`offline`')} "
3711
+ f"in this directory. Run {self._printer.code('`wandb online`')} "
3712
+ f"or set {self._printer.code('WANDB_MODE=online')} "
3713
+ "to enable cloud syncing."
3725
3714
  )
3715
+ self._printer.display([offline_warning, sync_location_msg])
3726
3716
  else:
3727
- sync_dir = self._settings.sync_dir
3728
- info = [f"Run data is saved locally in {self._printer.files(sync_dir)}"]
3717
+ messages = [sync_location_msg]
3718
+
3729
3719
  if not self._printer.supports_html:
3730
- info.append(
3720
+ disable_sync_msg = (
3731
3721
  f"Run {self._printer.code('`wandb offline`')} to turn off syncing."
3732
3722
  )
3723
+ messages.append(disable_sync_msg)
3724
+
3733
3725
  if not self._settings.quiet and not self._settings.silent:
3734
- self._printer.display(info)
3726
+ self._printer.display(messages)
3735
3727
 
3736
3728
  def _header_run_info(self) -> None:
3737
3729
  settings, printer = self._settings, self._printer
@@ -3985,19 +3977,19 @@ def restore(
3985
3977
  By default, will only download the file if it doesn't already exist.
3986
3978
 
3987
3979
  Args:
3988
- name: the name of the file
3989
- run_path: optional path to a run to pull files from, i.e. `username/project_name/run_id`
3980
+ name: The name of the file.
3981
+ run_path: Optional path to a run to pull files from, i.e. `username/project_name/run_id`
3990
3982
  if wandb.init has not been called, this is required.
3991
- replace: whether to download the file even if it already exists locally
3992
- root: the directory to download the file to. Defaults to the current
3983
+ replace: Whether to download the file even if it already exists locally
3984
+ root: The directory to download the file to. Defaults to the current
3993
3985
  directory or the run directory if wandb.init was called.
3994
3986
 
3995
3987
  Returns:
3996
- None if it can't find the file, otherwise a file object open for reading
3988
+ None if it can't find the file, otherwise a file object open for reading.
3997
3989
 
3998
3990
  Raises:
3999
- wandb.CommError: if we can't connect to the wandb backend
4000
- ValueError: if the file is not found or can't find run_path
3991
+ CommError: If W&B can't connect to the W&B backend.
3992
+ ValueError: If the file is not found or can't find run_path.
4001
3993
  """
4002
3994
  is_disabled = wandb.run is not None and wandb.run.disabled
4003
3995
  run = None if is_disabled else wandb.run