원클릭으로
experiment-setup
Guide Hydra configuration management patterns for ML projects. "hydra", "OmegaConf" などで起動。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Guide Hydra configuration management patterns for ML projects. "hydra", "OmegaConf" などで起動。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Ask OpenAI Codex CLI for an autonomous second AI opinion. "ask codex", "codex と相談" などで起動。
Request GitHub Copilot review on a Pull Request. "PR レビュー依頼", "copilot review" などで起動。
Extract VTT transcript from a Zoom recording share page. "zoom transcript", "zoom 文字起こし" などで起動。
Download the video (MP4) from a Zoom recording share page. "zoom video download", "zoom 録画 ダウンロード", "zoom 動画 ダウンロード" などで起動。
Round-trip code review through difit. Use when the user mentions "difit", "diff review", "open the diff", "let me look at this", or "review this PR locally". Launch mode arg — "open" (default, no comments at launch), "explain" (AI annotates its own change), "review" (AI posts findings on human code).
Stop tool execution before exhausting your Claude usage — set a 5h/7d usage-% or per-session cost threshold.
| name | experiment-setup |
| description | Guide Hydra configuration management patterns for ML projects. "hydra", "OmegaConf" などで起動。 |
| metadata | {"author":"pokutuna"} |
| compatibility | requires hydra-core, omegaconf |
Hydra によるパラメータ管理と実験実行のパターン。 実験パラメータと環境設定を分離し、yaml は差分だけで管理する。
experiments/ 配下に実験ごとのディレクトリ NNN-name/ を作成する。
アプローチが異なる実験は別ディレクトリ、同じアプローチのパラメータ違いは exp/ 内の yaml で管理する。
experiments/NNN-name/
config.yaml # エントリポイント (defaults 指定 + hydra 設定)
train.py # dataclass 定義 + 学習ロジック
exp/
001.yaml # パラメータ違い (差分のみ)
002.yaml
env/ # 環境を分ける場合のみ作成
runpod.yaml
local.yaml
from dataclasses import dataclass, field
from hydra.core.config_store import ConfigStore
@dataclass
class ExpConfig:
name: str = "default"
seed: int = 42
learning_rate: float = 2e-5
batch_size: int = 16
# ハイパーパラメータはフラットに配置 (ネストしない)
@dataclass
class EnvConfig:
base_model: str = "/workspace/models/Model"
output_dir: str = "output/NNN-name"
model_output_dir: str = "/workspace/output/NNN-name"
@dataclass
class Config:
exp: ExpConfig = field(default_factory=ExpConfig)
env: EnvConfig = field(default_factory=EnvConfig)
cs = ConfigStore.instance()
cs.store(name="default", group="exp", node=ExpConfig)
cs.store(name="default", group="env", node=EnvConfig)
exp/default.yaml や env/default.yaml は作らない (ConfigStore の name="default" と衝突するため)。
# 設定確認: python train.py --cfg job
# 実験指定: python train.py exp=001
defaults:
- _self_
- exp: default # ConfigStore のデフォルト
- env: default # ConfigStore のデフォルト (yaml なし)
# - env: runpod # yaml がある場合はこちら
- override hydra/job_logging: none # hydra ログファイル生成を無効化
hydra:
output_subdir: null # .hydra/ ディレクトリを作らない
job:
chdir: false # 作業ディレクトリを変更しない
run:
dir: . # 出力ディレクトリをカレントに
config.yaml には exp: や env: ブロックで値を直接書かない。値は dataclass のデフォルトで管理し、変更は exp/*.yaml で行う。
# exp/001.yaml
defaults:
- default@_here_ # ConfigStore の "default" スキーマを継承
name: "001-lr-sweep"
learning_rate: 5.0e-5
defaults: [default@_here_] で dataclass のデフォルト値を継承@_here_ は「このファイル自身の位置に展開する」という意味EnvConfig のデフォルト値がメインの実行環境に合っていれば yaml は不要。
別環境で動かす必要が出たら env/ に yaml を追加する:
# env/local.yaml
defaults:
- default@_here_
base_model: "Qwen/Qwen3-4B-Instruct-2507" # HuggingFace から取得
model_output_dir: "output/NNN-name" # ローカルパス
python train.py exp=001 env=local
| 置き場 | 内容 | 判断基準 |
|---|---|---|
exp | 学習パラメータ、データセット、seed | 実験ごとに変える値 |
env | モデルパス、出力パス | 同じ実験を別マシンで動かすときに変える値 |
@hydra.main(version_base=None, config_path=".", config_name="config")
def main(cfg: Config) -> None:
# 実験実行...
if __name__ == "__main__":
main()
Hydra 組み込みの --cfg オプションを使う。show_config フラグは不要。
python train.py --cfg job # 自分の設定だけ表示
python train.py --cfg job exp=001 # 実験指定して確認
python train.py --cfg hydra # Hydra 自体の設定
python train.py --cfg all # 全部
uv run python train.py # デフォルト設定で実行
uv run python train.py exp=001 # exp/001.yaml を使用
uv run python train.py exp=001 env=local # exp/001.yaml, env/local.yaml を使用
uv run python train.py exp=001 exp.debug=true # オーバーライド
uv run python train.py exp=001 exp.batch_size=8 # 値を直接変更
# fold: [0, 1, 2, 3, 4]
for fold in cfg.exp.fold:
with wandb.init(
project=os.environ.get("WANDB_PROJECT", "my-project"),
group=cfg.exp.name,
name=f"{cfg.exp.name}/fold{fold}",
config=OmegaConf.to_container(cfg.exp, resolve=True), # type: ignore
mode="disabled" if cfg.exp.debug else "online",
):
train_fold(cfg, fold)
...
from hydra import compose, initialize
with initialize(version_base=None, config_path="./experiments/001-baseline"):
cfg = compose(
config_name="config.yaml", # .yaml をつける
overrides=["exp.name=foo"],
)
User: 「新しい実験 002-larger-model を始めたい」
mkdir -p experiments/002-larger-model/expconfig.yaml と train.py をコピーexp/001.yaml を作成してパラメータ設定uv run python train.py --cfg job exp=001 で設定確認uv run python train.py exp=001 で実行User: 「learning rate を変えて試したい」
exp/002.yaml を作成:
defaults:
- default@_here_
name: "002-smaller-lr"
learning_rate: 1e-5
uv run python train.py exp=002 で実行User: 「ローカルで同じ実験を動かしたい」
env/local.yaml を作成:
defaults:
- default@_here_
base_model: "Qwen/Qwen3-4B-Instruct-2507"
model_output_dir: "output/002-larger-model"
env: local に変更、または:
uv run python train.py exp=001 env=local
config_path 確認defaults の _self_ の位置を確認"exp.fold=[0,1,2]" と引用符で囲むGlobalHydra.instance().clear() してから initializedefaults:
- default@_here_ # default の内容をこの階層にマージ
str | list[str]) は OmegaConf がサポートしない