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

> Spark クラスター 上で実験管理、メトリクスのログ記録、モデル管理を行えるように、W&B を Databricks と統合します。

# Databricks

W\&B は、Databricks 環境での W\&B の Jupyter notebook エクスペリエンスをカスタマイズすることで、[Databricks](https://www.databricks.com/) と統合されています。

<div id="configure-databricks">
  ## Databricks を設定する
</div>

1. クラスターに wandb をインストールする

   クラスター設定にアクセスし、対象のクラスターを選択して **Libraries** をクリックします。次に **Install New** をクリックし、**PyPI** を選択してパッケージ `wandb` を追加します。

2. 認証を設定する

   W\&B アカウントを認証するには、ノートブックからクエリできる Databricks シークレットを追加します。

   ```bash theme={null}
   # databricks cli をインストールする
   pip install databricks-cli

   # databricks UI でトークンを生成する
   databricks configure --token

   # 2 つのコマンドのいずれかを使ってスコープを作成する（databricks で security features が有効かどうかによって異なります）:
   # security add-on あり
   databricks secrets create-scope --scope wandb
   # security add-on なし
   databricks secrets create-scope --scope wandb --initial-manage-principal users

   # https://wandb.ai/settings で APIキー を作成する
   databricks secrets put --scope wandb --key api_key
   ```

<div id="examples">
  ## 例
</div>

<div id="simple-example">
  ### 基本的な例
</div>

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

api_key = dbutils.secrets.get("wandb", "api_key")
wandb.login(key=api_key)

with wandb.init() as run:
    run.log({"foo": 1})
```

<div id="sweeps">
  ### Sweeps
</div>

wandb.sweep() または wandb.agent() を使用するノートブックで必要な一時的なセットアップ:

```python theme={null}
import os

# これらは将来的には不要になります
os.environ["WANDB_ENTITY"] = "my-entity"
os.environ["WANDB_PROJECT"] = "my-project-that-exists"
```
