Skip to content

rome.manager

ROME Manager — the single object a host workflow talks to.

ROME adds model improvement to a workflow that already exists. The manager is the seam: it owns the three components from the design deck and wires them to each other so the workflow only ever sees a handful of API calls.

Data Manager    gathers scored outputs -> training dataset
Training Manager schedules training tasks -> publishes checkpoints
Stream Manager  runs inference/reward streams -> hot-swaps checkpoints

The wiring that closes the loop is one line in Manager.start: the training manager's checkpoint callback is the stream manager's reload hook, so a finished training round is the event that swaps the streams onto the new model. Nothing in the host workflow has to orchestrate that.

Typical adoption::

rome = Manager(asyncflow=flow, data_config=DataConfig(min_samples=64),
               trainer_config=TrainerConfig(trainer=my_trainer))
await rome.start()

...                                   # the workflow runs unchanged
rome.add_training_data(sequence=seq, score=plddt)   # from anywhere
if rome.get_current_model():                        # improved weights
    mpnn.load(rome.get_current_model())

await rome.stop()

ROME_NS module-attribute

ROME_NS = 'rome'

Prefix isolating ROME's keys.

A DDict shared with the host workflow therefore never collides with the workflow's own state.

DEFAULT_DDICT_KWARGS module-attribute

DEFAULT_DDICT_KWARGS: Dict[str, Any] = {'managers_per_node': 1, 'n_nodes': 1, 'total_mem': 1024 ** 3}

Defaults for a DDict ROME allocates itself.

Dragon's own default total_mem is 3 MiB; a campaign corpus of a few thousand records plus the stream queues goes past that, and the failure mode is an allocation error deep in a manager rather than anything ROME can explain, so ask for room.

Manager

Manager(asyncflow: Optional[WorkflowEngine] = None, *, backend: Any = None, data_config: Optional[DataConfig] = None, trainer_config: Optional[TrainerConfig] = None, stream_configs: Optional[List[StreamConfig]] = None, ddict: Optional[DDict] = None, ddict_kwargs: Optional[Dict[str, Any]] = None, auto_reload_streams: bool = True)

Manager class for handling tasks and data in the ROME framework.

Parameters:

  • asyncflow (WorkflowEngine, default: None ) –

    The engine ROME submits its tasks to. Pass the host workflow's — for an IMPRESS campaign that is impress_manager.flow, available once the manager has started — and ROME's rounds and streams are scheduled against the same allocation as the campaign's own tasks.

    Leave it None and ROME builds its own engine at start and shuts it down at stop. That is the right choice when ROME should manage its own tasks independently of the host, or when the host creates its engine internally and does not hand one out.

  • backend (optional, default: None ) –

    Execution backend for the engine ROME builds for itself. Ignored when asyncflow is given. When both are omitted, asyncflow falls back to a local, in-process backend — fine for tests and CPU work, but wrong for a GPU fine-tune: a training round then runs inside this driver process, so the model's CUDA context stays resident for the whole campaign instead of being freed when the round ends. Pass a process-based backend (DragonExecutionBackendV3 on Delta, or a ConcurrentExecutionBackend(ProcessPoolExecutor())) so each round runs in a task process that releases its VRAM on exit. See examples/impress_r/run_protein_binding_rome.py.

  • data_config (DataConfig, default: None ) –

    How scored outputs become a dataset, and how much data a training round needs.

  • trainer_config (TrainerConfig, default: None ) –

    Which training algorithm to run and when. Required before training can start; may also be passed to start.

  • stream_configs (list[StreamConfig], default: None ) –

    Inference and reward streams to bring up at start. Streams can equally be started later via manager.stream.start(...), or omitted entirely by workflows that only want the data + training halves.

  • ddict (DDict, default: None ) –

    Share the host workflow's dictionary instead of allocating one. ROME namespaces all of its keys, so sharing is safe, and passing the DDict object into a task is all it takes to reach it from another node — Dragon attaches the receiving process automatically.

  • ddict_kwargs (dict, default: None ) –

    Passed to DDict(...) when ROME allocates its own. Worth setting on a real campaign: Dragon's default total_mem is 3 MiB, which a corpus of a few thousand records will exhaust, so ROME asks for DEFAULT_DDICT_KWARGS instead.

  • auto_reload_streams (bool, default: True ) –

    Wire published checkpoints to stream reloads (default). Turn off if the workflow would rather decide when inference switches models.

Source code in rome/manager.py
def __init__(
    self,
    asyncflow: Optional[WorkflowEngine] = None,
    *,
    backend: Any = None,
    data_config: Optional[DataConfig] = None,
    trainer_config: Optional[TrainerConfig] = None,
    stream_configs: Optional[List[StreamConfig]] = None,
    ddict: Optional[DDict] = None,
    ddict_kwargs: Optional[Dict[str, Any]] = None,
    auto_reload_streams: bool = True,
):
    self.asyncflow = asyncflow
    self.backend = backend
    #: True when ROME built the engine and is therefore responsible for
    #: shutting it down. An engine handed in belongs to the host workflow.
    self._owns_asyncflow = False
    if ddict is not None:
        self.manager_ddict = ddict
    else:
        self.manager_ddict = DDict(**{**DEFAULT_DDICT_KWARGS, **(ddict_kwargs or {})})
    self.ns = Namespace(self.manager_ddict, f"{ROME_NS}|")
    self.stop_event = Event()
    self.auto_reload_streams = auto_reload_streams
    self._stream_configs = list(stream_configs or [])
    self._started = False

    self.data = DataManager(self.ns, data_config)
    self.trainer = Trainer(self.ns, self.data, asyncflow, trainer_config)
    self.stream = Stream(self.ns, asyncflow)

model_version property

model_version: int

Version of the newest published checkpoint (0 = never trained).

start async

start(trainer_config: Optional[TrainerConfig] = None, stream_configs: Optional[List[StreamConfig]] = None) -> 'Manager'

Start the ROME manager: bring up the streams, then the trainer.

Order matters. Streams come up first so they are already draining requests by the time the first checkpoint lands, and the checkpoint hook is registered before the trainer can fire a round — otherwise a very fast first round could publish weights nobody is listening for.

Source code in rome/manager.py
async def start(
    self,
    trainer_config: Optional[TrainerConfig] = None,
    stream_configs: Optional[List[StreamConfig]] = None,
) -> "Manager":
    """Start the ROME manager: bring up the streams, then the trainer.

    Order matters. Streams come up first so they are already draining
    requests by the time the first checkpoint lands, and the checkpoint hook
    is registered before the trainer can fire a round — otherwise a very
    fast first round could publish weights nobody is listening for.
    """
    if trainer_config is not None:
        self.trainer.config = trainer_config
    if stream_configs is not None:
        self._stream_configs = list(stream_configs)

    await self._ensure_asyncflow()
    self.stop_event.clear()

    if self.auto_reload_streams:
        self.trainer.on_checkpoint(self.stream.on_checkpoint)

    for config in self._stream_configs:
        if config.kind is StreamKind.REWARD and config.on_output is None:
            # A reward stream's whole point is to score things for training,
            # so its results go straight into the corpus unless the workflow
            # has said otherwise.
            config.on_output = self._reward_output_to_corpus
        await self.stream.start(config)

    if self.trainer.config.trainer is not None:
        await self.trainer.start()

    self._started = True
    log.info("started — %d stream group%s, min_samples=%d, trainer %s",
             len(self._stream_configs),
             "" if len(self._stream_configs) == 1 else "s",
             self.data.config.min_samples,
             type(self.trainer.config.trainer).__name__
             if self.trainer.config.trainer is not None else "none")
    return self

stop async

stop(wait: bool = True, timeout: float = 300.0) -> None

Stop the ROME manager.

Trainer first: an in-flight round is waited out rather than cancelled, and letting the streams keep serving while it finishes means the final checkpoint still reaches them.

Source code in rome/manager.py
async def stop(self, wait: bool = True, timeout: float = 300.0) -> None:
    """Stop the ROME manager.

    Trainer first: an in-flight round is waited out rather than cancelled,
    and letting the streams keep serving while it finishes means the final
    checkpoint still reaches them.
    """
    self.stop_event.set()
    log.info("stopping — corpus %d, %d round%s completed, model v%d",
             self.data.total_count, self.trainer.rounds_completed,
             "" if self.trainer.rounds_completed == 1 else "s",
             self.model_version)
    await self.trainer.stop(wait_for_stop=wait, timeout=timeout)
    await self.stream.stop(wait_for_stop=wait, timeout=timeout)
    # Each stream group owns a dictionary; the manager's teardown is where
    # they are released, after the streams have finished draining.
    self.stream.close()
    if self._owns_asyncflow and self.asyncflow is not None:
        # Only an engine ROME built is ROME's to shut down; the host
        # workflow's is still running its own tasks.
        await self.asyncflow.shutdown()
        self.asyncflow = None
        self._owns_asyncflow = False
    self._started = False

add_training_data

add_training_data(prompt: Any = None, completion: Any = None, score: Optional[float] = None, **fields: Any) -> Optional[str]

Add training data to the manager, from anywhere in the workflow.

The prompt/completion/score triple is the LLM-shaped convenience form; any other domain passes keywords instead::

rome.add_training_data(sequence=seq, pdb_path=pdb, score=plddt)

Returns the record uid, or None when the data manager's filters rejected the sample.

Source code in rome/manager.py
def add_training_data(self, prompt: Any = None, completion: Any = None,
                      score: Optional[float] = None, **fields: Any) -> Optional[str]:
    """Add training data to the manager, from anywhere in the workflow.

    The ``prompt``/``completion``/``score`` triple is the LLM-shaped
    convenience form; any other domain passes keywords instead::

        rome.add_training_data(sequence=seq, pdb_path=pdb, score=plddt)

    Returns the record uid, or ``None`` when the data manager's filters
    rejected the sample.
    """
    if prompt is not None:
        fields["prompt"] = prompt
    if completion is not None:
        fields["completion"] = completion
    return self.data.add(score=score, **fields)

add_training_batch

add_training_batch(records: List[Dict[str, Any]]) -> List[str]

Add many scored outputs at once; returns the accepted uids.

Source code in rome/manager.py
def add_training_batch(self, records: List[Dict[str, Any]]) -> List[str]:
    """Add many scored outputs at once; returns the accepted uids."""
    return self.data.add_batch(records)

get_training_dataset

get_training_dataset(as_hf_dataset: bool = False) -> Any

The dataset the next training round would train on.

Source code in rome/manager.py
def get_training_dataset(self, as_hf_dataset: bool = False) -> Any:
    """The dataset the next training round would train on."""
    return self.data.get_dataset(as_hf_dataset=as_hf_dataset)

start_training async

start_training(force: bool = True, **kwargs: Any) -> Optional[str]

Trigger a training round by hand; returns the new checkpoint path.

Source code in rome/manager.py
async def start_training(self, force: bool = True, **kwargs: Any) -> Optional[str]:
    """Trigger a training round by hand; returns the new checkpoint path."""
    return await self.trainer.train(force=force, **kwargs)

get_training_status

get_training_status() -> TrainerStatus

Get the status of the training tasks.

Source code in rome/manager.py
def get_training_status(self) -> TrainerStatus:
    """Get the status of the training tasks."""
    return self.trainer.status

get_current_model

get_current_model() -> Optional[str]

Path to the newest published checkpoint, or None before round 1.

Source code in rome/manager.py
def get_current_model(self) -> Optional[str]:
    """Path to the newest published checkpoint, or ``None`` before round 1."""
    return self.trainer.get_current_model()

ready_to_train

ready_to_train() -> bool

Whether enough fresh data has accumulated for a round.

Source code in rome/manager.py
def ready_to_train(self) -> bool:
    """Whether enough fresh data has accumulated for a round."""
    return self.data.ready_to_train()

submit

submit(payload: Any, stream: Optional[str] = None) -> str

Queue one inference or scoring request; returns its request id.

Source code in rome/manager.py
def submit(self, payload: Any, stream: Optional[str] = None) -> str:
    """Queue one inference or scoring request; returns its request id."""
    return self.stream.submit(payload, stream=stream)

get_outputs

get_outputs(stream: Optional[str] = None, consume: bool = True) -> List[Dict[str, Any]]

Collect finished stream results.

Source code in rome/manager.py
def get_outputs(self, stream: Optional[str] = None,
                consume: bool = True) -> List[Dict[str, Any]]:
    """Collect finished stream results."""
    return self.stream.get_outputs(stream=stream, consume=consume)

reload_model async

reload_model(model_path: Optional[str] = None, wait_for_reload: bool = True) -> None

Push a checkpoint into the running streams.

Source code in rome/manager.py
async def reload_model(self, model_path: Optional[str] = None,
                       wait_for_reload: bool = True) -> None:
    """Push a checkpoint into the running streams."""
    await self.stream.reload_model(model_path, wait_for_reload=wait_for_reload)

get_stream_status

get_stream_status(stream: Optional[str] = None) -> List[StreamStatus]

Status of the running stream tasks.

Source code in rome/manager.py
def get_stream_status(self, stream: Optional[str] = None) -> List[StreamStatus]:
    """Status of the running stream tasks."""
    return self.stream.get_status(stream=stream)

report

report() -> Dict[str, Any]

One-call snapshot of all three components.

Source code in rome/manager.py
def report(self) -> Dict[str, Any]:
    """One-call snapshot of all three components."""
    return {
        "started": self._started,
        "data": {
            "total": self.data.total_count,
            "unconsumed": self.data.unconsumed_count,
            "ready_to_train": self.data.ready_to_train(),
        },
        "training": self.trainer.report(),
        "streams": self.stream.report(),
        "model_path": self.ns.get(MODEL_PATH_KEY),
    }