> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-docs-1917.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Is it possible to save metrics offline and sync them to W&B later?

By default, `wandb.init` starts a process that syncs metrics in real time to the cloud. For offline use, set two environment variables to enable offline mode and sync later.

Set the following environment variables:

1. `WANDB_API_KEY=$KEY`, where `$KEY` is an API key created at [User Settings](https://wandb.ai/settings).
2. `WANDB_MODE="offline"`.

Here is an example of implementing this in a script:

```python theme={null}
import wandb
import os

os.environ["WANDB_API_KEY"] = "YOUR_KEY_HERE"
os.environ["WANDB_MODE"] = "offline"

config = {
    "dataset": "CIFAR10",
    "machine": "offline cluster",
    "model": "CNN",
    "learning_rate": 0.01,
    "batch_size": 128,
}

with wandb.init(project="offline-demo") as run:
    for i in range(100):
        run.log({"accuracy": i})
```

Sample terminal output is shown below:

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/lIX_1lVVY6B5YU9v/images/experiments/sample_terminal_output.png?fit=max&auto=format&n=lIX_1lVVY6B5YU9v&q=85&s=96d598bf689f84afc3b209e18fe1ca46" alt="Offline mode terminal output" width="1486" height="452" data-path="images/experiments/sample_terminal_output.png" />
</Frame>

After completing work, run the following command to sync data to the cloud:

```shell theme={null}
wandb sync wandb/dryrun-folder-name
```

<Frame>
  <img src="https://mintcdn.com/wb-21fd5541-docs-1917/lIX_1lVVY6B5YU9v/images/experiments/sample_terminal_output_cloud.png?fit=max&auto=format&n=lIX_1lVVY6B5YU9v&q=85&s=bb3ab65c7f33a7594c34e8ba51683a19" alt="Cloud sync terminal output" width="1496" height="408" data-path="images/experiments/sample_terminal_output_cloud.png" />
</Frame>

***

<Badge stroke shape="pill" color="orange" size="md">[Experiments](/support/models/tags/experiments)</Badge><Badge stroke shape="pill" color="orange" size="md">[Environment Variables](/support/models/tags/environment-variables)</Badge><Badge stroke shape="pill" color="orange" size="md">[Metrics](/support/models/tags/metrics)</Badge>
