Skip to content

rome.dummy

Dummy components for exercising ROME without a model.

Everything here has the same shape as a real ROME trainer or stream function and none of the cost: the trainer sleeps instead of fine-tuning, and the model emits a placeholder string instead of generating. That makes them useful for

  • smoke-testing a new execution backend or allocation, where the question is whether tasks are placed and whether the DDict is reachable, not whether the model learns;
  • demonstrating the closed loop end to end in seconds (see examples/agnostic/dummy_loop.py);
  • standing in for one half of a real campaign while the other half is built.

The dummy checkpoint is a real file on disk holding the round's version, so a stream that reloads it genuinely observes the new version rather than being told about it. A run therefore fails in the same places a real one would --- an unwritable checkpoint directory, a DDict that is not shared, a stream that never sees a publication.

Both the trainer and the inference function block on time.sleep. That is correct rather than sloppy: ROME runs a synchronous trainer inside an asyncflow task and a synchronous process_func in a worker thread, so neither sleep stalls the event loop the other streams are sharing.

DEFAULT_TEMPLATE module-attribute

DEFAULT_TEMPLATE = 'model example output [{uuid}]'

What a dummy model "generates".

{uuid} is a fresh UUID per output; {version} and {index} are available for callers who want the model version or the position in the batch visible in the text itself.

CHECKPOINT_FILE module-attribute

CHECKPOINT_FILE = 'checkpoint.json'

Filename the dummy trainer writes and the dummy model reads back.

DummyTrainer

DummyTrainer(*, train_seconds: float = 2.0, gpus: int = 1, nodes: int = 1, name: Optional[str] = None, fail_every: Optional[int] = None)

Bases: TrainTask

A training task that pretends to train.

Sleeps for train_seconds to stand in for compute, then writes a checkpoint recording what the round would have learned from. The sleep is the point: it makes a round take long enough that the surrounding machinery --- the RUNNING status, streams continuing to serve while a round is in flight, a stop request waiting for the round rather than cancelling it --- is actually observable.

Parameters:

  • train_seconds (float, default: 2.0 ) –

    How long a round pretends to take.

  • gpus (int, default: 1 ) –

    Resources declared to the workflow engine, exactly as a real trainer would. Nothing uses them, but a backend smoke test wants them requested.

  • nodes (int, default: 1 ) –

    Resources declared to the workflow engine, exactly as a real trainer would. Nothing uses them, but a backend smoke test wants them requested.

  • name (str, default: None ) –

    Checkpoint directories are named after this. Defaults to "dummy".

  • fail_every (Optional[int], default: None ) –

    Raise on every n-th round. Used to exercise the training manager's failure handling; None (default) never fails.

Source code in rome/dummy.py
def __init__(
    self,
    *,
    train_seconds: float = 2.0,
    gpus: int = 1,
    nodes: int = 1,
    name: Optional[str] = None,
    fail_every: Optional[int] = None,
):
    super().__init__(gpus=gpus, nodes=nodes, name=name or "dummy")
    self.train_seconds = train_seconds
    self.fail_every = fail_every
    self.rounds: List[Dict[str, Any]] = []
    """One entry per completed round: what it trained on and for how long."""

rounds instance-attribute

rounds: List[Dict[str, Any]] = []

One entry per completed round: what it trained on and for how long.

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, output_dir: str, **kwargs: Any) -> str

Pretend to train on dataset; return the checkpoint directory.

Source code in rome/dummy.py
def train(self, dataset, output_dir: str, **kwargs: Any) -> str:
    """Pretend to train on ``dataset``; return the checkpoint directory."""
    version = int(kwargs.get("model_version", len(self.rounds) + 1))
    samples = len(dataset)

    if self.fail_every and version % self.fail_every == 0:
        raise RuntimeError(
            f"{self.name}: simulated training failure on round {version}"
        )

    started = time.time()
    time.sleep(self.train_seconds)      # stand-in for the actual fine-tune
    elapsed = time.time() - started

    write_dummy_checkpoint(output_dir, version=version, samples=samples)
    self.rounds.append({
        "version": version,
        "samples": samples,
        "seconds": elapsed,
        "checkpoint": output_dir,
    })
    return output_dir

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

DummyModel

DummyModel(checkpoint_path: Optional[str] = None, template: str = DEFAULT_TEMPLATE, latency: float = 0.0)

A model that generates a placeholder string.

Reports the version it was loaded from, read out of the checkpoint file rather than passed in, so that a reload is observable from the output alone.

Parameters:

  • checkpoint_path (Optional[str], default: None ) –

    Where it was loaded from. None means untrained (version 0).

  • template (str, default: DEFAULT_TEMPLATE ) –

    Output format. {uuid} is substituted with a fresh UUID per call; {version} and {index} are also available.

  • latency (float, default: 0.0 ) –

    Seconds one generation pretends to take.

Source code in rome/dummy.py
def __init__(
    self,
    checkpoint_path: Optional[str] = None,
    template: str = DEFAULT_TEMPLATE,
    latency: float = 0.0,
):
    self.checkpoint_path = checkpoint_path
    self.template = template
    self.latency = latency
    metadata = read_dummy_checkpoint(checkpoint_path)
    self.version = int(metadata.get("version", 0))
    self.trained_on = int(metadata.get("samples", 0))

generate

generate(prompt: Any = None, index: int = 0) -> str

Produce one placeholder output.

Source code in rome/dummy.py
def generate(self, prompt: Any = None, index: int = 0) -> str:
    """Produce one placeholder output."""
    if self.latency:
        time.sleep(self.latency)
    return self.template.format(
        uuid=uuid.uuid4(), version=self.version, index=index, prompt=prompt
    )

write_dummy_checkpoint

write_dummy_checkpoint(output_dir: str, version: int, samples: int) -> str

Write the placeholder checkpoint a dummy round produces.

Source code in rome/dummy.py
def write_dummy_checkpoint(output_dir: str, version: int, samples: int) -> str:
    """Write the placeholder checkpoint a dummy round produces."""
    os.makedirs(output_dir, exist_ok=True)
    path = os.path.join(output_dir, CHECKPOINT_FILE)
    with open(path, "w") as fd:
        json.dump(
            {"version": version, "samples": samples, "trained_at": time.time()},
            fd,
            indent=2,
        )
    return path

read_dummy_checkpoint

read_dummy_checkpoint(checkpoint_path: Optional[str]) -> Dict[str, Any]

Read a dummy checkpoint, tolerating one that was never written.

A stream starts before the first training round completes, so "no checkpoint yet" is the normal initial state, not an error: it reports version 0, which is what the untrained model is.

Source code in rome/dummy.py
def read_dummy_checkpoint(checkpoint_path: Optional[str]) -> Dict[str, Any]:
    """Read a dummy checkpoint, tolerating one that was never written.

    A stream starts before the first training round completes, so "no
    checkpoint yet" is the normal initial state, not an error: it reports
    version 0, which is what the untrained model is.
    """
    if not checkpoint_path:
        return {"version": 0, "samples": 0}
    path = checkpoint_path
    if os.path.isdir(path):
        path = os.path.join(path, CHECKPOINT_FILE)
    try:
        with open(path) as fd:
            return json.load(fd)
    except (OSError, ValueError):
        return {"version": 0, "samples": 0}

dummy_load

dummy_load(checkpoint_path: Optional[str], ctx: Any = None, template: str = DEFAULT_TEMPLATE, latency: float = 0.0) -> DummyModel

load_func for a dummy inference stream.

Called once at startup and again every time the training manager publishes a checkpoint. Pass template and latency through StreamConfig.load_kwargs.

Source code in rome/dummy.py
def dummy_load(
    checkpoint_path: Optional[str],
    ctx: Any = None,
    template: str = DEFAULT_TEMPLATE,
    latency: float = 0.0,
) -> DummyModel:
    """``load_func`` for a dummy inference stream.

    Called once at startup and again every time the training manager publishes
    a checkpoint. Pass ``template`` and ``latency`` through
    ``StreamConfig.load_kwargs``.
    """
    return DummyModel(checkpoint_path, template=template, latency=latency)

dummy_infer

dummy_infer(prompts: List[Any], ctx: Any) -> List[str]

process_func for a dummy inference stream.

Returns one placeholder output per prompt, generated by whichever model version the stream currently holds.

Source code in rome/dummy.py
def dummy_infer(prompts: List[Any], ctx: Any) -> List[str]:
    """``process_func`` for a dummy inference stream.

    Returns one placeholder output per prompt, generated by whichever model
    version the stream currently holds.
    """
    model = ctx.model
    if model is None:
        # No checkpoint had been published when this replica started, so
        # load_func never ran. An untrained dummy is the right stand-in.
        model = DummyModel()
    return model.generate_batch(prompts)

dummy_reward

dummy_reward(outputs: List[Any], score: float = 1.0) -> List[Dict[str, Any]]

process_func for a dummy reward stream.

Emits a corpus-shaped record per output, so a manager with this stream configured accumulates training data with no scoring code at all. Real reward functions vary the score; this one is deliberately constant, so a run's behaviour depends only on the plumbing under test.

Source code in rome/dummy.py
def dummy_reward(outputs: List[Any], score: float = 1.0) -> List[Dict[str, Any]]:
    """``process_func`` for a dummy reward stream.

    Emits a corpus-shaped record per output, so a manager with this stream
    configured accumulates training data with no scoring code at all. Real
    reward functions vary the score; this one is deliberately constant, so a
    run's behaviour depends only on the plumbing under test.
    """
    return [{"completion": output, "score": score} for output in outputs]