Skip to content

Latest commit

 

History

History
246 lines (168 loc) · 5.41 KB

DGX-SPARK-README.md

File metadata and controls

246 lines (168 loc) · 5.41 KB

DGX Spark Guide (Chapters 1-5)

This guide helps a reader run Chapters 1 through 5 on NVIDIA DGX Spark (GB10) with GPU acceleration.

1. What matters most on DGX Spark

DGX Spark GB10 requires a GPU build of PyTorch that supports compute capability sm_121.

  • Use PyTorch wheels from cu130 (or newer).
  • Do not use cu126 on GB10 for this book flow.

2. Host preflight checks

Run these checks before creating the Python environment:

nvidia-smi

You should see:

  • A visible NVIDIA GPU (GB10)
  • A modern driver (for example, 580+)
  • CUDA runtime capability compatible with CUDA 13.x

3. Setup from scratch

From repository root:

cd code
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip

Install GPU PyTorch for GB10:

python -m pip install --upgrade --index-url https://download.pytorch.org/whl/cu130 torch torchvision torchaudio

Install book dependencies:

python -m pip install -e ".[dev,chapter03]"

4. Verify CUDA is actually working

python - <<'PY'
import torch
print('torch', torch.__version__)
print('cuda', torch.cuda.is_available())
print('gpu_count', torch.cuda.device_count())
if torch.cuda.is_available():
    print('gpu_name', torch.cuda.get_device_name(0))
    x = torch.randn(1024, 1024, device='cuda')
    y = x @ x
    torch.cuda.synchronize()
    print('cuda_matmul_ok', y.shape)
PY

Expected:

  • cuda True
  • gpu_name NVIDIA GB10
  • Successful matmul output

5. One-time data prep used by Chapters 2 and 5

python scripts/build_it_support_dataset.py
python scripts/reformat_it_answers.py

6. Chapter-by-chapter run sequence (1 to 5)

Run from code/ with .venv active.

Chapter 1

Base-only sidebar run:

python -m chapter01.run_sidebar_example --base_only

Optional base+LoRA comparison after Chapter 5 smoke adapter exists:

python -m chapter01.run_sidebar_example --lora_dir chapter05/runs/validate_lora_smoke

Chapter 2

Quickstart training:

python -m chapter02.quickstart

Optional adapter preview:

python -m chapter02.run_chapter5_adapter --use-quickstart

Chapter 3

Manifest runnable path:

python -m chapter03.ch03_datasetmanifest

Synthetic pipeline path (requires ANTHROPIC_API_KEY):

python -m chapter03.ch03_synthetic_data_generation

Chapter 4

HF backend (GPU):

python -m chapter04.few_shot_demo --shots 8 --backend hf --output chapter04/runs/few_shot_hf_dgx.json

Validator (mock backend):

python -m chapter04.prompt_validator --shots 8 --runs 3 --backend mock

RAG eval (hash backend):

python -m chapter04.scripts.listing_4_5_rag_eval --k 3 --backend hash

Chapter 5

Chapter preflight + tiny LoRA smoke training:

python chapter05/scripts/validate_chapter05.py

Generation with smoke adapter:

python -m chapter05.generate --base Qwen/Qwen3-4B-Instruct-2507 --adapter chapter05/runs/validate_lora_smoke --prompt "My laptop won't connect to office Wi-Fi after update. What should I do?"

Minimal base-vs-adapter smoke evaluation:

python -m chapter05.scripts.listing_5_3_evaluate \
  --base Qwen/Qwen3-4B-Instruct-2507 \
  --adapter chapter05/runs/validate_lora_smoke \
  --dolly_test chapter05/data/smoke/valid.jsonl \
  --toy_golden chapter05/data/golden/toy_test.jsonl \
  --safety_prompts chapter05/data/golden/safety_regression_prompts.jsonl \
  --out chapter05/runs/eval_report_dgx_smoke

7. Quick regression test command

python -m pytest -q chapter04/tests chapter05/tests

8. Common DGX Spark issues and fixes

Issue: CUDA appears available but GPU kernels are unsupported

Symptom example:

  • Warning about unsupported sm_121 / compute capability 12.1

Fix:

  • Reinstall torch from cu130 index:
python -m pip install --upgrade --index-url https://download.pytorch.org/whl/cu130 torch torchvision torchaudio

Issue: No module named chapterXX

Fix:

  • Ensure you are in code/
  • Ensure .venv is activated
  • Reinstall editable package:
python -m pip install -e ".[dev,chapter03]"

Issue: Chapter 1 skips SFT comparison

This is expected in a Chapter 1-5 workflow because the SFT artifact is produced in Chapter 6.

9. Reproducible DGX Spark automation script

Use these scripts:

  • ./DGX-SPARK-RECIPE.sh (chapter-oriented: setup, ch1 ... ch5, all)
  • code/validation/cuda_dgx_spark/dgx_spark_recipe.sh (one-shot validation path)

Examples:

# Full setup + chapter 1-5 run path
./DGX-SPARK-RECIPE.sh all

# Run only chapter 4
./DGX-SPARK-RECIPE.sh ch4

# Fast smoke checks
./DGX-SPARK-RECIPE.sh smoke

Validation logs and run report from a real DGX Spark pass are in:

  • code/validation/cuda_dgx_spark/

Recipe validation status

The new chapter-oriented recipe was exercised on DGX Spark in this environment:

  • ./DGX-SPARK-RECIPE.sh smoke -> PASS
  • ./DGX-SPARK-RECIPE.sh ch4 -> PASS
  • ./DGX-SPARK-RECIPE.sh ch1 -> PASS
  • ./DGX-SPARK-RECIPE.sh ch2 -> PASS (after recipe fix)
  • ./DGX-SPARK-RECIPE.sh ch3 -> PASS
  • ./DGX-SPARK-RECIPE.sh ch5 -> PASS
  • ./DGX-SPARK-RECIPE.sh all -> PASS

Recipe fix applied during validation:

  • Updated data reformat step to process both train and valid splits by default: python scripts/reformat_it_answers.py

If you are trying this on a fresh DGX Spark machine, run setup first, then smoke, then chapter commands (ch1 ... ch5) or all.