wandb 0.17.7__py3-none-win_amd64.whl → 0.17.8rc1__py3-none-win_amd64.whl

Sign up to get free protection for your applications and to get access to all the features.
wandb/__init__.pyi ADDED
@@ -0,0 +1,964 @@
1
+ """Use wandb to track machine learning work.
2
+
3
+ Train and fine-tune models, manage models from experimentation to production.
4
+
5
+ For guides and examples, see https://docs.wandb.ai.
6
+
7
+ For scripts and interactive notebooks, see https://github.com/wandb/examples.
8
+
9
+ For reference documentation, see https://docs.wandb.com/ref/python.
10
+ """
11
+
12
+ __all__ = (
13
+ "__version__",
14
+ "init",
15
+ "setup",
16
+ "save",
17
+ "sweep",
18
+ "controller",
19
+ "agent",
20
+ "config",
21
+ "log",
22
+ "summary",
23
+ "Api",
24
+ "Graph",
25
+ "Image",
26
+ "Plotly",
27
+ "Video",
28
+ "Audio",
29
+ "Table",
30
+ "Html",
31
+ "box3d",
32
+ "Object3D",
33
+ "Molecule",
34
+ "Histogram",
35
+ "ArtifactTTL",
36
+ "log_model",
37
+ "use_model",
38
+ "link_model",
39
+ "define_metric",
40
+ "Error",
41
+ "termsetup",
42
+ "termlog",
43
+ "termerror",
44
+ "termwarn",
45
+ "Artifact",
46
+ "Settings",
47
+ "teardown",
48
+ )
49
+
50
+ import os
51
+ from typing import Any, Callable, Dict, List, Optional, Sequence, Union
52
+
53
+ from wandb.analytics import Sentry as _Sentry
54
+ from wandb.apis import InternalApi, PublicApi
55
+ from wandb.data_types import (
56
+ Audio,
57
+ Graph,
58
+ Histogram,
59
+ Html,
60
+ Image,
61
+ Molecule,
62
+ Object3D,
63
+ Plotly,
64
+ Table,
65
+ Video,
66
+ box3d,
67
+ )
68
+ from wandb.errors import Error
69
+ from wandb.errors.term import termerror, termlog, termsetup, termwarn
70
+ from wandb.sdk import Artifact, Settings, wandb_config, wandb_metric, wandb_summary
71
+ from wandb.sdk.artifacts.artifact_ttl import ArtifactTTL
72
+ from wandb.sdk.interface.interface import PolicyName
73
+ from wandb.sdk.lib.paths import FilePathStr, StrPath
74
+ from wandb.sdk.wandb_run import Run
75
+ from wandb.sdk.wandb_setup import _WandbSetup
76
+ from wandb.wandb_controller import _WandbController
77
+
78
+ __version__: str = "0.17.8rc1"
79
+
80
+ run: Optional[Run] = None
81
+ config = wandb_config.Config
82
+ summary = wandb_summary.Summary
83
+ Api = PublicApi
84
+ api = InternalApi()
85
+ _sentry = _Sentry()
86
+
87
+ # record of patched libraries
88
+ patched = {"tensorboard": [], "keras": [], "gym": []} # type: ignore
89
+
90
+ def setup(
91
+ settings: Optional[Settings] = None,
92
+ ) -> Optional[_WandbSetup]:
93
+ """Prepares W&B for use in the current process and its children.
94
+
95
+ You can usually ignore this as it is implicitly called by `wandb.init()`.
96
+
97
+ When using wandb in multiple processes, calling `wandb.setup()`
98
+ in the parent process before starting child processes may improve
99
+ performance and resource utilization.
100
+
101
+ Note that `wandb.setup()` modifies `os.environ`, and it is important
102
+ that child processes inherit the modified environment variables.
103
+
104
+ See also `wandb.teardown()`.
105
+
106
+ Args:
107
+ settings (Optional[Union[Dict[str, Any], wandb.Settings]]): Configuration settings
108
+ to apply globally. These can be overridden by subsequent `wandb.init()` calls.
109
+
110
+ Example:
111
+ ```python
112
+ import multiprocessing
113
+
114
+ import wandb
115
+
116
+
117
+ def run_experiment(params):
118
+ with wandb.init(config=params):
119
+ # Run experiment
120
+ pass
121
+
122
+
123
+ if __name__ == "__main__":
124
+ # Start backend and set global config
125
+ wandb.setup(settings={"project": "my_project"})
126
+
127
+ # Define experiment parameters
128
+ experiment_params = [
129
+ {"learning_rate": 0.01, "epochs": 10},
130
+ {"learning_rate": 0.001, "epochs": 20},
131
+ ]
132
+
133
+ # Start multiple processes, each running a separate experiment
134
+ processes = []
135
+ for params in experiment_params:
136
+ p = multiprocessing.Process(target=run_experiment, args=(params,))
137
+ p.start()
138
+ processes.append(p)
139
+
140
+ # Wait for all processes to complete
141
+ for p in processes:
142
+ p.join()
143
+
144
+ # Optional: Explicitly shut down the backend
145
+ wandb.teardown()
146
+ ```
147
+ """
148
+ ...
149
+
150
+ def teardown(exit_code: Optional[int] = None) -> None:
151
+ """Waits for wandb to finish and frees resources.
152
+
153
+ Completes any runs that were not explicitly finished
154
+ using `run.finish()` and waits for all data to be uploaded.
155
+
156
+ It is recommended to call this at the end of a session
157
+ that used `wandb.setup()`. It is invoked automatically
158
+ in an `atexit` hook, but this is not reliable in certain setups
159
+ such as when using Python's `multiprocessing` module.
160
+ """
161
+ ...
162
+
163
+ def init(
164
+ job_type: Optional[str] = None,
165
+ dir: Optional[StrPath] = None,
166
+ config: Union[Dict, str, None] = None,
167
+ project: Optional[str] = None,
168
+ entity: Optional[str] = None,
169
+ reinit: Optional[bool] = None,
170
+ tags: Optional[Sequence] = None,
171
+ group: Optional[str] = None,
172
+ name: Optional[str] = None,
173
+ notes: Optional[str] = None,
174
+ magic: Optional[Union[dict, str, bool]] = None,
175
+ config_exclude_keys: Optional[List[str]] = None,
176
+ config_include_keys: Optional[List[str]] = None,
177
+ anonymous: Optional[str] = None,
178
+ mode: Optional[str] = None,
179
+ allow_val_change: Optional[bool] = None,
180
+ resume: Optional[Union[bool, str]] = None,
181
+ force: Optional[bool] = None,
182
+ tensorboard: Optional[bool] = None, # alias for sync_tensorboard
183
+ sync_tensorboard: Optional[bool] = None,
184
+ monitor_gym: Optional[bool] = None,
185
+ save_code: Optional[bool] = None,
186
+ id: Optional[str] = None,
187
+ fork_from: Optional[str] = None,
188
+ resume_from: Optional[str] = None,
189
+ settings: Union[Settings, Dict[str, Any], None] = None,
190
+ ) -> Run:
191
+ r"""Start a new run to track and log to W&B.
192
+
193
+ In an ML training pipeline, you could add `wandb.init()`
194
+ to the beginning of your training script as well as your evaluation
195
+ script, and each piece would be tracked as a run in W&B.
196
+
197
+ `wandb.init()` spawns a new background process to log data to a run, and it
198
+ also syncs data to wandb.ai by default, so you can see live visualizations.
199
+
200
+ Call `wandb.init()` to start a run before logging data with `wandb.log()`:
201
+ <!--yeadoc-test:init-method-log-->
202
+ ```python
203
+ import wandb
204
+
205
+ wandb.init()
206
+ # ... calculate metrics, generate media
207
+ wandb.log({"accuracy": 0.9})
208
+ ```
209
+
210
+ `wandb.init()` returns a run object, and you can also access the run object
211
+ via `wandb.run`:
212
+ <!--yeadoc-test:init-and-assert-global-->
213
+ ```python
214
+ import wandb
215
+
216
+ run = wandb.init()
217
+
218
+ assert run is wandb.run
219
+ ```
220
+
221
+ At the end of your script, we will automatically call `wandb.finish` to
222
+ finalize and cleanup the run. However, if you call `wandb.init` from a
223
+ child process, you must explicitly call `wandb.finish` at the end of the
224
+ child process.
225
+
226
+ For more on using `wandb.init()`, including detailed examples, check out our
227
+ [guide and FAQs](https://docs.wandb.ai/guides/track/launch).
228
+
229
+ Arguments:
230
+ project: (str, optional) The name of the project where you're sending
231
+ the new run. If the project is not specified, we will try to infer
232
+ the project name from git root or the current program file. If we
233
+ can't infer the project name, we will default to `"uncategorized"`.
234
+ entity: (str, optional) An entity is a username or team name where
235
+ you're sending runs. This entity must exist before you can send runs
236
+ there, so make sure to create your account or team in the UI before
237
+ starting to log runs.
238
+ If you don't specify an entity, the run will be sent to your default
239
+ entity. Change your default entity
240
+ in [your settings](https://wandb.ai/settings) under "default location
241
+ to create new projects".
242
+ config: (dict, argparse, absl.flags, str, optional)
243
+ This sets `wandb.config`, a dictionary-like object for saving inputs
244
+ to your job, like hyperparameters for a model or settings for a data
245
+ preprocessing job. The config will show up in a table in the UI that
246
+ you can use to group, filter, and sort runs. Keys should not contain
247
+ `.` in their names, and values should be under 10 MB.
248
+ If dict, argparse or absl.flags: will load the key value pairs into
249
+ the `wandb.config` object.
250
+ If str: will look for a yaml file by that name, and load config from
251
+ that file into the `wandb.config` object.
252
+ save_code: (bool, optional) Turn this on to save the main script or
253
+ notebook to W&B. This is valuable for improving experiment
254
+ reproducibility and to diff code across experiments in the UI. By
255
+ default this is off, but you can flip the default behavior to on
256
+ in [your settings page](https://wandb.ai/settings).
257
+ group: (str, optional) Specify a group to organize individual runs into
258
+ a larger experiment. For example, you might be doing cross
259
+ validation, or you might have multiple jobs that train and evaluate
260
+ a model against different test sets. Group gives you a way to
261
+ organize runs together into a larger whole, and you can toggle this
262
+ on and off in the UI. For more details, see our
263
+ [guide to grouping runs](https://docs.wandb.com/guides/runs/grouping).
264
+ job_type: (str, optional) Specify the type of run, which is useful when
265
+ you're grouping runs together into larger experiments using group.
266
+ For example, you might have multiple jobs in a group, with job types
267
+ like train and eval. Setting this makes it easy to filter and group
268
+ similar runs together in the UI so you can compare apples to apples.
269
+ tags: (list, optional) A list of strings, which will populate the list
270
+ of tags on this run in the UI. Tags are useful for organizing runs
271
+ together, or applying temporary labels like "baseline" or
272
+ "production". It's easy to add and remove tags in the UI, or filter
273
+ down to just runs with a specific tag.
274
+ If you are resuming a run, its tags will be overwritten by the tags
275
+ you pass to `wandb.init()`. If you want to add tags to a resumed run
276
+ without overwriting its existing tags, use `run.tags += ["new_tag"]`
277
+ after `wandb.init()`.
278
+ name: (str, optional) A short display name for this run, which is how
279
+ you'll identify this run in the UI. By default, we generate a random
280
+ two-word name that lets you easily cross-reference runs from the
281
+ table to charts. Keeping these run names short makes the chart
282
+ legends and tables easier to read. If you're looking for a place to
283
+ save your hyperparameters, we recommend saving those in config.
284
+ notes: (str, optional) A longer description of the run, like a `-m` commit
285
+ message in git. This helps you remember what you were doing when you
286
+ ran this run.
287
+ dir: (str or pathlib.Path, optional) An absolute path to a directory where
288
+ metadata will be stored. When you call `download()` on an artifact,
289
+ this is the directory where downloaded files will be saved. By default,
290
+ this is the `./wandb` directory.
291
+ resume: (bool, str, optional) Sets the resuming behavior. Options:
292
+ `"allow"`, `"must"`, `"never"`, `"auto"` or `None`. Defaults to `None`.
293
+ Cases:
294
+ - `None` (default): If the new run has the same ID as a previous run,
295
+ this run overwrites that data.
296
+ - `"auto"` (or `True`): if the previous run on this machine crashed,
297
+ automatically resume it. Otherwise, start a new run.
298
+ - `"allow"`: if id is set with `init(id="UNIQUE_ID")` or
299
+ `WANDB_RUN_ID="UNIQUE_ID"` and it is identical to a previous run,
300
+ wandb will automatically resume the run with that id. Otherwise,
301
+ wandb will start a new run.
302
+ - `"never"`: if id is set with `init(id="UNIQUE_ID")` or
303
+ `WANDB_RUN_ID="UNIQUE_ID"` and it is identical to a previous run,
304
+ wandb will crash.
305
+ - `"must"`: if id is set with `init(id="UNIQUE_ID")` or
306
+ `WANDB_RUN_ID="UNIQUE_ID"` and it is identical to a previous run,
307
+ wandb will automatically resume the run with the id. Otherwise,
308
+ wandb will crash.
309
+ See [our guide to resuming runs](https://docs.wandb.com/guides/runs/resuming)
310
+ for more.
311
+ reinit: (bool, optional) Allow multiple `wandb.init()` calls in the same
312
+ process. (default: `False`)
313
+ magic: (bool, dict, or str, optional) The bool controls whether we try to
314
+ auto-instrument your script, capturing basic details of your run
315
+ without you having to add more wandb code. (default: `False`)
316
+ You can also pass a dict, json string, or yaml filename.
317
+ config_exclude_keys: (list, optional) string keys to exclude from
318
+ `wandb.config`.
319
+ config_include_keys: (list, optional) string keys to include in
320
+ `wandb.config`.
321
+ anonymous: (str, optional) Controls anonymous data logging. Options:
322
+ - `"never"` (default): requires you to link your W&B account before
323
+ tracking the run, so you don't accidentally create an anonymous
324
+ run.
325
+ - `"allow"`: lets a logged-in user track runs with their account, but
326
+ lets someone who is running the script without a W&B account see
327
+ the charts in the UI.
328
+ - `"must"`: sends the run to an anonymous account instead of to a
329
+ signed-up user account.
330
+ mode: (str, optional) Can be `"online"`, `"offline"` or `"disabled"`. Defaults to
331
+ online.
332
+ allow_val_change: (bool, optional) Whether to allow config values to
333
+ change after setting the keys once. By default, we throw an exception
334
+ if a config value is overwritten. If you want to track something
335
+ like a varying learning rate at multiple times during training, use
336
+ `wandb.log()` instead. (default: `False` in scripts, `True` in Jupyter)
337
+ force: (bool, optional) If `True`, this crashes the script if a user isn't
338
+ logged in to W&B. If `False`, this will let the script run in offline
339
+ mode if a user isn't logged in to W&B. (default: `False`)
340
+ sync_tensorboard: (bool, optional) Synchronize wandb logs from tensorboard or
341
+ tensorboardX and save the relevant events file. (default: `False`)
342
+ monitor_gym: (bool, optional) Automatically log videos of environment when
343
+ using OpenAI Gym. (default: `False`)
344
+ See [our guide to this integration](https://docs.wandb.com/guides/integrations/openai-gym).
345
+ id: (str, optional) A unique ID for this run, used for resuming. It must
346
+ be unique in the project, and if you delete a run you can't reuse
347
+ the ID. Use the `name` field for a short descriptive name, or `config`
348
+ for saving hyperparameters to compare across runs. The ID cannot
349
+ contain the following special characters: `/\#?%:`.
350
+ See [our guide to resuming runs](https://docs.wandb.com/guides/runs/resuming).
351
+ fork_from: (str, optional) A string with the format {run_id}?_step={step} describing
352
+ a moment in a previous run to fork a new run from. Creates a new run that picks up
353
+ logging history from the specified run at the specified moment. The target run must
354
+ be in the current project. Example: `fork_from="my-run-id?_step=1234"`.
355
+
356
+ Examples:
357
+ ### Set where the run is logged
358
+
359
+ You can change where the run is logged, just like changing
360
+ the organization, repository, and branch in git:
361
+ ```python
362
+ import wandb
363
+
364
+ user = "geoff"
365
+ project = "capsules"
366
+ display_name = "experiment-2021-10-31"
367
+
368
+ wandb.init(entity=user, project=project, name=display_name)
369
+ ```
370
+
371
+ ### Add metadata about the run to the config
372
+
373
+ Pass a dictionary-style object as the `config` keyword argument to add
374
+ metadata, like hyperparameters, to your run.
375
+ <!--yeadoc-test:init-set-config-->
376
+ ```python
377
+ import wandb
378
+
379
+ config = {"lr": 3e-4, "batch_size": 32}
380
+ config.update({"architecture": "resnet", "depth": 34})
381
+ wandb.init(config=config)
382
+ ```
383
+
384
+ Raises:
385
+ Error: if some unknown or internal error happened during the run initialization.
386
+ AuthenticationError: if the user failed to provide valid credentials.
387
+ CommError: if there was a problem communicating with the WandB server.
388
+ UsageError: if the user provided invalid arguments.
389
+ KeyboardInterrupt: if user interrupts the run.
390
+
391
+ Returns:
392
+ A `Run` object.
393
+ """
394
+ ...
395
+
396
+ def log(
397
+ data: Dict[str, Any],
398
+ step: Optional[int] = None,
399
+ commit: Optional[bool] = None,
400
+ sync: Optional[bool] = None,
401
+ ) -> None:
402
+ """Upload run data.
403
+
404
+ Use `log` to log data from runs, such as scalars, images, video,
405
+ histograms, plots, and tables.
406
+
407
+ See our [guides to logging](https://docs.wandb.ai/guides/track/log) for
408
+ live examples, code snippets, best practices, and more.
409
+
410
+ The most basic usage is `run.log({"train-loss": 0.5, "accuracy": 0.9})`.
411
+ This will save the loss and accuracy to the run's history and update
412
+ the summary values for these metrics.
413
+
414
+ Visualize logged data in the workspace at [wandb.ai](https://wandb.ai),
415
+ or locally on a [self-hosted instance](https://docs.wandb.ai/guides/hosting)
416
+ of the W&B app, or export data to visualize and explore locally, e.g. in
417
+ Jupyter notebooks, with [our API](https://docs.wandb.ai/guides/track/public-api-guide).
418
+
419
+ Logged values don't have to be scalars. Logging any wandb object is supported.
420
+ For example `run.log({"example": wandb.Image("myimage.jpg")})` will log an
421
+ example image which will be displayed nicely in the W&B UI.
422
+ See the [reference documentation](https://docs.wandb.com/ref/python/data-types)
423
+ for all of the different supported types or check out our
424
+ [guides to logging](https://docs.wandb.ai/guides/track/log) for examples,
425
+ from 3D molecular structures and segmentation masks to PR curves and histograms.
426
+ You can use `wandb.Table` to log structured data. See our
427
+ [guide to logging tables](https://docs.wandb.ai/guides/data-vis/log-tables)
428
+ for details.
429
+
430
+ The W&B UI organizes metrics with a forward slash (`/`) in their name
431
+ into sections named using the text before the final slash. For example,
432
+ the following results in two sections named "train" and "validate":
433
+
434
+ ```
435
+ run.log({
436
+ "train/accuracy": 0.9,
437
+ "train/loss": 30,
438
+ "validate/accuracy": 0.8,
439
+ "validate/loss": 20,
440
+ })
441
+ ```
442
+
443
+ Only one level of nesting is supported; `run.log({"a/b/c": 1})`
444
+ produces a section named "a/b".
445
+
446
+ `run.log` is not intended to be called more than a few times per second.
447
+ For optimal performance, limit your logging to once every N iterations,
448
+ or collect data over multiple iterations and log it in a single step.
449
+
450
+ ### The W&B step
451
+
452
+ With basic usage, each call to `log` creates a new "step".
453
+ The step must always increase, and it is not possible to log
454
+ to a previous step.
455
+
456
+ Note that you can use any metric as the X axis in charts.
457
+ In many cases, it is better to treat the W&B step like
458
+ you'd treat a timestamp rather than a training step.
459
+
460
+ ```
461
+ # Example: log an "epoch" metric for use as an X axis.
462
+ run.log({"epoch": 40, "train-loss": 0.5})
463
+ ```
464
+
465
+ See also [define_metric](https://docs.wandb.ai/ref/python/run#define_metric).
466
+
467
+ It is possible to use multiple `log` invocations to log to
468
+ the same step with the `step` and `commit` parameters.
469
+ The following are all equivalent:
470
+
471
+ ```
472
+ # Normal usage:
473
+ run.log({"train-loss": 0.5, "accuracy": 0.8})
474
+ run.log({"train-loss": 0.4, "accuracy": 0.9})
475
+
476
+ # Implicit step without auto-incrementing:
477
+ run.log({"train-loss": 0.5}, commit=False)
478
+ run.log({"accuracy": 0.8})
479
+ run.log({"train-loss": 0.4}, commit=False)
480
+ run.log({"accuracy": 0.9})
481
+
482
+ # Explicit step:
483
+ run.log({"train-loss": 0.5}, step=current_step)
484
+ run.log({"accuracy": 0.8}, step=current_step)
485
+ current_step += 1
486
+ run.log({"train-loss": 0.4}, step=current_step)
487
+ run.log({"accuracy": 0.9}, step=current_step)
488
+ ```
489
+
490
+ Arguments:
491
+ data: A `dict` with `str` keys and values that are serializable
492
+ Python objects including: `int`, `float` and `string`;
493
+ any of the `wandb.data_types`; lists, tuples and NumPy arrays
494
+ of serializable Python objects; other `dict`s of this
495
+ structure.
496
+ step: The step number to log. If `None`, then an implicit
497
+ auto-incrementing step is used. See the notes in
498
+ the description.
499
+ commit: If true, finalize and upload the step. If false, then
500
+ accumulate data for the step. See the notes in the description.
501
+ If `step` is `None`, then the default is `commit=True`;
502
+ otherwise, the default is `commit=False`.
503
+ sync: This argument is deprecated and does nothing.
504
+
505
+ Examples:
506
+ For more and more detailed examples, see
507
+ [our guides to logging](https://docs.wandb.com/guides/track/log).
508
+
509
+ ### Basic usage
510
+ <!--yeadoc-test:init-and-log-basic-->
511
+ ```python
512
+ import wandb
513
+
514
+ run = wandb.init()
515
+ run.log({"accuracy": 0.9, "epoch": 5})
516
+ ```
517
+
518
+ ### Incremental logging
519
+ <!--yeadoc-test:init-and-log-incremental-->
520
+ ```python
521
+ import wandb
522
+
523
+ run = wandb.init()
524
+ run.log({"loss": 0.2}, commit=False)
525
+ # Somewhere else when I'm ready to report this step:
526
+ run.log({"accuracy": 0.8})
527
+ ```
528
+
529
+ ### Histogram
530
+ <!--yeadoc-test:init-and-log-histogram-->
531
+ ```python
532
+ import numpy as np
533
+ import wandb
534
+
535
+ # sample gradients at random from normal distribution
536
+ gradients = np.random.randn(100, 100)
537
+ run = wandb.init()
538
+ run.log({"gradients": wandb.Histogram(gradients)})
539
+ ```
540
+
541
+ ### Image from numpy
542
+ <!--yeadoc-test:init-and-log-image-numpy-->
543
+ ```python
544
+ import numpy as np
545
+ import wandb
546
+
547
+ run = wandb.init()
548
+ examples = []
549
+ for i in range(3):
550
+ pixels = np.random.randint(low=0, high=256, size=(100, 100, 3))
551
+ image = wandb.Image(pixels, caption=f"random field {i}")
552
+ examples.append(image)
553
+ run.log({"examples": examples})
554
+ ```
555
+
556
+ ### Image from PIL
557
+ <!--yeadoc-test:init-and-log-image-pillow-->
558
+ ```python
559
+ import numpy as np
560
+ from PIL import Image as PILImage
561
+ import wandb
562
+
563
+ run = wandb.init()
564
+ examples = []
565
+ for i in range(3):
566
+ pixels = np.random.randint(low=0, high=256, size=(100, 100, 3), dtype=np.uint8)
567
+ pil_image = PILImage.fromarray(pixels, mode="RGB")
568
+ image = wandb.Image(pil_image, caption=f"random field {i}")
569
+ examples.append(image)
570
+ run.log({"examples": examples})
571
+ ```
572
+
573
+ ### Video from numpy
574
+ <!--yeadoc-test:init-and-log-video-numpy-->
575
+ ```python
576
+ import numpy as np
577
+ import wandb
578
+
579
+ run = wandb.init()
580
+ # axes are (time, channel, height, width)
581
+ frames = np.random.randint(low=0, high=256, size=(10, 3, 100, 100), dtype=np.uint8)
582
+ run.log({"video": wandb.Video(frames, fps=4)})
583
+ ```
584
+
585
+ ### Matplotlib Plot
586
+ <!--yeadoc-test:init-and-log-matplotlib-->
587
+ ```python
588
+ from matplotlib import pyplot as plt
589
+ import numpy as np
590
+ import wandb
591
+
592
+ run = wandb.init()
593
+ fig, ax = plt.subplots()
594
+ x = np.linspace(0, 10)
595
+ y = x * x
596
+ ax.plot(x, y) # plot y = x^2
597
+ run.log({"chart": fig})
598
+ ```
599
+
600
+ ### PR Curve
601
+ ```python
602
+ import wandb
603
+
604
+ run = wandb.init()
605
+ run.log({"pr": wandb.plot.pr_curve(y_test, y_probas, labels)})
606
+ ```
607
+
608
+ ### 3D Object
609
+ ```python
610
+ import wandb
611
+
612
+ run = wandb.init()
613
+ run.log(
614
+ {
615
+ "generated_samples": [
616
+ wandb.Object3D(open("sample.obj")),
617
+ wandb.Object3D(open("sample.gltf")),
618
+ wandb.Object3D(open("sample.glb")),
619
+ ]
620
+ }
621
+ )
622
+ ```
623
+
624
+ Raises:
625
+ wandb.Error: if called before `wandb.init`
626
+ ValueError: if invalid data is passed
627
+ """
628
+ ...
629
+
630
+ def save(
631
+ glob_str: Optional[Union[str, os.PathLike]] = None,
632
+ base_path: Optional[Union[str, os.PathLike]] = None,
633
+ policy: PolicyName = "live",
634
+ ) -> Union[bool, List[str]]:
635
+ """Sync one or more files to W&B.
636
+
637
+ Relative paths are relative to the current working directory.
638
+
639
+ A Unix glob, such as "myfiles/*", is expanded at the time `save` is
640
+ called regardless of the `policy`. In particular, new files are not
641
+ picked up automatically.
642
+
643
+ A `base_path` may be provided to control the directory structure of
644
+ uploaded files. It should be a prefix of `glob_str`, and the directory
645
+ structure beneath it is preserved. It's best understood through
646
+ examples:
647
+
648
+ ```
649
+ wandb.save("these/are/myfiles/*")
650
+ # => Saves files in a "these/are/myfiles/" folder in the run.
651
+
652
+ wandb.save("these/are/myfiles/*", base_path="these")
653
+ # => Saves files in an "are/myfiles/" folder in the run.
654
+
655
+ wandb.save("/User/username/Documents/run123/*.txt")
656
+ # => Saves files in a "run123/" folder in the run. See note below.
657
+
658
+ wandb.save("/User/username/Documents/run123/*.txt", base_path="/User")
659
+ # => Saves files in a "username/Documents/run123/" folder in the run.
660
+
661
+ wandb.save("files/*/saveme.txt")
662
+ # => Saves each "saveme.txt" file in an appropriate subdirectory
663
+ # of "files/".
664
+ ```
665
+
666
+ Note: when given an absolute path or glob and no `base_path`, one
667
+ directory level is preserved as in the example above.
668
+
669
+ Arguments:
670
+ glob_str: A relative or absolute path or Unix glob.
671
+ base_path: A path to use to infer a directory structure; see examples.
672
+ policy: One of `live`, `now`, or `end`.
673
+ * live: upload the file as it changes, overwriting the previous version
674
+ * now: upload the file once now
675
+ * end: upload file when the run ends
676
+
677
+ Returns:
678
+ Paths to the symlinks created for the matched files.
679
+
680
+ For historical reasons, this may return a boolean in legacy code.
681
+ """
682
+ ...
683
+
684
+ def sweep(
685
+ sweep: Union[dict, Callable],
686
+ entity: Optional[str] = None,
687
+ project: Optional[str] = None,
688
+ prior_runs: Optional[List[str]] = None,
689
+ ) -> str:
690
+ """Initialize a hyperparameter sweep.
691
+
692
+ Search for hyperparameters that optimizes a cost function
693
+ of a machine learning model by testing various combinations.
694
+
695
+ Make note the unique identifier, `sweep_id`, that is returned.
696
+ At a later step provide the `sweep_id` to a sweep agent.
697
+
698
+ Args:
699
+ sweep: The configuration of a hyperparameter search.
700
+ (or configuration generator). See
701
+ [Sweep configuration structure](https://docs.wandb.ai/guides/sweeps/define-sweep-configuration)
702
+ for information on how to define your sweep.
703
+ If you provide a callable, ensure that the callable does
704
+ not take arguments and that it returns a dictionary that
705
+ conforms to the W&B sweep config spec.
706
+ entity: The username or team name where you want to send W&B
707
+ runs created by the sweep to. Ensure that the entity you
708
+ specify already exists. If you don't specify an entity,
709
+ the run will be sent to your default entity,
710
+ which is usually your username.
711
+ project: The name of the project where W&B runs created from
712
+ the sweep are sent to. If the project is not specified, the
713
+ run is sent to a project labeled 'Uncategorized'.
714
+ prior_runs: The run IDs of existing runs to add to this sweep.
715
+
716
+ Returns:
717
+ sweep_id: str. A unique identifier for the sweep.
718
+ """
719
+ ...
720
+
721
+ def controller(
722
+ sweep_id_or_config: Optional[Union[str, Dict]] = None,
723
+ entity: Optional[str] = None,
724
+ project: Optional[str] = None,
725
+ ) -> _WandbController:
726
+ """Public sweep controller constructor.
727
+
728
+ Usage:
729
+ ```python
730
+ import wandb
731
+
732
+ tuner = wandb.controller(...)
733
+ print(tuner.sweep_config)
734
+ print(tuner.sweep_id)
735
+ tuner.configure_search(...)
736
+ tuner.configure_stopping(...)
737
+ ```
738
+ """
739
+ ...
740
+
741
+ def agent(
742
+ sweep_id: str,
743
+ function: Optional[Callable] = None,
744
+ entity: Optional[str] = None,
745
+ project: Optional[str] = None,
746
+ count: Optional[int] = None,
747
+ ) -> None:
748
+ """Start one or more sweep agents.
749
+
750
+ The sweep agent uses the `sweep_id` to know which sweep it
751
+ is a part of, what function to execute, and (optionally) how
752
+ many agents to run.
753
+
754
+ Arguments:
755
+ sweep_id: The unique identifier for a sweep. A sweep ID
756
+ is generated by W&B CLI or Python SDK.
757
+ function: A function to call instead of the "program"
758
+ specified in the sweep config.
759
+ entity: The username or team name where you want to send W&B
760
+ runs created by the sweep to. Ensure that the entity you
761
+ specify already exists. If you don't specify an entity,
762
+ the run will be sent to your default entity,
763
+ which is usually your username.
764
+ project: The name of the project where W&B runs created from
765
+ the sweep are sent to. If the project is not specified, the
766
+ run is sent to a project labeled "Uncategorized".
767
+ count: The number of sweep config trials to try.
768
+ """
769
+ ...
770
+
771
+ def define_metric(
772
+ name: str,
773
+ step_metric: Union[str, wandb_metric.Metric, None] = None,
774
+ step_sync: Optional[bool] = None,
775
+ hidden: Optional[bool] = None,
776
+ summary: Optional[str] = None,
777
+ goal: Optional[str] = None,
778
+ overwrite: Optional[bool] = None,
779
+ ) -> wandb_metric.Metric:
780
+ """Customize metrics logged with `wandb.log()`.
781
+
782
+ Arguments:
783
+ name: The name of the metric to customize.
784
+ step_metric: The name of another metric to serve as the X-axis
785
+ for this metric in automatically generated charts.
786
+ step_sync: Automatically insert the last value of step_metric into
787
+ `run.log()` if it is not provided explicitly. Defaults to True
788
+ if step_metric is specified.
789
+ hidden: Hide this metric from automatic plots.
790
+ summary: Specify aggregate metrics added to summary.
791
+ Supported aggregations include "min", "max", "mean", "last",
792
+ "best", "copy" and "none". "best" is used together with the
793
+ goal parameter. "none" prevents a summary from being generated.
794
+ "copy" is deprecated and should not be used.
795
+ goal: Specify how to interpret the "best" summary type.
796
+ Supported options are "minimize" and "maximize".
797
+ overwrite: If false, then this call is merged with previous
798
+ `define_metric` calls for the same metric by using their
799
+ values for any unspecified parameters. If true, then
800
+ unspecified parameters overwrite values specified by
801
+ previous calls.
802
+
803
+ Returns:
804
+ An object that represents this call but can otherwise be discarded.
805
+ """
806
+ ...
807
+
808
+ def log_model(
809
+ path: StrPath,
810
+ name: Optional[str] = None,
811
+ aliases: Optional[List[str]] = None,
812
+ ) -> None:
813
+ """Logs a model artifact containing the contents inside the 'path' to a run and marks it as an output to this run.
814
+
815
+ Arguments:
816
+ path: (str) A path to the contents of this model,
817
+ can be in the following forms:
818
+ - `/local/directory`
819
+ - `/local/directory/file.txt`
820
+ - `s3://bucket/path`
821
+ name: (str, optional) A name to assign to the model artifact that the file contents will be added to.
822
+ The string must contain only the following alphanumeric characters: dashes, underscores, and dots.
823
+ This will default to the basename of the path prepended with the current
824
+ run id if not specified.
825
+ aliases: (list, optional) Aliases to apply to the created model artifact,
826
+ defaults to `["latest"]`
827
+
828
+ Examples:
829
+ ```python
830
+ run.log_model(
831
+ path="/local/directory",
832
+ name="my_model_artifact",
833
+ aliases=["production"],
834
+ )
835
+ ```
836
+
837
+ Invalid usage
838
+ ```python
839
+ run.log_model(
840
+ path="/local/directory",
841
+ name="my_entity/my_project/my_model_artifact",
842
+ aliases=["production"],
843
+ )
844
+ ```
845
+
846
+ Raises:
847
+ ValueError: if name has invalid special characters
848
+
849
+ Returns:
850
+ None
851
+ """
852
+ ...
853
+
854
+ def use_model(name: str) -> FilePathStr:
855
+ """Download the files logged in a model artifact 'name'.
856
+
857
+ Arguments:
858
+ name: (str) A model artifact name. 'name' must match the name of an existing logged
859
+ model artifact.
860
+ May be prefixed with entity/project/. Valid names
861
+ can be in the following forms:
862
+ - model_artifact_name:version
863
+ - model_artifact_name:alias
864
+
865
+ Examples:
866
+ ```python
867
+ run.use_model(
868
+ name="my_model_artifact:latest",
869
+ )
870
+
871
+ run.use_model(
872
+ name="my_project/my_model_artifact:v0",
873
+ )
874
+
875
+ run.use_model(
876
+ name="my_entity/my_project/my_model_artifact:<digest>",
877
+ )
878
+ ```
879
+
880
+ Invalid usage
881
+ ```python
882
+ run.use_model(
883
+ name="my_entity/my_project/my_model_artifact",
884
+ )
885
+ ```
886
+
887
+ Raises:
888
+ AssertionError: if model artifact 'name' is of a type that does not contain the substring 'model'.
889
+
890
+ Returns:
891
+ path: (str) path to downloaded model artifact file(s).
892
+ """
893
+ ...
894
+
895
+ def link_model(
896
+ path: StrPath,
897
+ registered_model_name: str,
898
+ name: Optional[str] = None,
899
+ aliases: Optional[List[str]] = None,
900
+ ) -> None:
901
+ """Log a model artifact version and link it to a registered model in the model registry.
902
+
903
+ The linked model version will be visible in the UI for the specified registered model.
904
+
905
+ Steps:
906
+ - Check if 'name' model artifact has been logged. If so, use the artifact version that matches the files
907
+ located at 'path' or log a new version. Otherwise log files under 'path' as a new model artifact, 'name'
908
+ of type 'model'.
909
+ - Check if registered model with name 'registered_model_name' exists in the 'model-registry' project.
910
+ If not, create a new registered model with name 'registered_model_name'.
911
+ - Link version of model artifact 'name' to registered model, 'registered_model_name'.
912
+ - Attach aliases from 'aliases' list to the newly linked model artifact version.
913
+
914
+ Arguments:
915
+ path: (str) A path to the contents of this model,
916
+ can be in the following forms:
917
+ - `/local/directory`
918
+ - `/local/directory/file.txt`
919
+ - `s3://bucket/path`
920
+ registered_model_name: (str) - the name of the registered model that the model is to be linked to.
921
+ A registered model is a collection of model versions linked to the model registry, typically representing a
922
+ team's specific ML Task. The entity that this registered model belongs to will be derived from the run
923
+ name: (str, optional) - the name of the model artifact that files in 'path' will be logged to. This will
924
+ default to the basename of the path prepended with the current run id if not specified.
925
+ aliases: (List[str], optional) - alias(es) that will only be applied on this linked artifact
926
+ inside the registered model.
927
+ The alias "latest" will always be applied to the latest version of an artifact that is linked.
928
+
929
+ Examples:
930
+ ```python
931
+ run.link_model(
932
+ path="/local/directory",
933
+ registered_model_name="my_reg_model",
934
+ name="my_model_artifact",
935
+ aliases=["production"],
936
+ )
937
+ ```
938
+
939
+ Invalid usage
940
+ ```python
941
+ run.link_model(
942
+ path="/local/directory",
943
+ registered_model_name="my_entity/my_project/my_reg_model",
944
+ name="my_model_artifact",
945
+ aliases=["production"],
946
+ )
947
+
948
+ run.link_model(
949
+ path="/local/directory",
950
+ registered_model_name="my_reg_model",
951
+ name="my_entity/my_project/my_model_artifact",
952
+ aliases=["production"],
953
+ )
954
+ ```
955
+
956
+ Raises:
957
+ AssertionError: if registered_model_name is a path or
958
+ if model artifact 'name' is of a type that does not contain the substring 'model'
959
+ ValueError: if name has invalid special characters
960
+
961
+ Returns:
962
+ None
963
+ """
964
+ ...