Files
Davids048andClaude Opus 5.5 00a8e5bcb6 [refactor]: build resolved configs in the modular trainer
- moduleloader builds the component-loading config and the inference
  config as resolved configs (_build_training_resolved_config and
  build_inference_resolved_config) instead of TrainingArgs objects mutated
  after construction; the transformer override, weights path, and
  teacher/critic flag are config values or load_module arguments.
  keep_checkpoint_component_config keeps the trainer's PipelineConfig view
  of the checkpoint-filled VAE and text-encoder configs.
- The validation callback builds its pipeline with
  from_pretrained(path, resolved_config=...) and forwards with a resolved
  config built per run; it no longer replaces or mutates the trainer's
  pipeline_config, and generator_overrides takes nested GeneratorConfig
  fields instead of flat names.
- Against the 3f6893a0 snapshots of the 67 trainer YAML files, every
  PipelineConfig and value matches except ltx2_vae_tiling (the model's
  vae_tiling) and the unread pretrained_model_name_or_path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012M91wnVFmPEvJ9h39r5BH7
2026-10-03 06:19:13 +00:00

57 lines
2.0 KiB
Python

# SPDX-License-Identifier: Apache-2.0
"""Assembly: build method + dataloader from a ``_target_``-based config."""
from __future__ import annotations
from typing import Any, TYPE_CHECKING
from fastvideo.train.utils.instantiate import (
instantiate,
resolve_target,
)
from fastvideo.train.utils.config import RunConfig
if TYPE_CHECKING:
from fastvideo.train.utils.training_config import (
TrainingConfig, )
from fastvideo.train.methods.base import TrainingMethod
def build_from_config(cfg: RunConfig, ) -> tuple[TrainingConfig, TrainingMethod, Any, int]:
"""Build method + dataloader from a v3 run config.
1. Instantiate each model in ``cfg.models`` via ``_target_``.
2. Resolve the method class from ``cfg.method["_target_"]``
and construct it with ``(cfg=cfg, role_models=...)``.
3. Return ``(training_config, method, dataloader, start_step)``.
"""
from fastvideo.train.models.base import ModelBase
# --- 1. Build role model instances ---
role_models: dict[str, ModelBase] = {}
for role, model_cfg in cfg.models.items():
model = instantiate(model_cfg, training_config=cfg.training)
if not isinstance(model, ModelBase):
raise TypeError(f"models.{role}._target_ must resolve to a "
f"ModelBase subclass, got {type(model).__name__}")
role_models[role] = model
# --- 2. Build method ---
method_cfg = dict(cfg.method)
method_target = str(method_cfg.pop("_target_"))
method_cls = resolve_target(method_target)
# The student model provides the dataloader.
student = role_models.get("student")
method = method_cls(
cfg=cfg,
role_models=role_models,
)
# --- 3. Gather dataloader and start_step ---
dataloader = (getattr(student, "dataloader", None) if student is not None else None)
start_step = int(getattr(student, "start_step", 0) if student is not None else 0)
return cfg.training, method, dataloader, start_step