wandb 0.18.4__py3-none-any.whl → 0.18.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. wandb/__init__.py +2 -2
  2. wandb/__init__.pyi +21 -19
  3. wandb/agents/pyagent.py +1 -1
  4. wandb/apis/importers/wandb.py +1 -1
  5. wandb/apis/normalize.py +2 -18
  6. wandb/apis/public/api.py +122 -62
  7. wandb/apis/public/artifacts.py +8 -3
  8. wandb/apis/public/files.py +17 -2
  9. wandb/apis/public/jobs.py +2 -2
  10. wandb/apis/public/query_generator.py +1 -1
  11. wandb/apis/public/runs.py +8 -8
  12. wandb/apis/public/teams.py +3 -3
  13. wandb/apis/public/users.py +1 -1
  14. wandb/apis/public/utils.py +68 -0
  15. wandb/bin/gpu_stats +0 -0
  16. wandb/cli/cli.py +12 -3
  17. wandb/data_types.py +1 -1
  18. wandb/docker/__init__.py +2 -1
  19. wandb/docker/auth.py +2 -3
  20. wandb/errors/links.py +73 -0
  21. wandb/errors/term.py +7 -6
  22. wandb/filesync/step_prepare.py +1 -1
  23. wandb/filesync/upload_job.py +1 -1
  24. wandb/integration/catboost/catboost.py +2 -2
  25. wandb/integration/diffusers/pipeline_resolver.py +1 -1
  26. wandb/integration/diffusers/resolvers/multimodal.py +6 -6
  27. wandb/integration/diffusers/resolvers/utils.py +1 -1
  28. wandb/integration/fastai/__init__.py +3 -2
  29. wandb/integration/keras/callbacks/metrics_logger.py +1 -1
  30. wandb/integration/keras/callbacks/model_checkpoint.py +1 -1
  31. wandb/integration/keras/keras.py +1 -1
  32. wandb/integration/kfp/kfp_patch.py +1 -1
  33. wandb/integration/lightgbm/__init__.py +2 -2
  34. wandb/integration/magic.py +2 -2
  35. wandb/integration/metaflow/metaflow.py +1 -1
  36. wandb/integration/sacred/__init__.py +1 -1
  37. wandb/integration/sagemaker/auth.py +1 -1
  38. wandb/integration/sklearn/plot/classifier.py +7 -7
  39. wandb/integration/sklearn/plot/clusterer.py +3 -3
  40. wandb/integration/sklearn/plot/regressor.py +3 -3
  41. wandb/integration/sklearn/plot/shared.py +2 -2
  42. wandb/integration/tensorboard/log.py +2 -2
  43. wandb/integration/ultralytics/callback.py +2 -2
  44. wandb/integration/xgboost/xgboost.py +1 -1
  45. wandb/jupyter.py +0 -1
  46. wandb/plot/__init__.py +17 -8
  47. wandb/plot/bar.py +53 -27
  48. wandb/plot/confusion_matrix.py +151 -70
  49. wandb/plot/custom_chart.py +124 -0
  50. wandb/plot/histogram.py +46 -20
  51. wandb/plot/line.py +57 -26
  52. wandb/plot/line_series.py +148 -60
  53. wandb/plot/pr_curve.py +89 -44
  54. wandb/plot/roc_curve.py +82 -37
  55. wandb/plot/scatter.py +53 -20
  56. wandb/plot/viz.py +20 -102
  57. wandb/sdk/artifacts/artifact.py +280 -328
  58. wandb/sdk/artifacts/artifact_manifest.py +10 -9
  59. wandb/sdk/artifacts/artifact_manifest_entry.py +1 -1
  60. wandb/sdk/artifacts/storage_handlers/azure_handler.py +9 -4
  61. wandb/sdk/artifacts/storage_handlers/gcs_handler.py +1 -3
  62. wandb/sdk/artifacts/storage_handlers/s3_handler.py +1 -1
  63. wandb/sdk/artifacts/storage_handlers/wb_artifact_handler.py +2 -2
  64. wandb/sdk/artifacts/storage_handlers/wb_local_artifact_handler.py +1 -1
  65. wandb/sdk/backend/backend.py +0 -1
  66. wandb/sdk/data_types/audio.py +1 -1
  67. wandb/sdk/data_types/base_types/media.py +66 -5
  68. wandb/sdk/data_types/bokeh.py +1 -1
  69. wandb/sdk/data_types/helper_types/bounding_boxes_2d.py +1 -1
  70. wandb/sdk/data_types/helper_types/image_mask.py +2 -2
  71. wandb/sdk/data_types/histogram.py +1 -1
  72. wandb/sdk/data_types/html.py +1 -1
  73. wandb/sdk/data_types/image.py +1 -1
  74. wandb/sdk/data_types/molecule.py +3 -3
  75. wandb/sdk/data_types/object_3d.py +4 -4
  76. wandb/sdk/data_types/plotly.py +1 -1
  77. wandb/sdk/data_types/saved_model.py +0 -1
  78. wandb/sdk/data_types/table.py +7 -7
  79. wandb/sdk/data_types/trace_tree.py +1 -1
  80. wandb/sdk/data_types/video.py +4 -3
  81. wandb/sdk/interface/router.py +0 -2
  82. wandb/sdk/internal/datastore.py +1 -1
  83. wandb/sdk/internal/file_pusher.py +1 -1
  84. wandb/sdk/internal/file_stream.py +4 -4
  85. wandb/sdk/internal/handler.py +3 -2
  86. wandb/sdk/internal/internal.py +1 -1
  87. wandb/sdk/internal/internal_api.py +183 -64
  88. wandb/sdk/internal/job_builder.py +4 -3
  89. wandb/sdk/internal/system/assets/__init__.py +0 -2
  90. wandb/sdk/internal/tb_watcher.py +11 -10
  91. wandb/sdk/launch/_launch.py +4 -3
  92. wandb/sdk/launch/_launch_add.py +2 -2
  93. wandb/sdk/launch/builder/kaniko_builder.py +0 -1
  94. wandb/sdk/launch/create_job.py +1 -0
  95. wandb/sdk/launch/environment/local_environment.py +0 -1
  96. wandb/sdk/launch/errors.py +0 -6
  97. wandb/sdk/launch/registry/local_registry.py +0 -2
  98. wandb/sdk/launch/runner/abstract.py +0 -5
  99. wandb/sdk/launch/sweeps/__init__.py +0 -2
  100. wandb/sdk/launch/sweeps/scheduler.py +0 -2
  101. wandb/sdk/launch/sweeps/scheduler_sweep.py +0 -1
  102. wandb/sdk/lib/apikey.py +3 -3
  103. wandb/sdk/lib/file_stream_utils.py +1 -1
  104. wandb/sdk/lib/filesystem.py +1 -1
  105. wandb/sdk/lib/ipython.py +16 -9
  106. wandb/sdk/lib/mailbox.py +0 -4
  107. wandb/sdk/lib/printer.py +44 -8
  108. wandb/sdk/lib/retry.py +1 -1
  109. wandb/sdk/service/service.py +3 -3
  110. wandb/sdk/service/streams.py +2 -4
  111. wandb/sdk/wandb_init.py +20 -20
  112. wandb/sdk/wandb_login.py +1 -1
  113. wandb/sdk/wandb_require.py +1 -4
  114. wandb/sdk/wandb_run.py +57 -69
  115. wandb/sdk/wandb_settings.py +3 -4
  116. wandb/sdk/wandb_sync.py +2 -1
  117. wandb/util.py +46 -18
  118. wandb/wandb_agent.py +3 -3
  119. wandb/wandb_controller.py +2 -2
  120. {wandb-0.18.4.dist-info → wandb-0.18.6.dist-info}/METADATA +1 -1
  121. {wandb-0.18.4.dist-info → wandb-0.18.6.dist-info}/RECORD +124 -125
  122. wandb/sdk/internal/system/assets/gpu_apple.py +0 -177
  123. wandb/sdk/lib/_wburls_generate.py +0 -25
  124. wandb/sdk/lib/_wburls_generated.py +0 -22
  125. wandb/sdk/lib/wburls.py +0 -46
  126. {wandb-0.18.4.dist-info → wandb-0.18.6.dist-info}/WHEEL +0 -0
  127. {wandb-0.18.4.dist-info → wandb-0.18.6.dist-info}/entry_points.txt +0 -0
  128. {wandb-0.18.4.dist-info → wandb-0.18.6.dist-info}/licenses/LICENSE +0 -0
wandb/plot/roc_curve.py CHANGED
@@ -1,40 +1,84 @@
1
- from typing import Optional
1
+ from __future__ import annotations
2
+
3
+ import numbers
4
+ from typing import TYPE_CHECKING, Sequence
2
5
 
3
6
  import wandb
4
7
  from wandb import util
8
+ from wandb.plot.custom_chart import plot_table
9
+ from wandb.plot.utils import test_missing, test_types
5
10
 
6
- from .utils import test_missing, test_types
11
+ if TYPE_CHECKING:
12
+ from wandb.plot.custom_chart import CustomChart
7
13
 
8
14
 
9
15
  def roc_curve(
10
- y_true=None,
11
- y_probas=None,
12
- labels=None,
13
- classes_to_plot=None,
14
- title=None,
15
- split_table: Optional[bool] = False,
16
- ):
17
- """Calculate and visualize receiver operating characteristic (ROC) scores.
18
-
19
- Arguments:
20
- y_true (arr): true sparse labels
21
- y_probas (arr): Target scores, can either be probability estimates, confidence
22
- values, or non-thresholded measure of decisions.
23
- shape: (*y_true.shape, num_classes)
24
- labels (list): Named labels for target variable (y). Makes plots easier to
25
- read by replacing target values with corresponding index.
26
- For example labels = ['dog', 'cat', 'owl'] all 0s are
27
- replaced by 'dog', 1s by 'cat'.
28
- classes_to_plot (list): unique values of y_true to include in the plot
29
- split_table (bool): If True, adds "Custom Chart Tables/" to the key of the table so that it's logged in a different section.
16
+ y_true: Sequence[numbers.Number],
17
+ y_probas: Sequence[Sequence[float]] | None = None,
18
+ labels: list[str] | None = None,
19
+ classes_to_plot: list[numbers.Number] | None = None,
20
+ title: str = "ROC Curve",
21
+ split_table: bool = False,
22
+ ) -> CustomChart:
23
+ """Constructs Receiver Operating Characteristic (ROC) curve chart.
24
+
25
+ Args:
26
+ y_true (Sequence[numbers.Number]): The true class labels (ground truth)
27
+ for the target variable. Shape should be (num_samples,).
28
+ y_probas (Sequence[Sequence[float]]): The predicted probabilities or
29
+ decision scores for each class. Shape should be (num_samples, num_classes).
30
+ labels (list[str]): Human-readable labels corresponding to the class
31
+ indices in `y_true`. For example, if `labels=['dog', 'cat']`,
32
+ class 0 will be displayed as 'dog' and class 1 as 'cat' in the plot.
33
+ If None, the raw class indices from `y_true` will be used.
34
+ Default is None.
35
+ classes_to_plot (list[numbers.Number]): A subset of unique class labels
36
+ to include in the ROC curve. If None, all classes in `y_true` will
37
+ be plotted. Default is None.
38
+ title (str): Title of the ROC curve plot. Default is "ROC Curve".
39
+ split_table (bool): Whether the table should be split into a separate
40
+ section in the W&B UI. If `True`, the table will be displayed in a
41
+ section named "Custom Chart Tables". Default is `False`.
30
42
 
31
43
  Returns:
32
- Nothing. To see plots, go to your W&B run page then expand the 'media' tab
33
- under 'auto visualizations'.
44
+ CustomChart: A custom chart object that can be logged to W&B. To log the
45
+ chart, pass it to `wandb.log()`.
46
+
47
+ Raises:
48
+ wandb.Error: If numpy, pandas, or scikit-learn are not found.
34
49
 
35
50
  Example:
36
51
  ```
37
- wandb.log({'roc-curve': wandb.plot.roc_curve(y_true, y_probas, labels)})
52
+ import numpy as np
53
+ import wandb
54
+
55
+ # Simulate a medical diagnosis classification problem with three diseases
56
+ n_samples = 200
57
+ n_classes = 3
58
+
59
+ # True labels: assign "Diabetes", "Hypertension", or "Heart Disease" to
60
+ # each sample
61
+ disease_labels = ["Diabetes", "Hypertension", "Heart Disease"]
62
+ # 0: Diabetes, 1: Hypertension, 2: Heart Disease
63
+ y_true = np.random.choice([0, 1, 2], size=n_samples)
64
+
65
+ # Predicted probabilities: simulate predictions, ensuring they sum to 1
66
+ # for each sample
67
+ y_probas = np.random.dirichlet(np.ones(n_classes), size=n_samples)
68
+
69
+ # Specify classes to plot (plotting all three diseases)
70
+ classes_to_plot = [0, 1, 2]
71
+
72
+ # Initialize a W&B run and log a ROC curve plot for disease classification
73
+ with wandb.init(project="medical_diagnosis") as run:
74
+ roc_plot = wandb.plot.roc_curve(
75
+ y_true=y_true,
76
+ y_probas=y_probas,
77
+ labels=disease_labels,
78
+ classes_to_plot=classes_to_plot,
79
+ title="ROC Curve for Disease Classification",
80
+ )
81
+ run.log({"roc-curve": roc_plot})
38
82
  ```
39
83
  """
40
84
  np = util.get_module(
@@ -66,8 +110,8 @@ def roc_curve(
66
110
  if classes_to_plot is None:
67
111
  classes_to_plot = classes
68
112
 
69
- fpr = dict()
70
- tpr = dict()
113
+ fpr = {}
114
+ tpr = {}
71
115
  indices_to_plot = np.where(np.isin(classes, classes_to_plot))[0]
72
116
  for i in indices_to_plot:
73
117
  if labels is not None and (
@@ -87,12 +131,11 @@ def roc_curve(
87
131
  "fpr": np.hstack(list(fpr.values())),
88
132
  "tpr": np.hstack(list(tpr.values())),
89
133
  }
90
- )
91
- df = df.round(3)
134
+ ).round(3)
92
135
 
93
136
  if len(df) > wandb.Table.MAX_ROWS:
94
137
  wandb.termwarn(
95
- "wandb uses only %d data points to create the plots." % wandb.Table.MAX_ROWS
138
+ f"wandb uses only {wandb.Table.MAX_ROWS} data points to create the plots."
96
139
  )
97
140
  # different sampling could be applied, possibly to ensure endpoints are kept
98
141
  df = sklearn_utils.resample(
@@ -103,13 +146,15 @@ def roc_curve(
103
146
  stratify=df["class"],
104
147
  ).sort_values(["fpr", "tpr", "class"])
105
148
 
106
- table = wandb.Table(dataframe=df)
107
- title = title or "ROC"
108
- return wandb.plot_table(
109
- "wandb/area-under-curve/v0",
110
- table,
111
- {"x": "fpr", "y": "tpr", "class": "class"},
112
- {
149
+ return plot_table(
150
+ data_table=wandb.Table(dataframe=df),
151
+ vega_spec_name="wandb/area-under-curve/v0",
152
+ fields={
153
+ "x": "fpr",
154
+ "y": "tpr",
155
+ "class": "class",
156
+ },
157
+ string_fields={
113
158
  "title": title,
114
159
  "x-axis-title": "False positive rate",
115
160
  "y-axis-title": "True positive rate",
wandb/plot/scatter.py CHANGED
@@ -1,32 +1,65 @@
1
- from typing import Optional
1
+ from __future__ import annotations
2
2
 
3
- import wandb
3
+ from typing import TYPE_CHECKING
4
4
 
5
+ from wandb.plot.custom_chart import plot_table
5
6
 
6
- def scatter(table, x, y, title=None, split_table: Optional[bool] = False):
7
- """Construct a scatter plot.
7
+ if TYPE_CHECKING:
8
+ import wandb
9
+ from wandb.plot.custom_chart import CustomChart
8
10
 
9
- Arguments:
10
- table (wandb.Table): Table of data.
11
- x (string): Name of column to as for x-axis values.
12
- y (string): Name of column to as for y-axis values.
13
- title (string): Plot title.
14
- split_table (bool): If True, adds "Custom Chart Tables/" to the key of the table so that it's logged in a different section.
15
11
 
16
- Returns:
17
- A plot object, to be passed to wandb.log()
12
+ def scatter(
13
+ table: wandb.Table,
14
+ x: str,
15
+ y: str,
16
+ title: str = "",
17
+ split_table: bool = False,
18
+ ) -> CustomChart:
19
+ """Constructs a scatter plot from a wandb.Table of data.
20
+
21
+ Args:
22
+ table (wandb.Table): The W&B Table containing the data to visualize.
23
+ x (str): The name of the column used for the x-axis.
24
+ y (str): The name of the column used for the y-axis.
25
+ title (str): The title of the scatter chart.
26
+ split_table (bool): Whether the table should be split into a separate section
27
+ in the W&B UI. If `True`, the table will be displayed in a section named
28
+ "Custom Chart Tables". Default is `False`.
18
29
 
30
+ Returns:
31
+ CustomChart: A custom chart object that can be logged to W&B. To log the
32
+ chart, pass it to `wandb.log()`.
19
33
  Example:
20
34
  ```
21
- data = [[i, random.random() + math.sin(i / 10)] for i in range(100)]
22
- table = wandb.Table(data=data, columns=["step", "height"])
23
- wandb.log({'scatter-plot1': wandb.plot.scatter(table, "step", "height")})
35
+ import math
36
+ import random
37
+ import wandb
38
+
39
+ # Simulate temperature variations at different altitudes over time
40
+ data = [
41
+ [i, random.uniform(-10, 20) - 0.005 * i + 5 * math.sin(i / 50)] for i in range(300)
42
+ ]
43
+
44
+ # Create W&B table with altitude (m) and temperature (°C) columns
45
+ table = wandb.Table(data=data, columns=["altitude (m)", "temperature (°C)"])
46
+
47
+ # Initialize W&B run and log the scatter plot
48
+ with wandb.init(project="temperature-altitude-scatter") as run:
49
+ # Create and log the scatter plot
50
+ scatter_plot = wandb.plot.scatter(
51
+ table=table,
52
+ x="altitude (m)",
53
+ y="temperature (°C)",
54
+ title="Altitude vs Temperature",
55
+ )
56
+ run.log({"altitude-temperature-scatter": scatter_plot})
24
57
  ```
25
58
  """
26
- return wandb.plot_table(
27
- "wandb/scatter/v0",
28
- table,
29
- {"x": x, "y": y},
30
- {"title": title},
59
+ return plot_table(
60
+ data_table=table,
61
+ vega_spec_name="wandb/scatter/v0",
62
+ fields={"x": x, "y": y},
63
+ string_fields={"title": title},
31
64
  split_table=split_table,
32
65
  )
wandb/plot/viz.py CHANGED
@@ -1,118 +1,36 @@
1
- from typing import Any, Dict, Optional, Tuple
1
+ from __future__ import annotations
2
+
3
+ from dataclasses import dataclass
4
+ from typing import Any
2
5
 
3
6
  from wandb.data_types import Table
4
7
  from wandb.errors import Error
5
8
 
6
9
 
7
- class Visualize:
8
- def __init__(self, id: str, data: Table) -> None:
9
- self._id = id
10
- self._data = data
11
-
12
- def get_config_value(self, key: str) -> Dict[str, Any]:
13
- return {
14
- "id": self._id,
15
- "historyFieldSettings": {"x-axis": "_step", "key": key},
16
- }
17
-
18
- @staticmethod
19
- def get_config_key(key: str) -> Tuple[str, str, str]:
20
- return "_wandb", "viz", key
10
+ @dataclass
11
+ class VisualizeSpec:
12
+ name: str
13
+ key: str = ""
21
14
 
22
15
  @property
23
- def value(self) -> Table:
24
- return self._data
25
-
26
-
27
- class CustomChart:
28
- def __init__(
29
- self,
30
- id: str,
31
- data: Table,
32
- fields: Dict[str, Any],
33
- string_fields: Dict[str, Any],
34
- split_table: Optional[bool] = False,
35
- ) -> None:
36
- self._id = id
37
- self._data = data
38
- self._fields = fields
39
- self._string_fields = string_fields
40
- self._split_table = split_table
41
-
42
- def get_config_value(
43
- self,
44
- panel_type: str,
45
- query: Dict[str, Any],
46
- ) -> Dict[str, Any]:
16
+ def config_value(self) -> dict[str, Any]:
47
17
  return {
48
- "panel_type": panel_type,
49
- "panel_config": {
50
- "panelDefId": self._id,
51
- "fieldSettings": self._fields,
52
- "stringSettings": self._string_fields,
53
- "transform": {"name": "tableWithLeafColNames"},
54
- "userQuery": query,
55
- },
56
- }
57
-
58
- @staticmethod
59
- def get_config_key(key: str) -> Tuple[str, str, str]:
60
- return "_wandb", "visualize", key
61
-
62
- @staticmethod
63
- def user_query(table_key: str) -> Dict[str, Any]:
64
- return {
65
- "queryFields": [
66
- {
67
- "name": "runSets",
68
- "args": [{"name": "runSets", "value": "${runSets}"}],
69
- "fields": [
70
- {"name": "id", "fields": []},
71
- {"name": "name", "fields": []},
72
- {"name": "_defaultColorIndex", "fields": []},
73
- {
74
- "name": "summaryTable",
75
- "args": [{"name": "tableKey", "value": table_key}],
76
- "fields": [],
77
- },
78
- ],
79
- }
80
- ],
18
+ "id": self.name,
19
+ "historyFieldSettings": {"x-axis": "_step", "key": self.key},
81
20
  }
82
21
 
83
22
  @property
84
- def table(self) -> Table:
85
- return self._data
23
+ def config_key(self) -> tuple[str, str, str]:
24
+ return ("_wandb", "viz", self.key)
86
25
 
87
- @property
88
- def fields(self) -> Dict[str, Any]:
89
- return self._fields
90
-
91
- @property
92
- def string_fields(self) -> Dict[str, Any]:
93
- return self._string_fields
94
26
 
27
+ @dataclass
28
+ class Visualize:
29
+ table: Table
30
+ spec: VisualizeSpec
95
31
 
96
- def custom_chart(
97
- vega_spec_name: str,
98
- data_table: Table,
99
- fields: Dict[str, Any],
100
- string_fields: Optional[Dict[str, Any]] = None,
101
- split_table: Optional[bool] = False,
102
- ) -> CustomChart:
103
- if string_fields is None:
104
- string_fields = {}
105
- if not isinstance(data_table, Table):
106
- raise Error(
107
- f"Expected `data_table` to be `wandb.Table` type, instead got {type(data_table).__name__}"
108
- )
109
- return CustomChart(
110
- id=vega_spec_name,
111
- data=data_table,
112
- fields=fields,
113
- string_fields=string_fields,
114
- split_table=split_table,
115
- )
32
+ def set_key(self, key: str) -> None:
33
+ self.spec.key = key
116
34
 
117
35
 
118
36
  def visualize(id: str, value: Table) -> Visualize:
@@ -120,4 +38,4 @@ def visualize(id: str, value: Table) -> Visualize:
120
38
  raise Error(
121
39
  f"Expected `value` to be `wandb.Table` type, instead got {type(value).__name__}"
122
40
  )
123
- return Visualize(id=id, data=value)
41
+ return Visualize(table=value, spec=VisualizeSpec(name=id))