Skip to content

rome.train

Training algorithms available to ROME's training manager.

Adding one is a single task: subclass TrainTask, implement train(dataset, output_dir) -> checkpoint_path, and hand the instance to a TrainerConfig. The LLM/GRPO trainer here is imported lazily so a workflow that does not use it never pays for TRL.

The ProteinMPNN trainer is not here: it is an IMPRESS-R integration, not framework core, so it ships with that example — examples/impress_r/mpnn.py (from examples.impress_r.mpnn import ProteinMPNNTrainer, ProteinMPNNConfig).

FunctionTrainer

FunctionTrainer(func, *, gpus: int = 1, nodes: int = 1, name: Optional[str] = None, wants_hf_dataset: bool = False)

Bases: TrainTask

Adapter that turns a bare function into a TrainTask.

The cheapest possible way to plug an existing training script into ROME::

rome = Manager(trainer=FunctionTrainer(my_finetune, gpus=4))

where my_finetune(dataset, output_dir, **kwargs) -> checkpoint_path.

Source code in rome/train/base.py
def __init__(self, func, *, gpus: int = 1, nodes: int = 1, name: Optional[str] = None,
             wants_hf_dataset: bool = False):
    super().__init__(gpus=gpus, nodes=nodes, name=name or getattr(func, "__name__", "function"))
    self._func = func
    self.wants_hf_dataset = wants_hf_dataset

as_command

as_command(dataset: Any, output_dir: str, **kwargs: Any) -> Optional[Tuple[str, str]]

Optionally run this round as an executable task instead of a function.

Return (shell_command, checkpoint_path) to have the training manager submit shell_command as an executable task — a subprocess on the allocation's resources, the way IMPRESS submits its wrapper scripts — rather than pickling train into a worker. checkpoint_path is where the command will write the checkpoint, since an executable task's return value is not the path.

Return None (the default) to run train in-process as a function task. A GPU fine-tune should prefer the command form: the subprocess exits when the round ends, releasing its VRAM.

Completion contract: the command MUST write a file named train_complete (rome.trainer.TRAIN_COMPLETE_MARKER) into its output_dir as its final action, after the checkpoint is safely on disk. The training manager polls for that marker to detect the round finished, because on Dragon a task can run to completion and never resolve its future (a running service blocks result delivery — see docs/dragon.md). The marker, not the checkpoint, is the signal: with publish-in-place the checkpoint path already exists from the prior round.

Source code in rome/train/base.py
def as_command(self, dataset: Any, output_dir: str,
               **kwargs: Any) -> Optional[Tuple[str, str]]:
    """Optionally run this round as an executable task instead of a function.

    Return ``(shell_command, checkpoint_path)`` to have the training manager
    submit ``shell_command`` as an *executable* task — a subprocess on the
    allocation's resources, the way IMPRESS submits its wrapper scripts —
    rather than pickling :meth:`train` into a worker. ``checkpoint_path`` is
    where the command will write the checkpoint, since an executable task's
    return value is not the path.

    Return ``None`` (the default) to run :meth:`train` in-process as a
    function task. A GPU fine-tune should prefer the command form: the
    subprocess exits when the round ends, releasing its VRAM.

    Completion contract: the command MUST write a file named
    ``train_complete`` (``rome.trainer.TRAIN_COMPLETE_MARKER``) into its
    ``output_dir`` as its *final* action, after the checkpoint is safely on
    disk. The training manager polls for that marker to detect the round
    finished, because on Dragon a task can run to completion and never
    resolve its future (a running service blocks result delivery — see
    ``docs/dragon.md``). The marker, not the checkpoint, is the signal: with
    publish-in-place the checkpoint path already exists from the prior round.
    """
    return None

validate

validate(dataset: Any) -> None

Raise if dataset cannot be trained on.

Called by the training manager before a task is scheduled, so an unusable corpus fails fast on the manager instead of burning an HPC allocation. The default check is just "not empty".

Source code in rome/train/base.py
def validate(self, dataset: Any) -> None:
    """Raise if ``dataset`` cannot be trained on.

    Called by the training manager *before* a task is scheduled, so an
    unusable corpus fails fast on the manager instead of burning an HPC
    allocation. The default check is just "not empty".
    """
    try:
        size = len(dataset)
    except TypeError:
        return
    if size == 0:
        raise ValueError(f"{self.name}: refusing to train on an empty dataset")

prepare_output_dir staticmethod

prepare_output_dir(base_dir: str, version: int, name: str) -> str

Standard checkpoint layout: <base_dir>/<name>/v<version>.

Source code in rome/train/base.py
@staticmethod
def prepare_output_dir(base_dir: str, version: int, name: str) -> str:
    """Standard checkpoint layout: ``<base_dir>/<name>/v<version>``."""
    path = os.path.join(base_dir, name, f"v{version}")
    os.makedirs(path, exist_ok=True)
    return path

TrainTask

TrainTask(*, gpus: int = 1, nodes: int = 1, name: Optional[str] = None)

Abstract base for ROME training algorithms.

Subclasses implement train. Everything else — when to run, where the data comes from, who hears about the new checkpoint — belongs to the training manager.

Parameters:

  • gpus (int, default: 1 ) –

    GPUs a single training task needs. The training manager forwards this to the workflow engine when submitting the task.

  • nodes (int, default: 1 ) –

    Nodes a single training task needs.

  • name (str, default: None ) –

    Human-readable label used in status reporting and checkpoint paths. Defaults to the class name.

Source code in rome/train/base.py
def __init__(self, *, gpus: int = 1, nodes: int = 1, name: Optional[str] = None):
    self.gpus = gpus
    self.nodes = nodes
    self.name = name or type(self).__name__

wants_hf_dataset class-attribute instance-attribute

wants_hf_dataset: bool = False

Set on subclasses that want a datasets.Dataset rather than a list.

train

train(dataset: Any, output_dir: str, **kwargs: Any) -> str

Train on dataset and write a checkpoint under output_dir.

Parameters:

  • dataset (Any) –

    Whatever rome.data.DataManager.get_dataset produced — a list of record dicts by default, or a datasets.Dataset when the trainer asked for one via wants_hf_dataset.

  • output_dir (str) –

    Directory the checkpoint should be written to. Already created.

  • **kwargs (Any, default: {} ) –

    Forwarded from rome.trainer.Trainer.train; implementations should tolerate unknown keys.

Returns:

  • str –

    Path to the checkpoint the stream manager should load. Returning output_dir itself is the common case.

Source code in rome/train/base.py
def train(self, dataset: Any, output_dir: str, **kwargs: Any) -> str:
    """Train on ``dataset`` and write a checkpoint under ``output_dir``.

    Parameters
    ----------
    dataset : Any
        Whatever :meth:`rome.data.DataManager.get_dataset` produced — a
        list of record dicts by default, or a ``datasets.Dataset`` when the
        trainer asked for one via :attr:`wants_hf_dataset`.
    output_dir : str
        Directory the checkpoint should be written to. Already created.
    **kwargs
        Forwarded from :meth:`rome.trainer.Trainer.train`; implementations
        should tolerate unknown keys.

    Returns
    -------
    str
        Path to the checkpoint the stream manager should load. Returning
        ``output_dir`` itself is the common case.
    """
    raise NotImplementedError("TrainTask.train() must be implemented by subclasses")

as_command

as_command(dataset: Any, output_dir: str, **kwargs: Any) -> Optional[Tuple[str, str]]

Optionally run this round as an executable task instead of a function.

Return (shell_command, checkpoint_path) to have the training manager submit shell_command as an executable task — a subprocess on the allocation's resources, the way IMPRESS submits its wrapper scripts — rather than pickling train into a worker. checkpoint_path is where the command will write the checkpoint, since an executable task's return value is not the path.

Return None (the default) to run train in-process as a function task. A GPU fine-tune should prefer the command form: the subprocess exits when the round ends, releasing its VRAM.

Completion contract: the command MUST write a file named train_complete (rome.trainer.TRAIN_COMPLETE_MARKER) into its output_dir as its final action, after the checkpoint is safely on disk. The training manager polls for that marker to detect the round finished, because on Dragon a task can run to completion and never resolve its future (a running service blocks result delivery — see docs/dragon.md). The marker, not the checkpoint, is the signal: with publish-in-place the checkpoint path already exists from the prior round.

Source code in rome/train/base.py
def as_command(self, dataset: Any, output_dir: str,
               **kwargs: Any) -> Optional[Tuple[str, str]]:
    """Optionally run this round as an executable task instead of a function.

    Return ``(shell_command, checkpoint_path)`` to have the training manager
    submit ``shell_command`` as an *executable* task — a subprocess on the
    allocation's resources, the way IMPRESS submits its wrapper scripts —
    rather than pickling :meth:`train` into a worker. ``checkpoint_path`` is
    where the command will write the checkpoint, since an executable task's
    return value is not the path.

    Return ``None`` (the default) to run :meth:`train` in-process as a
    function task. A GPU fine-tune should prefer the command form: the
    subprocess exits when the round ends, releasing its VRAM.

    Completion contract: the command MUST write a file named
    ``train_complete`` (``rome.trainer.TRAIN_COMPLETE_MARKER``) into its
    ``output_dir`` as its *final* action, after the checkpoint is safely on
    disk. The training manager polls for that marker to detect the round
    finished, because on Dragon a task can run to completion and never
    resolve its future (a running service blocks result delivery — see
    ``docs/dragon.md``). The marker, not the checkpoint, is the signal: with
    publish-in-place the checkpoint path already exists from the prior round.
    """
    return None

validate

validate(dataset: Any) -> None

Raise if dataset cannot be trained on.

Called by the training manager before a task is scheduled, so an unusable corpus fails fast on the manager instead of burning an HPC allocation. The default check is just "not empty".

Source code in rome/train/base.py
def validate(self, dataset: Any) -> None:
    """Raise if ``dataset`` cannot be trained on.

    Called by the training manager *before* a task is scheduled, so an
    unusable corpus fails fast on the manager instead of burning an HPC
    allocation. The default check is just "not empty".
    """
    try:
        size = len(dataset)
    except TypeError:
        return
    if size == 0:
        raise ValueError(f"{self.name}: refusing to train on an empty dataset")

prepare_output_dir staticmethod

prepare_output_dir(base_dir: str, version: int, name: str) -> str

Standard checkpoint layout: <base_dir>/<name>/v<version>.

Source code in rome/train/base.py
@staticmethod
def prepare_output_dir(base_dir: str, version: int, name: str) -> str:
    """Standard checkpoint layout: ``<base_dir>/<name>/v<version>``."""
    path = os.path.join(base_dir, name, f"v{version}")
    os.makedirs(path, exist_ok=True)
    return path