Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions models/ref/sdk-coding-cheat-sheet.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Select a card to view code examples in that category.
<Card title="Runs" href="/models/ref/sdk-coding-cheat-sheet/runs">
Code examples to initialize, manage, and fork W&B runs
</Card>
<Card title="Sweeps" href="/models/ref/sdk-coding-cheat-sheet/sweeps">
Code examples to configure, create, and run hyperparameter sweeps with W&B
</Card>
<Card title="Logging" href="/models/ref/sdk-coding-cheat-sheet/logging">
Code examples to log metrics, hyperparameters, tables, and custom data to W&B
</Card>
Expand Down
30 changes: 30 additions & 0 deletions models/ref/sdk-coding-cheat-sheet/logging.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,60 @@ title: Logging
description: Log metrics, hyperparameters, tables, and custom data to W&B.
---

import LogCsvFiles from '/snippets/en/_includes/code-examples/log_csv_files.mdx';
import LogCustomSummaryMetric from '/snippets/en/_includes/code-examples/log_custom_summary_metric.mdx';
import LogCustomSummatyMetric from '/snippets/en/_includes/code-examples/log_custom_summaty_metric.mdx';
import LogExistingArtifactLinkCollection from '/snippets/en/_includes/code-examples/log_existing_artifact_link_collection.mdx';
import LogHistogramPlot from '/snippets/en/_includes/code-examples/log_histogram_plot.mdx';
import LogHyperparameter from '/snippets/en/_includes/code-examples/log_hyperparameter.mdx';
import LogLinePlot from '/snippets/en/_includes/code-examples/log_line_plot.mdx';
import LogMetric from '/snippets/en/_includes/code-examples/log_metric.mdx';
import LogScatterPlot from '/snippets/en/_includes/code-examples/log_scatter_plot.mdx';
import LogSummaryMetric from '/snippets/en/_includes/code-examples/log_summary_metric.mdx';
import LogTable from '/snippets/en/_includes/code-examples/log_table.mdx';

Log metrics, hyperparameters, tables, and custom data to W&B.

## Log a CSV file to as a table

<LogCsvFiles />

## Log a custom summary metric

<LogCustomSummaryMetric />

## Log a custom summary metric

<LogCustomSummatyMetric />

## Download and log an existing artifact from a registry collection

<LogExistingArtifactLinkCollection />

## Log a histogram plot

<LogHistogramPlot />

## Initialize a run and log hyperparameters

<LogHyperparameter />

## Log a line plot

<LogLinePlot />

## Initialize a run and log a metric

<LogMetric />

## Log a scatter plot

<LogScatterPlot />

## Explicitly log a summary metric

<LogSummaryMetric />

## Log a table

<LogTable />
Expand Down
35 changes: 35 additions & 0 deletions models/ref/sdk-coding-cheat-sheet/runs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ description: Initialize and manage W&B runs to organize your experiments and tra
import ExperimentsCreate from '/snippets/en/_includes/code-examples/experiments_create.mdx';
import RunFork from '/snippets/en/_includes/code-examples/run_fork.mdx';
import RunInit from '/snippets/en/_includes/code-examples/run_init.mdx';
import RunResume from '/snippets/en/_includes/code-examples/run_resume.mdx';
import RunRewind from '/snippets/en/_includes/code-examples/run_rewind.mdx';
Comment on lines +9 to +10
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

import RunsAddTags from '/snippets/en/_includes/code-examples/runs_add_tags.mdx';
import RunsGroup from '/snippets/en/_includes/code-examples/runs_group.mdx';
import RunsOrganizeByType from '/snippets/en/_includes/code-examples/runs_organize_by_type.mdx';
import RunsUpdateTag from '/snippets/en/_includes/code-examples/runs_update_tag.mdx';
import RunsUpdateTagPublicApi from '/snippets/en/_includes/code-examples/runs_update_tag_public_api.mdx';

Initialize and manage W&B runs to organize your experiments and track your work.

Expand All @@ -21,3 +28,31 @@ Initialize and manage W&B runs to organize your experiments and track your work.

<RunInit />

## Set resume behaviour for a run if it is paused, stops, or fails

<RunResume />

## Rewind a run to modify the history of a run

<RunRewind />

## Add one or more tags to a run

<RunsAddTags />

## Add one or more runs to a group

<RunsGroup />

## Organize runs by their job type

<RunsOrganizeByType />

## Add one or more tags to an active run

<RunsUpdateTag />

## Add one or more tags to previously saved runs

<RunsUpdateTagPublicApi />

28 changes: 28 additions & 0 deletions models/ref/sdk-coding-cheat-sheet/sweeps.mdx
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
title: Sweeps
description: Configure sweep definitions, create sweeps, and launch sweep agents with the W&B Python SDK.
---

import SweepConfig from '/snippets/en/_includes/code-examples/sweep_config.mdx';
import SweepCreate from '/snippets/en/_includes/code-examples/sweep_create.mdx';
import SweepInitialize from '/snippets/en/_includes/code-examples/sweep_initialize.mdx';
import SweepStart from '/snippets/en/_includes/code-examples/sweep_start.mdx';

Configure sweep definitions, create sweeps, and launch sweep agents with the W&B Python SDK.

## Example sweep configuration for Sweeps

<SweepConfig />

## Define a sweep config, initialize, and start Sweep

<SweepCreate />

## Initialize a Sweep

<SweepInitialize />

## Start a sweep job to run a sweep agent

<SweepStart />

35 changes: 35 additions & 0 deletions snippets/CodeSnippet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* AUTO-GENERATED: Do not edit manually. Run sync_code_examples.sh to regenerate.
*/


// Import all MDX-wrapped code examples
import ArtifactAddAlias from '/snippets/en/_includes/code-examples/artifact_add_alias.mdx';
import ArtifactAddAliasExisting from '/snippets/en/_includes/code-examples/artifact_add_alias_existing.mdx';
Expand All @@ -28,10 +29,16 @@ import ArtifactUpdate from '/snippets/en/_includes/code-examples/artifact_update
import ArtifactUpdateExisting from '/snippets/en/_includes/code-examples/artifact_update_existing.mdx';
import ArtifactsDownload from '/snippets/en/_includes/code-examples/artifacts_download.mdx';
import ExperimentsCreate from '/snippets/en/_includes/code-examples/experiments_create.mdx';
import LogCsvFiles from '/snippets/en/_includes/code-examples/log_csv_files.mdx';
import LogCustomSummaryMetric from '/snippets/en/_includes/code-examples/log_custom_summary_metric.mdx';
import LogCustomSummatyMetric from '/snippets/en/_includes/code-examples/log_custom_summaty_metric.mdx';
import LogExistingArtifactLinkCollection from '/snippets/en/_includes/code-examples/log_existing_artifact_link_collection.mdx';
import LogHistogramPlot from '/snippets/en/_includes/code-examples/log_histogram_plot.mdx';
import LogHyperparameter from '/snippets/en/_includes/code-examples/log_hyperparameter.mdx';
import LogLinePlot from '/snippets/en/_includes/code-examples/log_line_plot.mdx';
import LogMetric from '/snippets/en/_includes/code-examples/log_metric.mdx';
import LogScatterPlot from '/snippets/en/_includes/code-examples/log_scatter_plot.mdx';
import LogSummaryMetric from '/snippets/en/_includes/code-examples/log_summary_metric.mdx';
import LogTable from '/snippets/en/_includes/code-examples/log_table.mdx';
import RegistryAddAnnotation from '/snippets/en/_includes/code-examples/registry_add_annotation.mdx';
import RegistryCollectionCreate from '/snippets/en/_includes/code-examples/registry_collection_create.mdx';
Expand All @@ -43,6 +50,17 @@ import RegistryLinkArtifactExisting from '/snippets/en/_includes/code-examples/r
import RegistryUseLinkedArtifact from '/snippets/en/_includes/code-examples/registry_use_linked_artifact.mdx';
import RunFork from '/snippets/en/_includes/code-examples/run_fork.mdx';
import RunInit from '/snippets/en/_includes/code-examples/run_init.mdx';
import RunResume from '/snippets/en/_includes/code-examples/run_resume.mdx';
import RunRewind from '/snippets/en/_includes/code-examples/run_rewind.mdx';
import RunsAddTags from '/snippets/en/_includes/code-examples/runs_add_tags.mdx';
import RunsGroup from '/snippets/en/_includes/code-examples/runs_group.mdx';
import RunsOrganizeByType from '/snippets/en/_includes/code-examples/runs_organize_by_type.mdx';
import RunsUpdateTag from '/snippets/en/_includes/code-examples/runs_update_tag.mdx';
import RunsUpdateTagPublicApi from '/snippets/en/_includes/code-examples/runs_update_tag_public_api.mdx';
import SweepConfig from '/snippets/en/_includes/code-examples/sweep_config.mdx';
import SweepCreate from '/snippets/en/_includes/code-examples/sweep_create.mdx';
import SweepInitialize from '/snippets/en/_includes/code-examples/sweep_initialize.mdx';
import SweepStart from '/snippets/en/_includes/code-examples/sweep_start.mdx';

// Map filenames to imported content
const snippets = {
Expand All @@ -61,10 +79,16 @@ const snippets = {
'artifact_update_existing.py': ArtifactUpdateExisting,
'artifacts_download.py': ArtifactsDownload,
'experiments_create.py': ExperimentsCreate,
'log_csv_files.py': LogCsvFiles,
'log_custom_summary_metric.py': LogCustomSummaryMetric,
'log_custom_summaty_metric.py': LogCustomSummatyMetric,
'log_existing_artifact_link_collection.py': LogExistingArtifactLinkCollection,
'log_histogram_plot.py': LogHistogramPlot,
'log_hyperparameter.py': LogHyperparameter,
'log_line_plot.py': LogLinePlot,
'log_metric.py': LogMetric,
'log_scatter_plot.py': LogScatterPlot,
'log_summary_metric.py': LogSummaryMetric,
'log_table.py': LogTable,
'registry_add_annotation.py': RegistryAddAnnotation,
'registry_collection_create.py': RegistryCollectionCreate,
Expand All @@ -76,6 +100,17 @@ const snippets = {
'registry_use_linked_artifact.py': RegistryUseLinkedArtifact,
'run_fork.py': RunFork,
'run_init.py': RunInit,
'run_resume.py': RunResume,
'run_rewind.py': RunRewind,
'runs_add_tags.py': RunsAddTags,
'runs_group.py': RunsGroup,
'runs_organize_by_type.py': RunsOrganizeByType,
'runs_update_tag.py': RunsUpdateTag,
'runs_update_tag_public_api.py': RunsUpdateTagPublicApi,
'sweep_config.py': SweepConfig,
'sweep_create.py': SweepCreate,
'sweep_initialize.py': SweepInitialize,
'sweep_start.py': SweepStart,
};

export const CodeSnippet = ({ file }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

with wandb.init(project="<project>") as run:
# Log the artifact with aliases
run.log_artifact(artifact, aliases=["<alias1>", "<alias2>"])
run.log_artifact(artifact, aliases=["<alias1>", "<alias2>"])
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Retrieve an existing artifact and add an alias to it
artifact = wandb.Api().artifact("entity/project/artifact:version")
artifact.aliases = ["<new-alias>"]
artifact.save()
artifact.save()
2 changes: 1 addition & 1 deletion snippets/en/_includes/code-examples/artifact_add_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@

# Log the artifact with tags
with wandb.init(project="<project>") as run:
run.log_artifact(artifact, tags=["<tag1>", "<tag2>"])
run.log_artifact(artifact, tags=["<tag1>", "<tag2>"])
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
# Retrieve an existing artifact and add a tag to it
artifact = wandb.Api().artifact("entity/project/artifact:version")
artifact.tags = ["new-tag"]
artifact.save()
artifact.save()
2 changes: 1 addition & 1 deletion snippets/en/_includes/code-examples/artifact_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@
# Training and logging code goes here

# Example of logging an artifact
run.log_artifact(artifact)
run.log_artifact(artifact)
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
with wandb.init(project="<project>") as run:

# Log the artifact's metadata
run.log_artifact(artifact)
run.log_artifact(artifact)
2 changes: 1 addition & 1 deletion snippets/en/_includes/code-examples/artifact_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
# Index the last two characters of the artifact version name (str) that
# consists of the version number
if artifact_version.name[-2:] == "v"+ "<version_number>":
artifact_version.delete(delete_aliases=True)
artifact_version.delete(delete_aliases=True)
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
type_name="<artifact_type>"
)

collection.delete()
collection.delete()
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
artifact = run.use_artifact("<artifact_name>:<alias>")

# Download a specific file or sub-folder
artifact.download(path_prefix="<file_name>") # downloads only the specified file or folder
artifact.download(path_prefix="<file_name>") # downloads only the specified file or folder
2 changes: 1 addition & 1 deletion snippets/en/_includes/code-examples/artifact_ttl.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@

with wandb.init(project="<project>", entity="<entity>") as run:
# Log the artifact with TTL
run.log_artifact(artifact)
run.log_artifact(artifact)
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
artifact.ttl = timedelta(days=365) # Delete in one year

# Save the updated artifact
artifact.save()
artifact.save()
2 changes: 1 addition & 1 deletion snippets/en/_includes/code-examples/artifact_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
# Update the artifact's description
artifact.description = "<description>"
# Save the updated artifact
artifact.save()
artifact.save()
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
artifact.aliases = ["replaced"]

# Persist all artifact modifications
artifact.save()
artifact.save()
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
entry = artifact.get_entry("<file_name>")

# Download the entire artifact
datadir = artifact.download()
datadir = artifact.download()
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
# Initialize a W&B run
with wandb.init(project="<project>") as run:
# Experiment code goes here
pass
pass
24 changes: 24 additions & 0 deletions snippets/en/_includes/code-examples/log_csv_files.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
```python
"""
Log a CSV file to W&B as a table.

Replace:
- values enclosed in angle brackets with your own
- <name>.csv in pd.read_csv() with the name of your CSV file
"""

import wandb
import pandas as pd

# Read CSV as a DataFrame object (pandas)
dataframe = pd.read_csv("<name>.csv")

# Convert the DataFrame into a W&B Table
table = wandb.Table(dataframe=dataframe)

# Start a W&B run to log data
with wandb.init(project="<project>") as run:

# Log the table to visualize it in the W&B UI
run.log({"<table_name>": table})
```
22 changes: 22 additions & 0 deletions snippets/en/_includes/code-examples/log_csv_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Log a CSV file to W&B as a table.

Replace:
- values enclosed in angle brackets with your own
- <name>.csv in pd.read_csv() with the name of your CSV file
"""

import wandb
import pandas as pd

# Read CSV as a DataFrame object (pandas)
dataframe = pd.read_csv("<name>.csv")

# Convert the DataFrame into a W&B Table
table = wandb.Table(dataframe=dataframe)

# Start a W&B run to log data
with wandb.init(project="<project>") as run:

# Log the table to visualize it in the W&B UI
run.log({"<table_name>": table})
Loading
Loading