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

# Databricks

> W&B를 Databricks와 통합하는 방법.

W\&B는 Databricks 환경에서 W\&B Jupyter 노트북 경험을 최적화하여 [Databricks](https://www.databricks.com/)와 통합됩니다.

## Databricks 설정

1. 클러스터에 wandb 설치하기

   클러스터 설정으로 이동하여 클러스터를 선택한 다음 **Libraries**를 클릭합니다. **Install New**를 클릭하고 **PyPI**를 선택한 후 `wandb` 패키지를 추가합니다.

2. 인증 설정하기

   W\&B 계정을 인증하기 위해 노트북에서 쿼리할 수 있는 Databricks secret을 추가할 수 있습니다.

   ```bash theme={null}
   # databricks cli 설치
   pip install databricks-cli

   # databricks UI에서 토큰 생성
   databricks configure --token

   # 다음 두 코맨드 중 하나를 사용하여 scope를 생성합니다 (databricks의 보안 기능 활성화 여부에 따라 다름):
   # 보안 애드온이 있는 경우
   databricks secrets create-scope --scope wandb
   # 보안 애드온이 없는 경우
   databricks secrets create-scope --scope wandb --initial-manage-principal users

   # https://wandb.ai/settings 에서 API 키 생성
   databricks secrets put --scope wandb --key api_key
   ```

## 예시

### 간단한 예시

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

# Databricks secret에서 API 키 가져오기
api_key = dbutils.secrets.get("wandb", "api_key")
wandb.login(key=api_key)

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

### Sweeps

wandb.sweep() 또는 wandb.agent()를 사용하려는 노트북에 필요한 (임시) 설정입니다:

```python theme={null}
import os

# 향후에는 이 설정이 필요하지 않을 예정입니다
os.environ["WANDB_ENTITY"] = "my-entity"
os.environ["WANDB_PROJECT"] = "my-project-that-exists"
```
