diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4caa51f6..58e82809 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,7 +17,7 @@ trainite init my-experiment --model transformer --dataset string-reverse ├─ 2. Config assembly │ Instantiate Pydantic config defaults for each component │ Inject collate function target from ModelSpec into DataConfig -│ Build a complete ProjectConfig and dump it to config.yaml +│ Build a complete ProjectConfig and dump it to configs/config.yaml │ ├─ 3. Template copying │ Copy implementation files (model, dataset, trainer, utils, main, config) diff --git a/README.md b/README.md index f266b83e..05eed025 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,8 @@ Built on [PyTorch-Ignite](https://github.com/pytorch/ignite), the generated code ``` my-experiment/ -├── config.yaml # YAML configuration (edit hyperparameters here) +├── configs/ # YAML configurations (edit hyperparameters here) +│ └── config.yaml ├── config.py # Pydantic validation models (IDE autocomplete) ├── models/ # Model architecture templates ├── dataset_impl/ # Dataset and transform implementations @@ -100,7 +101,7 @@ cd my-experiment pip install -e . # 3. Run training -python main.py config.yaml +python main.py configs/config.yaml ``` --- @@ -108,7 +109,7 @@ python main.py config.yaml ## Usage > [!NOTE] -> If you are using the `uv` workflow, prefix commands with `uv run` (e.g., `uv run trainite init` or `uv run python main.py config.yaml`). If you are using standard `pip`/`venv`, run them directly (e.g., `trainite init` or `python main.py config.yaml`). +> If you are using the `uv` workflow, prefix commands with `uv run` (e.g., `uv run trainite init` or `uv run python main.py configs/config.yaml`). If you are using standard `pip`/`venv`, run them directly (e.g., `trainite init` or `python main.py configs/config.yaml`). ### Initialize a Project @@ -137,7 +138,7 @@ Interactive prompt preview: ? Run name: rope-transformer__string-reverse ? Enable SkyPilot cloud training (generate sky.yaml)? No - Generated config.yaml + Generated configs/config.yaml Generated models/rope_transformer.py Generated dataset_impl/string_reverse.py Generated dataset_impl/transformed.py @@ -156,15 +157,15 @@ Your generated project is a standalone application with no runtime dependency on ```bash cd my-experiment -python main.py config.yaml +python main.py configs/config.yaml ``` ### Monitor & Iterate - **TensorBoard**: `tensorboard --logdir outputs` -- **ClearML**: Run `clearml-init`, then set `logger: clearml` in `config.yaml`. +- **ClearML**: Run `clearml-init`, then set `logger: clearml` in `configs/config.yaml`. - **Edit architecture**: Open `models/transformer.py` and modify the model. -- **Edit hyperparameters**: Open `config.yaml` and change learning rates, batch sizes, data splits, etc. +- **Edit hyperparameters**: Open `configs/config.yaml` and change learning rates, batch sizes, data splits, etc. With ClearML enabled, Trainite keeps checkpoints in the run directory and uploads them to ClearML's default file server. Generated projects document how to use another storage URI, defer to ClearML configuration, or keep @@ -251,7 +252,7 @@ sky launch sky.yaml ## Configuration -All configuration lives in `config.yaml`. The top-level blocks map to base validation schemas in `config.py` (e.g. `ModelConfig`, `DatasetConfig`). This ensures that your configuration has the correct overall structure and valid keys, while allowing you to pass custom hyperparameters to your local components. +All configuration lives in `configs/config.yaml`. The top-level blocks map to base validation schemas in `config.py` (e.g. `ModelConfig`, `DatasetConfig`). This ensures that your configuration has the correct overall structure and valid keys, while allowing you to pass custom hyperparameters to your local components. ### Swapping Components with `_target_` @@ -283,7 +284,7 @@ Since the generated code is yours, you can override at any layer without touchin | Eval step | Override `_eval_step()` in `trainer.py` | | Metrics | Add Ignite metrics in `_attach_metrics()` in `trainer.py` | | Handlers | Attach Ignite event handlers to `self.trainer` in `trainer.py` | -| Config fields | Add fields to the Pydantic models in `config.py` and corresponding keys in `config.yaml` | +| Config fields | Add fields to the Pydantic models in `config.py` and corresponding keys in `configs/config.yaml` | --- @@ -296,7 +297,7 @@ Working examples are in the [`examples/`](examples/) directory: | [`string_reversal`](examples/string_reversal/) | Train a decoder-only transformer to reverse strings. Demonstrates the full pipeline: data generation, training, evaluation, and inference logging. | | [`counting`](examples/counting/) | Train a decoder-only transformer to count the number of occurrences of a target token in a sequence. | -Each example is a standalone project — `cd` into it, install dependencies, and run `python main.py config.yaml`. +Each example is a standalone project — `cd` into it, install dependencies, and run `python main.py configs/config.yaml`. --- diff --git a/docs/cli.md b/docs/cli.md index 7228f2f4..0dfcd316 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -3,7 +3,7 @@ Trainite exposes a small command-line interface for scaffolding and extending standalone training projects. For project structure and first-run setup, see [Home](index.md). -For `config.yaml` details and training behavior, see [Training Guide](training.md). +For `configs/config.yaml` details and training behavior, see [Training Guide](training.md). ## Command summary @@ -45,8 +45,8 @@ You will be prompted for: 3. The primary active model (when multiple models are selected) 4. Dataset template 5. Trainer template -6. Output root (`output.root` in `config.yaml`) -7. Run name (`output.run_name` in `config.yaml`) +6. Output root (`output.root` in `configs/config.yaml`) +7. Run name (`output.run_name` in `configs/config.yaml`) 8. Whether to generate `sky.yaml` for SkyPilot ### Non-interactive mode @@ -68,11 +68,11 @@ trainite init my-experiment \ - `PROJECT_DIR` (positional): Output directory for the generated project (default: `my-cool-experiment`). - `--model`: One or more model templates. At least one is required. -- `--primary-model`: Active model in generated `config.yaml`. Must be one of the selected models; defaults to the first selected model. +- `--primary-model`: Active model in generated `configs/config.yaml`. Must be one of the selected models; defaults to the first selected model. - `--dataset`: Dataset template. - `--trainer`: Trainer template. -- `--output-root`: Value written to `output.root` in generated `config.yaml` (default: `outputs`). -- `--run-name`: Value written to `output.run_name` in generated `config.yaml` (default: `__`, with `-` replaced by `_`). +- `--output-root`: Value written to `output.root` in generated `configs/config.yaml` (default: `outputs`). +- `--run-name`: Value written to `output.run_name` in generated `configs/config.yaml` (default: `__`, with `-` replaced by `_`). - `--sky`: Also generate `sky.yaml` and include SkyPilot dependency in generated `pyproject.toml`. - `--force`: Overwrite starter files in a non-empty existing directory. @@ -96,14 +96,14 @@ trainite init my-experiment \ When multiple models are selected: - Trainite scaffolds each model template into `models/` (for example, `models/rope_transformer.py` and `models/basic_transformer.py`). -- The **first** model is the default primary model for generated `config.yaml`. Use `--primary-model` to choose a different selected model without changing the model list order. -- In interactive mode, use Space to select or deselect multiple checkboxes, and press Enter to confirm. Trainite then asks which selected model should be the primary active model in `config.yaml`. +- The **first** model is the default primary model for generated `configs/config.yaml`. Use `--primary-model` to choose a different selected model without changing the model list order. +- In interactive mode, use Space to select or deselect multiple checkboxes, and press Enter to confirm. Trainite then asks which selected model should be the primary active model in `configs/config.yaml`. ## `trainite add:sky` Enable SkyPilot support in an **existing** Trainite-generated project. -Run this command from your project directory (the one containing `config.yaml` and `main.py`): +Run this command from your project directory (the one containing `configs/config.yaml` and `main.py`): ```bash cd my-experiment @@ -113,14 +113,14 @@ trainite add:sky What it does: 1. Generates `sky.yaml` from Trainite's SkyPilot template. -2. Uses `project_name` from `config.yaml` (or falls back to the folder name) in the generated config. +2. Uses `project_name` from `configs/config.yaml` (or falls back to the folder name) in the generated config. 3. Adds a `skypilot` dependency to `pyproject.toml` (if it is not already present). Option: - `--force`: Overwrite an existing `sky.yaml`. -If `config.yaml` or `main.py` is missing, the command exits with an error and asks you to run it from a valid Trainite experiment directory. +If `configs/config.yaml` or `main.py` is missing, the command exits with an error and asks you to run it from a valid Trainite experiment directory. ### Quickstart with SkyPilot diff --git a/docs/index.md b/docs/index.md index 6636a545..6f018873 100644 --- a/docs/index.md +++ b/docs/index.md @@ -12,7 +12,7 @@ to see the currently available model, dataset, and trainer choices. See also: - [CLI Guide](cli.md) for all commands and flags. -- [Training Guide](training.md) for `config.yaml` structure and run behavior. +- [Training Guide](training.md) for `configs/config.yaml` structure and run behavior. ## Getting Started @@ -71,12 +71,12 @@ trainite init my-experiment \ ``` Trainite will generate both model files under `models/`; the first model listed -is used as the default active model in `config.yaml`. +is used as the default active model in `configs/config.yaml`. The command prints the files it created: ```text -Generated config.yaml +Generated configs/config.yaml Generated models/rope_transformer.py Generated dataset_impl/string_reverse.py Generated dataset_impl/transformed.py @@ -91,7 +91,7 @@ Generated pyproject.toml Trainite creates `my-experiment/` with: -- `config.yaml` for model, data, training, and output settings +- `configs/config.yaml` for model, data, training, and output settings - `main.py` as the training entry point - local `models/`, `dataset_impl/`, and `trainer.py` implementations - `pyproject.toml` with the generated project's runtime dependencies @@ -106,7 +106,7 @@ Install the generated project's dependencies and start training: ```bash cd my-experiment uv sync -uv run python main.py config.yaml +uv run python main.py configs/config.yaml ``` #### With pip @@ -120,13 +120,13 @@ cd my-experiment python3 -m venv .venv source .venv/bin/activate pip install -e . -python main.py config.yaml +python main.py configs/config.yaml ``` The run writes logs, checkpoints, and TensorBoard data beneath `outputs/rope_transformer__string_reverse/` in a timestamped directory. -You now have a standalone project. Change `config.yaml` to tune the experiment, +You now have a standalone project. Change `configs/config.yaml` to tune the experiment, or edit the generated Python modules to replace the starter implementation. ## Case Studies & Resources diff --git a/docs/training.md b/docs/training.md index 01bad4cb..6cece8b7 100644 --- a/docs/training.md +++ b/docs/training.md @@ -133,16 +133,16 @@ Split behavior by dataset family: ## Running training -Each example has a `main.py` entry point. From the example directory: +Each generated project has a `main.py` entry point. From the project directory: ```bash -uv run python main.py config.yaml +uv run python main.py configs/config.yaml ``` Or without `uv`: ```bash -python main.py config.yaml +python main.py configs/config.yaml ``` What happens under the hood: diff --git a/examples/counting/README.md b/examples/counting/README.md index 154de211..9a30c074 100644 --- a/examples/counting/README.md +++ b/examples/counting/README.md @@ -46,8 +46,8 @@ Therefore, the model must learn to recognize `L_k` up to `k = d + 2` block alter ## Project Structure -* `config.yaml`: Baseline hyperparameters for a single training run. -* `main.py`: Entrypoint for single run. Run it with `python main.py config.yaml`. +* `configs/config.yaml`: Baseline hyperparameters for a single training run. +* `main.py`: Entrypoint for single run. Run it with `python main.py configs/config.yaml`. * `sweep.py`: Outer loop hyperparameter sweep script. * `plot_results.py`: Unified plotting script that generates heatmaps for every unique configuration and the aggregated best configurations. * `models/transformer.py`: Causal transformer decoder without positional encodings. @@ -74,9 +74,9 @@ pip install -e . ``` ### 2. Run a Baseline Experiment -Train a single model configuration defined in `config.yaml`: +Train a single model configuration defined in `configs/config.yaml`: ```bash -uv run python main.py config.yaml +uv run python main.py configs/config.yaml ``` ### 3. Run the Multi-Config Sweep diff --git a/examples/counting/config.yaml b/examples/counting/configs/config.yaml similarity index 100% rename from examples/counting/config.yaml rename to examples/counting/configs/config.yaml diff --git a/examples/counting/main.py b/examples/counting/main.py index c510c6e0..6b055b3b 100644 --- a/examples/counting/main.py +++ b/examples/counting/main.py @@ -7,7 +7,7 @@ def main() -> None: parser = argparse.ArgumentParser() - parser.add_argument("config", nargs="?", default="config.yaml") + parser.add_argument("config", nargs="?", default="configs/config.yaml") args = parser.parse_args() config = load_config(Path(args.config), ProjectConfig) trainer = Trainer(config) diff --git a/examples/counting/sweep.py b/examples/counting/sweep.py index 9a504b14..c989a026 100644 --- a/examples/counting/sweep.py +++ b/examples/counting/sweep.py @@ -44,7 +44,7 @@ def main() -> None: ) # Load base config from local yaml - config = load_config(Path("config.yaml"), ProjectConfig) + config = load_config(Path("configs/config.yaml"), ProjectConfig) # Dynamic overrides config.data.dataset.k = k diff --git a/examples/string_reversal/README.md b/examples/string_reversal/README.md index ff973b08..691f89af 100644 --- a/examples/string_reversal/README.md +++ b/examples/string_reversal/README.md @@ -25,7 +25,7 @@ The decoder receives a prompt followed by the expected completion: abc123 321cba ``` -Only completion tokens contribute to the training loss. The dataset is automatically split into training, validation, and test sets using the ratios in `config.yaml`. +Only completion tokens contribute to the training loss. The dataset is automatically split into training, validation, and test sets using the ratios in `configs/config.yaml`. Important data settings: @@ -100,7 +100,7 @@ From this directory: ```bash uv sync -uv run python main.py config.yaml +uv run python main.py configs/config.yaml ``` Training outputs are written below `outputs///`. Each run contains its resolved configuration, console log, TensorBoard data, and model checkpoints. @@ -142,7 +142,7 @@ Replace `depth` with `width` or `full` as needed. Without `--time-budget`, a run ## Files -- `config.yaml` — experiment configuration. +- `configs/config.yaml` — experiment configuration. - `main.py` — single-run entry point. - `sweep.py` — depth and width sweeps. - `trainer.py` — training, metrics, generation, and checkpoints. diff --git a/examples/string_reversal/config.yaml b/examples/string_reversal/configs/config.yaml similarity index 100% rename from examples/string_reversal/config.yaml rename to examples/string_reversal/configs/config.yaml diff --git a/examples/string_reversal/main.py b/examples/string_reversal/main.py index c510c6e0..6b055b3b 100644 --- a/examples/string_reversal/main.py +++ b/examples/string_reversal/main.py @@ -7,7 +7,7 @@ def main() -> None: parser = argparse.ArgumentParser() - parser.add_argument("config", nargs="?", default="config.yaml") + parser.add_argument("config", nargs="?", default="configs/config.yaml") args = parser.parse_args() config = load_config(Path(args.config), ProjectConfig) trainer = Trainer(config) diff --git a/examples/string_reversal/sweep.py b/examples/string_reversal/sweep.py index 36225e36..1039e014 100644 --- a/examples/string_reversal/sweep.py +++ b/examples/string_reversal/sweep.py @@ -84,7 +84,11 @@ def parse_args(): choices=["depth", "width", "full"], help="which axis to sweep: depth (vary layers), width (vary hidden/heads), or full (cross-product)", ) - p.add_argument("--config", default="config.yaml", help="path to config.yaml (default: config.yaml)") + p.add_argument( + "--config", + default="configs/config.yaml", + help="path to configs/config.yaml (default: configs/config.yaml)", + ) p.add_argument( "--logger", default="tensorboard", diff --git a/tests/cli_sky_test.py b/tests/cli_sky_test.py index acff05d7..b96ac2b8 100644 --- a/tests/cli_sky_test.py +++ b/tests/cli_sky_test.py @@ -17,7 +17,8 @@ def mock_trainite_project(tmp_path: Path) -> Path: root: outputs run_name: test_run """ - (project_dir / "config.yaml").write_text(config_yaml) + (project_dir / "configs").mkdir() + (project_dir / "configs/config.yaml").write_text(config_yaml) (project_dir / "main.py").write_text("# main entrypoint\n") pyproject_toml = """[project] @@ -49,7 +50,7 @@ def test_sky_init_in_valid_project(mock_trainite_project: Path, monkeypatch: pyt assert data["resources"]["use_spot"] is False assert data["resources"]["disk_size"] == 50 assert "uv sync" in data["setup"] - assert "uv run python main.py config.yaml" in data["run"] + assert "uv run python main.py configs/config.yaml" in data["run"] # Check pyproject.toml updated pyproject_doc = tomlkit.parse((mock_trainite_project / "pyproject.toml").read_text()) diff --git a/tests/cli_test.py b/tests/cli_test.py index 5637623b..adc7f19a 100644 --- a/tests/cli_test.py +++ b/tests/cli_test.py @@ -87,7 +87,7 @@ def fake_prompt_multi_choice( assert captured["Model(s):"] == [DEFAULT_MODEL] assert captured["Dataset:"] == DEFAULT_DATASET assert captured["Trainer:"] == DEFAULT_TRAINER - assert captured["Primary active model in config.yaml:"] == init.DEFAULT_MODEL + assert captured["Primary active model in configs/config.yaml:"] == init.DEFAULT_MODEL def test_default_constants_exist_in_registry(): @@ -134,7 +134,7 @@ def fake_prompt_multi_choice(prompt, choices, default=None, instruction=None): init.run_interactive_mode() - assert captured["Primary active model in config.yaml:"] == "basic-transformer" + assert captured["Primary active model in configs/config.yaml:"] == "basic-transformer" def test_cli_init_defaults_are_explicit(): @@ -193,7 +193,7 @@ def test_init_generates_valid_project(models: list[str], dataset: str, trainer: preprocessor_file = f"preprocessors/{preprocessor_spec.name}.py" if preprocessor_spec else None expected_files = [ - "config.yaml", + "configs/config.yaml", "config.py", *[f"models/{spec.name}.py" for spec in model_specs], f"dataset_impl/{dataset_spec.name}.py", @@ -209,10 +209,11 @@ def test_init_generates_valid_project(models: list[str], dataset: str, trainer: for filename in expected_files: if filename is not None: assert (project_dir / filename).exists(), f"{filename} missing" + assert not (project_dir / "config.yaml").exists() - # Check that target inside config.yaml is rewritten correctly + # Check that target inside configs/config.yaml is rewritten correctly # and points to primary model - with open(project_dir / "config.yaml", "r") as f: + with open(project_dir / "configs/config.yaml", "r") as f: generated_config = yaml.safe_load(f) assert generated_config["project_name"] == project_dir.name @@ -299,8 +300,8 @@ def test_generated_project_is_runnable() -> None: check=True, ) - # 2. Modify config.yaml to run a minimal workload - config_path = project_dir / "config.yaml" + # 2. Modify configs/config.yaml to run a minimal workload + config_path = project_dir / "configs/config.yaml" with open(config_path, "r") as f: config = yaml.safe_load(f) @@ -342,7 +343,7 @@ def test_generated_project_is_runnable() -> None: # 4. Run the generated project try: subprocess.run( - ["uv", "run", "python", "main.py", "config.yaml"], + ["uv", "run", "python", "main.py", "configs/config.yaml"], cwd=project_dir, check=True, timeout=300, @@ -486,6 +487,7 @@ def test_generated_project_grid_search_logic() -> None: assert "def load_grid_configs" in generated_utils assert "load_grid_configs" in generated_main + assert '"configs/config.yaml"' in generated_main def _recreation_command(project_dir: Path) -> str: @@ -547,9 +549,9 @@ def test_recreation_command_is_replayable(tmp_path): ) assert "Unrecognized options" not in result.stdout + result.stderr - assert (replay_dir / "config.yaml").exists() + assert (replay_dir / "configs/config.yaml").exists() - replayed_config = yaml.safe_load((replay_dir / "config.yaml").read_text()) + replayed_config = yaml.safe_load((replay_dir / "configs/config.yaml").read_text()) assert replayed_config["output"]["run_name"] == "my great run" assert replayed_config["output"]["root"] == "my outputs" @@ -600,10 +602,10 @@ def test_primary_model_drives_generated_config(tmp_path): ) init_project(config) - generated_config = yaml.safe_load((project_dir / "config.yaml").read_text()) + generated_config = yaml.safe_load((project_dir / "configs/config.yaml").read_text()) - # The primary model drives config.yaml and the run name even though it is - # not first in the selection. + # The primary model drives configs/config.yaml and the run name even though + # it is not first in the selection. assert "basic_transformer" in generated_config["model"]["_target_"] assert "basic_transformer" in generated_config["model"]["collate_fn_target"] assert generated_config["loss"]["_target_"] == "models.basic_transformer.CausalLMCrossEntropyLoss" diff --git a/trainite/cli/init.py b/trainite/cli/init.py index 0f3c7ea2..25531d48 100644 --- a/trainite/cli/init.py +++ b/trainite/cli/init.py @@ -33,6 +33,8 @@ PACKAGE_ROOT = Path(__file__).resolve().parents[1] PROJECT_ROOT = PACKAGE_ROOT.parent +DEFAULT_CONFIG_PATH = Path("configs/config.yaml") + MODEL_CHOICES = tuple(REGISTRY["models"].keys()) DATASET_CHOICES = tuple(REGISTRY["datasets"].keys()) TRAINER_CHOICES = tuple(REGISTRY["trainers"].keys()) @@ -337,10 +339,10 @@ def run_interactive_mode() -> None: primary_model = None if len(models) > 1: primary_model = _prompt_choice( - "Primary active model in config.yaml:", + "Primary active model in configs/config.yaml:", models, default=DEFAULT_MODEL if DEFAULT_MODEL in models else models[0], - instruction="Choose which model is configured as default active in config.yaml", + instruction="Choose which model is configured as default active in configs/config.yaml", ) dataset = _prompt_choice( "Dataset:", @@ -404,7 +406,7 @@ class Init(BaseModel): Args: project_dir: Directory to create the starter project in. model: Starter model template(s) to use. - primary_model: Model configured as active in config.yaml. Defaults to the first selected model. + primary_model: Model configured as active in configs/config.yaml. Defaults to the first selected model. dataset: Starter dataset template to use. trainer: Starter trainer template to use. output_root: Output root for generated config. @@ -489,7 +491,7 @@ def init_project(config: Init) -> None: sky=config.sky, ) - # Instantiate configs from specs (primary model is used for default config.yaml) + # Instantiate configs from specs (primary model is used for default configs/config.yaml) model_component = primary_model_spec.config_cls(collate_fn_target=primary_model_spec.collate_fn_target) data_config = dataset_spec.config_cls() trainer_component = trainer_spec.config_cls() @@ -511,10 +513,12 @@ def init_project(config: Init) -> None: # Update targets to point to the local project structure _update_targets(starter_config, rewrites) - dump_config(starter_config, resolved_project_dir / "config.yaml") + config_path = resolved_project_dir / DEFAULT_CONFIG_PATH + config_path.parent.mkdir(parents=True, exist_ok=True) + dump_config(starter_config, config_path) for filename, content in templates.items(): _write_file(resolved_project_dir / filename, content, force) - print("\n Generated config.yaml") + print(f"\n Generated {DEFAULT_CONFIG_PATH}") for filename in templates: print(f" Generated {filename}") diff --git a/trainite/cli/sky.py b/trainite/cli/sky.py index 5715b00d..fc9b095f 100644 --- a/trainite/cli/sky.py +++ b/trainite/cli/sky.py @@ -3,7 +3,7 @@ from pydantic import BaseModel import tomlkit import yaml -from trainite.cli.init import parse_dependencies, PROJECT_ROOT, PACKAGE_ROOT +from trainite.cli.init import DEFAULT_CONFIG_PATH, parse_dependencies, PROJECT_ROOT, PACKAGE_ROOT class SkyInit(BaseModel): @@ -54,7 +54,7 @@ def _add_sky_dependency(pyproject_path: Path) -> bool: def init_sky(config: SkyInit) -> None: current_dir = Path.cwd() - config_yaml_path = current_dir / "config.yaml" + config_yaml_path = current_dir / DEFAULT_CONFIG_PATH main_py_path = current_dir / "main.py" pyproject_path = current_dir / "pyproject.toml" @@ -62,7 +62,7 @@ def init_sky(config: SkyInit) -> None: if not (config_yaml_path.exists() and main_py_path.exists()): print( f"Error: '{current_dir.name}' is not a valid Trainite project directory " - "(missing config.yaml and main.py).\n" + f"(missing {DEFAULT_CONFIG_PATH} and main.py).\n" "Please navigate into your Trainite experiment directory before running 'trainite add:sky'.", file=sys.stderr, ) @@ -77,7 +77,7 @@ def init_sky(config: SkyInit) -> None: ) sys.exit(1) - # Extract project_name from config.yaml if available, else folder name + # Extract project_name from configs/config.yaml if available, else folder name project_name = current_dir.name try: data = yaml.safe_load(config_yaml_path.read_text()) or {} diff --git a/trainite/shared/main.py b/trainite/shared/main.py index c3195302..f391ccc1 100644 --- a/trainite/shared/main.py +++ b/trainite/shared/main.py @@ -7,7 +7,7 @@ def main() -> None: parser = argparse.ArgumentParser() - parser.add_argument("config", nargs="?", default="config.yaml") + parser.add_argument("config", nargs="?", default="configs/config.yaml") args = parser.parse_args() configs = load_grid_configs(Path(args.config), ProjectConfig) diff --git a/trainite/shared/utils.py b/trainite/shared/utils.py index e1c0618a..dd92e0c6 100644 --- a/trainite/shared/utils.py +++ b/trainite/shared/utils.py @@ -321,7 +321,7 @@ def build_dataloaders( ) -> tuple[DataLoader, DataLoader, DataLoader | None]: """Entry point for building train/val/test DataLoaders from a data config. - Supports two config strategies (set in ``config.yaml`` under ``data:``): + Supports two config strategies (set in ``configs/config.yaml`` under ``data:``): * **Explicit splits** (``DataConfigBase``): ``train``, ``val``, and optionally ``test`` are each configured independently with their own dataset and diff --git a/trainite/templates/components/datasets/hugging_face.md b/trainite/templates/components/datasets/hugging_face.md index efd6fbee..241b6ce2 100644 --- a/trainite/templates/components/datasets/hugging_face.md +++ b/trainite/templates/components/datasets/hugging_face.md @@ -5,7 +5,7 @@ enter the Trainite pipeline. Hugging Face manages the local cache; dataset files ## Configure the source -Edit `data.dataset` in `config.yaml`: +Edit `data.dataset` in `configs/config.yaml`: ```yaml data: @@ -40,5 +40,5 @@ so Trainite cannot infer a correct generic transform. ## Limits Streaming is unsupported because the current Trainite pipeline requires dataset length and random indexing for -splitting, shuffling, and inference samples. Never put a Hugging Face access token in `config.yaml`; authenticate through the +splitting, shuffling, and inference samples. Never put a Hugging Face access token in `configs/config.yaml`; authenticate through the Hugging Face CLI or environment because Trainite copies configs into run outputs. diff --git a/trainite/templates/components/datasets/python_edu.md b/trainite/templates/components/datasets/python_edu.md index f0ebeec9..547971a1 100644 --- a/trainite/templates/components/datasets/python_edu.md +++ b/trainite/templates/components/datasets/python_edu.md @@ -45,6 +45,6 @@ The transform creates: ## Hugging Face authentication -The dataset is loaded and cached by Hugging Face Datasets. Do not put Hugging Face access tokens directly in `config.yaml`. +The dataset is loaded and cached by Hugging Face Datasets. Do not put Hugging Face access tokens directly in `configs/config.yaml`. If authentication is required, authenticate through the Hugging Face CLI or the appropriate environment configuration. diff --git a/trainite/templates/components/datasets/ultrachat_200k.md b/trainite/templates/components/datasets/ultrachat_200k.md index f93d3215..dcfe95e8 100644 --- a/trainite/templates/components/datasets/ultrachat_200k.md +++ b/trainite/templates/components/datasets/ultrachat_200k.md @@ -51,4 +51,4 @@ The generation-ranking splits (`train_gen` and `test_gen`) are outside the scope ## Hugging Face authentication -The dataset is downloaded and cached by Hugging Face Datasets. Do not put Hugging Face access tokens in `config.yaml`. Authenticate through the Hugging Face CLI or the environment when required. +The dataset is downloaded and cached by Hugging Face Datasets. Do not put Hugging Face access tokens in `configs/config.yaml`. Authenticate through the Hugging Face CLI or the environment when required. diff --git a/trainite/templates/components/datasets/wikitext.md b/trainite/templates/components/datasets/wikitext.md index b99d5832..c2b4bb4d 100644 --- a/trainite/templates/components/datasets/wikitext.md +++ b/trainite/templates/components/datasets/wikitext.md @@ -66,4 +66,4 @@ splitting is performed. ## Hugging Face authentication The dataset is downloaded and cached by Hugging Face Datasets. Do not put Hugging Face access -tokens in `config.yaml`. Authenticate through the Hugging Face CLI or the environment when required. +tokens in `configs/config.yaml`. Authenticate through the Hugging Face CLI or the environment when required. diff --git a/trainite/templates/components/trainers/decoder_trainer.md b/trainite/templates/components/trainers/decoder_trainer.md index 25a321a4..af83aeec 100644 --- a/trainite/templates/components/trainers/decoder_trainer.md +++ b/trainite/templates/components/trainers/decoder_trainer.md @@ -108,12 +108,12 @@ Launch distributed training using `accelerate launch`: ```bash # Launch directly specifying the number of processes: -accelerate launch --num_processes=4 main.py config.yaml +accelerate launch --num_processes=4 main.py configs/config.yaml # Or configure your environment interactively once: accelerate config # And launch with saved settings: -accelerate launch main.py config.yaml +accelerate launch main.py configs/config.yaml ``` Accelerate automatically handles DDP wrapping, data partitioning (distributed samplers), and metric synchronization across all processes. Checkpoints and evaluation logs are automatically isolated to the main process (rank 0). @@ -131,7 +131,7 @@ If you are just getting started, the usual first changes are: - `log_every_steps` - `grad_clip_norm` - `early_stopping_patience` -- optimizer settings in `config.yaml` +- optimizer settings in `configs/config.yaml` ## If you want to customize behavior diff --git a/trainite/templates/integrations/sky.yaml b/trainite/templates/integrations/sky.yaml index 9c766c72..4c9e0e37 100644 --- a/trainite/templates/integrations/sky.yaml +++ b/trainite/templates/integrations/sky.yaml @@ -14,7 +14,7 @@ setup: | uv sync run: | - uv run python main.py config.yaml + uv run python main.py configs/config.yaml # envs: # # Optional environment variables (accessible in setup and run, or override via --env) diff --git a/trainite/templates/project/README.md b/trainite/templates/project/README.md index 4f1fe6a7..c42aa16c 100644 --- a/trainite/templates/project/README.md +++ b/trainite/templates/project/README.md @@ -11,8 +11,8 @@ Trainite is a toolbox for training language models with PyTorch-Ignite. This pro ## Project Structure -- `config.yaml`: The central configuration for your experiment. Edit this to change hyperparameters, dataset paths, or output settings. -- `main.py`: The entrypoint for training. Run it with `python main.py config.yaml`. +- `configs/config.yaml`: The central configuration for your experiment. Edit this to change hyperparameters, dataset paths, or output settings. +- `main.py`: The entrypoint for training. Run it with `python main.py configs/config.yaml`. - `models/`: Contains the model architecture definition. - `dataset_impl/`: Contains the selected dataset and transform implementations. - `trainer.py`: Defines the training and evaluation logic. You can override `_train_step` or `_eval_step` here. @@ -45,7 +45,7 @@ You can set up and run this project using either **uv** (recommended for speed) 3. **Run Training**: ```bash - uv run python main.py config.yaml + uv run python main.py configs/config.yaml ``` 4. **Monitor Progress**: @@ -77,7 +77,7 @@ If you prefer standard Python tools, you can create a virtual environment and us > [!NOTE] > `pip install -e .` only installs this project's dependencies — it does **not** > build the project into an installable Python package. This project is meant - > to be run from source via `python main.py config.yaml`. + > to be run from source via `python main.py configs/config.yaml`. > > To make it installable as a real package, restructure your code into a single > package — e.g., move `models/`, `dataset_impl/`, `preprocessors/` and the @@ -97,7 +97,7 @@ If you prefer standard Python tools, you can create a virtual environment and us 3. **Run Training**: ```bash - python main.py config.yaml + python main.py configs/config.yaml ``` 4. **Monitor Progress**: @@ -136,7 +136,7 @@ To launch this experiment on cloud GPUs (AWS, GCP, Azure, Lambda, etc.) using [S The default `logger: tensorboard` stores metrics and checkpoints locally. To use ClearML instead: 1. Run `clearml-init` to configure your ClearML server and credentials. -2. Set `logger: clearml` in `config.yaml`. +2. Set `logger: clearml` in `configs/config.yaml`. ClearML runs still keep checkpoints in the local output directory. By default, `ClearMLSaver` also uploads them to ClearML's file server with `output_uri=True`. @@ -166,7 +166,7 @@ To disable checkpoint uploads while retaining ClearML metric logging, pass `outp ## Understanding `utils.py` -`utils.py` contains the bootstrapping and setup logic that links your configurations to executable code. It primarily acts as the file where all the helper functions are located that are being used in `trainer.py`. It handles parsing of dynamic `_target_` paths from `config.yaml`, builds your models and datasets, manages dataset splitting, and attaches standard PyTorch-Ignite event handlers (such as checkpointing, early stopping, learning rate scheduling, and logging). +`utils.py` contains the bootstrapping and setup logic that links your configurations to executable code. It primarily acts as the file where all the helper functions are located that are being used in `trainer.py`. It handles parsing of dynamic `_target_` paths from `configs/config.yaml`, builds your models and datasets, manages dataset splitting, and attaches standard PyTorch-Ignite event handlers (such as checkpointing, early stopping, learning rate scheduling, and logging). Since the generated code in `utils.py` belongs to you, you can modify it directly to customize checkpoint rules, adjust early stopping metrics, or add new loggers. @@ -174,7 +174,7 @@ Since the generated code in `utils.py` belongs to you, you can modify it directl ### Dataset Configuration -You can configure your data in two ways in `config.yaml`: +You can configure your data in two ways in `configs/config.yaml`: #### Option 1: Explicit Splits Define exactly what goes into each split. Use this for established datasets with fixed splits. @@ -207,11 +207,11 @@ data: *Note: In Option 2, the training split defaults to `shuffle: true`, while others default to `shuffle: false`.* ### Adding Configuration Parameters -1. Add the parameter to `config.yaml`. +1. Add the parameter to `configs/config.yaml`. 2. (Optional) Update the corresponding Pydantic model in `config.py` if you want strict validation and IDE autocomplete for custom fields. ### Grid Search / Hyperparameter Sweeps -Trainite supports grid search through the optional sweep section in `config.yaml`. Specify the parameters to explore using the same nested structure as the main configuration, with a list of candidate values for each parameter. +Trainite supports grid search through the optional sweep section in `configs/config.yaml`. Specify the parameters to explore using the same nested structure as the main configuration, with a list of candidate values for each parameter. For example, to try three learning rates: ```yaml @@ -227,7 +227,7 @@ sweep: Trainite generates a training run for each combination of sweep parameter values. Parameters not specified in sweep retain their base configuration values. Run the sweep using the usual command: -`uv run python main.py config.yaml` +`uv run python main.py configs/config.yaml` ## Design Philosophy The code generated here is yours. There are no hidden abstractions or magic imports. Feel free to refactor or rewrite any part of it to suit your research needs. diff --git a/trainite/trainers/decoder_trainer.py b/trainite/trainers/decoder_trainer.py index f72a23d3..ef6a536a 100644 --- a/trainite/trainers/decoder_trainer.py +++ b/trainite/trainers/decoder_trainer.py @@ -77,7 +77,7 @@ class Trainer: Typical usage:: - config = load_config("config.yaml", ProjectConfig) + config = load_config("configs/config.yaml", ProjectConfig) trainer = Trainer(config) trainer.run()