# 6. GR00T Fine-tuning 실행

[NVIDIA Isaac GR00T](https://github.com/NVIDIA/Isaac-GR00T)는 로봇을 위한 Foundation Model입니다. 이 워크플로는 GR00T 모델을 demo 데이터셋으로 fine-tuning합니다.

**Fine-tuning이란?** 사전 학습된 대형 모델을 특정 작업(예: 물건 집기)에 맞게 추가 학습하는 과정입니다. 전체 모델을 처음부터 학습하는 것보다 훨씬 적은 데이터와 시간으로 좋은 성능을 얻을 수 있습니다.

이 워크플로는:

1. PyTorch 컨테이너에서 Isaac-GR00T 코드를 clone
2. 필요한 Python 패키지 설치
3. demo 데이터셋(robot\_sim.PickNPlace)으로 100 step 학습
4. Fine-tuned 모델을 저장

***

### 6.1 워크플로 파일 작성

```bash
cat > /tmp/groot-finetune.yaml <<'EOF'
workflow:
  name: groot-finetune
  resources:
    default:
      cpu: 4
      gpu: 1
      memory: 32Gi
      storage: 100Gi
      platform: gpu-train
  tasks:
  - name: groot-finetune
    image: pytorch/pytorch:2.6.0-cuda12.4-cudnn9-devel
    command: ["/bin/bash"]
    args: ["/tmp/entry.sh"]
    environment:
      DEBIAN_FRONTEND: 'noninteractive'
      WANDB_MODE: 'disabled'
    files:
    - contents: |-
        set -ex
        export GROOT_DIR=/workspace/Isaac-GR00T

        apt-get update || true
        apt-get install -y --no-install-recommends \
            git git-lfs libgl1-mesa-glx libglib2.0-0 \
            libsm6 libxext6 libxrender-dev build-essential cmake wget curl || true

        git clone https://github.com/NVIDIA/Isaac-GR00T.git $GROOT_DIR
        cd $GROOT_DIR
        git checkout 796ca8d87360913c47e9f75e17c11d63f7805048

        pip install --upgrade setuptools
        pip install gpustat wandb==0.19.0
        pip install -e ".[base]"

        pip uninstall -y transformer-engine || true
        pip install flash_attn==2.7.1.post4 -U --force-reinstall
        pip uninstall -y opencv-python opencv-python-headless || true
        pip install opencv-python==4.8.0.74
        pip install --force-reinstall torch==2.5.1 torchvision==0.20.1 torchaudio==2.5.1 numpy==1.26.4

        pip install -e . --no-deps
        pip install "accelerate>=0.26.0"

        nvidia-smi

        # Kubernetes의 /dev/shm 크기 제한(64MB) 우회
        mount -o remount,size=8G /dev/shm 2>/dev/null || true

        python scripts/gr00t_finetune.py \
          --dataset-path ./demo_data/robot_sim.PickNPlace \
          --num-gpus 1 \
          --max-steps 100 \
          --output-dir /tmp/finetuned-model \
          --data-config fourier_gr1_arms_only \
          --dataloader_num_workers 0

        echo "=== Training complete ==="
        ls -la /tmp/finetuned-model/

      path: /tmp/entry.sh
EOF
```

**워크플로 YAML 구조 설명:**

* `resources.default` — 워크플로에 할당할 리소스 (CPU, GPU, 메모리, 디스크)
* `tasks[].image` — 실행할 컨테이너 이미지
* `tasks[].files` — 컨테이너 안에 생성할 파일 (여기서는 학습 스크립트)
* `tasks[].environment` — 환경 변수
* `WANDB_MODE: disabled` — Weights & Biases 로깅 비활성화 (API 키 불필요)
* `--dataloader_num_workers 0` — Kubernetes /dev/shm 64MB 제한 우회

***

### 6.2 워크플로 제출

```bash
osmo workflow submit /tmp/groot-finetune.yaml
```

***

### 6.3 모니터링

```bash
# 전체 상태 확인
osmo workflow query groot-finetune-1

# 실시간 로그 확인
osmo workflow logs groot-finetune-1

# Pod 상태 확인
kubectl get pods -n osmo-workflows -w
```

***

### 6.4 완료 확인

전체 소요 시간: 약 15분

* 이미지 풀: \~2분 (pytorch 이미지 7.4GB)
* 의존성 설치: \~8분 (pip install)
* 학습 (100 steps): \~5분 (\~3초/step)

```bash
osmo workflow query groot-finetune-1
```

**예상 출력:**

```
Workflow ID : groot-finetune-1
Status      : COMPLETED

Task Name        Start Time               Status
================================================
groot-finetune   ...                      COMPLETED
```

로그에서 학습 결과 확인:

```bash
osmo workflow logs groot-finetune-1
```

**예상 출력:**

```
100%|██████████| 100/100 [04:53<00:00, 2.92s/it]
{'train_runtime': 379.34, 'train_samples_per_second': 8.44, 'train_loss': 0.137}
=== Training complete ===
model.safetensors.index.json
trainer_state.json
training_args.bin
```

{% hint style="success" %}
`train_loss: 0.137`과 `model.safetensors` 파일이 보이면 fine-tuning이 성공한 것입니다!
{% endhint %}

***

### 6.5 GPU 노드 스케일다운

워크플로가 완료되면 비용 절감을 위해 GPU 노드를 0대로 되돌립니다.

```bash
aws eks update-nodegroup-config \
  --cluster-name osmo-eks \
  --nodegroup-name gpu-train \
  --scaling-config minSize=0,maxSize=4,desiredSize=0 \
  --region us-west-2
```

***

### 비용 참고

| 리소스          | 사양                                  | 시간당 비용 (us-west-2) | 언제 과금?      |
| ------------ | ----------------------------------- | ------------------ | ----------- |
| GPU-Train 노드 | g6e.12xlarge (4×L40S)               | \~$4.99/대          | 학습 실행 중     |
| GPU-Sim 노드   | g5.12xlarge (4×A10G)                | \~$5.67/대          | 시뮬레이션 실행 중  |
| 기본 유지        | EKS + System 노드 + RDS + Redis + NAT | \~$0.67            | 항상 (인프라 유지) |

{% hint style="info" %}
GPU 노드는 `desiredSize=0`으로 설정되어 있어, 워크플로를 실행하지 않으면 GPU 비용이 $0입니다. 이 워크숍 전체를 1시간 내 완료하면 GPU 비용은 약 $5\~10입니다.
{% endhint %}

***

### Troubleshooting

| 증상                               | 원인               | 해결                                                                                                           |
| -------------------------------- | ---------------- | ------------------------------------------------------------------------------------------------------------ |
| `No space left on device` (학습 중) | /dev/shm 64MB 제한 | `--dataloader_num_workers 0` 추가                                                                              |
| `wandb.errors.UsageError`        | wandb API 키 없음   | `WANDB_MODE: disabled` 환경변수 추가                                                                               |
| Pod `SCHEDULING`에서 멈춤            | GPU 노드가 0대       | [5. GPU 검증](/physical-ai-on-aws/physical-ai-on-aws-guide/nvidia-osmo-on-aws/5.-gpu-verification.md) Step 5.1 |
| 이미지 풀 실패 (nvcr.io)               | NGC secret 미생성   | [3. OSMO 설치](/physical-ai-on-aws/physical-ai-on-aws-guide/nvidia-osmo-on-aws/3.-osmo-install.md) Step 3.5    |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hi-space.gitbook.io/physical-ai-on-aws/physical-ai-on-aws-guide/nvidia-osmo-on-aws/6.-groot-finetune.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
