rome.train.llm¶
LLM trainer tasks: GRPO (reinforcement) and SFT (supervised).
The trainer shipped with the framework (the ProteinMPNN trainer lives with the
IMPRESS-R example, examples/impress_r/mpnn.py). It is the demonstration that
"adding new models and training algorithms requires just one task": everything
below this line is TRL-specific, and nothing above it — the data manager, the
training manager, the stream manager — knows that an LLM is involved.
The task takes the dataset the data manager built, runs TRL's GRPO over it, and writes a checkpoint (a LoRA adapter when one is configured, otherwise the full model). The training manager publishes that path and the inference streams hot-swap onto it.
ModelConfig
dataclass
¶
ModelConfig(base_model_name: Optional[str] = None, model_name: Optional[str] = None, lora_name: Optional[str] = None, lora_config: Optional['LoraConfig'] = None, generation_config: Optional['GenerationConfig'] = None, dtype: Optional[str] = 'auto', required_gpus: int = 1, device_map: Any = 'auto', max_seq_length: int = 2048)
Model configurations used for loading the model and tokenizer, as well as generation.
Parameters:
-
base_model_name(Optional[str], default:None) –Foundation model name, used to load tokenizer and model weights (when model_name is not provided). Should be a model name recognized by HuggingFace's AutoModelForCausalLM and AutoTokenizer classes.
-
model_name(Optional[str], default:None) –Full model name, used to load model weights. If no model_name is provided, base_model_name is used.
-
lora_name(Optional[str], default:None) –LoRA adapter name, used to load LoRA adapter weights. If no lora_name is provided, the full model is trained and saved.
-
lora_config(Optional['LoraConfig'], default:None) –Adapter shape, used when
lora_namenames a directory that does not exist yet. ROME's defaults are used when omitted. -
generation_config(Optional['GenerationConfig'], default:None) –Generation parameters, used by inference streams sharing this config.
-
dtype(Optional[str], default:'auto') –Loading and placement knobs forwarded to transformers.
-
device_map(Optional[str], default:'auto') –Loading and placement knobs forwarded to transformers.
-
required_gpus(Optional[str], default:'auto') –Loading and placement knobs forwarded to transformers.
-
max_seq_length(Optional[str], default:'auto') –Loading and placement knobs forwarded to transformers.
GRPOConfig
dataclass
¶
GRPOConfig(model_config: Optional[ModelConfig] = None, learning_rate: float = 5e-06, batch_size: int = 4, num_epochs: int = 3, gradient_accumulation_steps: int = 16, num_generations: int = 4, reward_funcs: List[Callable] = list(), prompt_column: str = 'prompt', rollout_func: Optional[Callable] = None, trl_config: Any = None, extra_args: Dict[str, Any] = dict())
Configuration class for managing GRPO training settings in the ROME framework.
Holds only the knobs ROME itself cares about. Anything else TRL accepts
goes in trl_config (a trl.GRPOConfig) or in extra_args, which is
merged into the TRL config that gets built.
Parameters:
-
model_config(ModelConfig, default:None) –What to train. Required.
-
learning_rate(float, default:5e-06) –The usual. Defaults follow the values ROME used for its LLM runs.
-
batch_size(float, default:5e-06) –The usual. Defaults follow the values ROME used for its LLM runs.
-
num_epochs(float, default:5e-06) –The usual. Defaults follow the values ROME used for its LLM runs.
-
gradient_accumulation_steps(float, default:5e-06) –The usual. Defaults follow the values ROME used for its LLM runs.
-
num_generations(int, default:4) –Completions GRPO samples per prompt.
-
reward_funcs(List[Callable], default:list()) –Reward functions TRL calls inline during training, with the signature
fn(prompts, completions, **kwargs) -> list[float]. Rewards that are expensive or need their own resources belong in a ROME reward stream instead — seerome.stream. -
prompt_column(str, default:'prompt') –Field of a corpus record holding the prompt TRL should train on.
-
trl_config(Optional[GRPOConfig], default:None) –Fully-specified TRL config. Overrides the individual knobs above.
-
extra_args(dict, default:dict()) –Additional keyword arguments merged into the constructed TRL config.
build_trl_config
¶
Materialize a trl.GRPOConfig.
Imported here rather than at module scope so the manager process — which only ever constructs configs — never has to pay for TRL.
Source code in rome/train/llm.py
GRPOTrainer
¶
GRPOTrainer(config: GRPOConfig, *, gpus: Optional[int] = None, nodes: int = 1, trainer_callbacks: Optional[List[Any]] = None, name: Optional[str] = None)
Bases: TrainTask
GRPO trainer task in the ROME framework.
Parameters:
-
config(GRPOConfig) –Training settings, including the
ModelConfigto train. -
gpus(int, default:None) –Resources one training round needs. Forwarded to asyncflow by the training manager. Defaults to
model_config.required_gpus. -
nodes(int, default:None) –Resources one training round needs. Forwarded to asyncflow by the training manager. Defaults to
model_config.required_gpus. -
trainer_callbacks(Optional[List[Any]], default:None) –transformerscallbacks passed through to TRL — e.g. a callback that checkpoints mid-round so streams can reload before the round ends.
Source code in rome/train/llm.py
wants_hf_dataset
class-attribute
instance-attribute
¶
TRL wants a datasets.Dataset, so the data manager builds one.
train
¶
Run one GRPO round and return the checkpoint path.
Runs inside the asyncflow task, so this is the first point where torch, transformers, TRL and peft are actually imported — on the node that has the GPUs.
Source code in rome/train/llm.py
as_command
¶
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
prepare_output_dir
staticmethod
¶
Standard checkpoint layout: <base_dir>/<name>/v<version>.
Source code in rome/train/base.py
SFTConfig
dataclass
¶
SFTConfig(model_config: Optional[ModelConfig] = None, learning_rate: float = 2e-05, batch_size: int = 4, num_epochs: int = 3, gradient_accumulation_steps: int = 8, prompt_column: str = 'prompt', completion_column: str = 'completion', text_column: str = 'text', trl_config: Any = None, extra_args: Dict[str, Any] = dict())
Configuration for supervised fine-tuning in the ROME framework.
SFT trains the model to imitate chosen (prompt, completion) pairs. In the
self-improvement loop it is the "train on the good ones" half: an inference
stream generates candidates, a reward stream scores them, the data manager
keeps the best/correct ones, and this fine-tunes on those — rejection-sampling
/ STaR-style, with no preference or RL objective. The reward that selects
the data lives in the data manager (a filter/sampler) or a reward stream, not
here; SFT only sees the winners.
Parameters:
-
model_config(ModelConfig, default:None) –What to train. Required.
-
learning_rate(float, default:2e-05) –The usual SFT knobs.
-
batch_size(float, default:2e-05) –The usual SFT knobs.
-
num_epochs(float, default:2e-05) –The usual SFT knobs.
-
gradient_accumulation_steps(float, default:2e-05) –The usual SFT knobs.
-
prompt_column(str, default:'prompt') –Corpus fields holding the instruction and the response to imitate.
-
completion_column(str, default:'prompt') –Corpus fields holding the instruction and the response to imitate.
-
text_column(str, default:'text') –Field holding a fully-formatted training string. When a record lacks it, the trainer builds it from prompt+completion via the tokenizer's chat template; when present, it is used as-is.
-
trl_config(Optional[SFTConfig], default:None) –Fully-specified TRL config. Overrides the individual knobs above.
-
extra_args(dict, default:dict()) –Additional keyword arguments merged into the constructed TRL config — e.g.
max_seq_length/max_length, whose name varies by TRL version, so it is left out of the defaults on purpose.
build_trl_config
¶
Materialize a trl.SFTConfig (imported here so the manager never
pays for TRL).
Source code in rome/train/llm.py
SFTTrainer
¶
SFTTrainer(config: SFTConfig, *, gpus: Optional[int] = None, nodes: int = 1, trainer_callbacks: Optional[List[Any]] = None, name: Optional[str] = None)
Bases: TrainTask
SFT trainer task in the ROME framework — the counterpart to GRPO.
Parameters mirror GRPOTrainer: a SFTConfig (with the
ModelConfig to train), resources forwarded to asyncflow, and
optional transformers callbacks.
Source code in rome/train/llm.py
train
¶
Run one SFT round on the chosen pairs and return the checkpoint path.
Like GRPO, torch/transformers/TRL/peft are imported here — on the node that has the GPUs, never in the manager process.
Source code in rome/train/llm.py
as_command
¶
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
prepare_output_dir
staticmethod
¶
Standard checkpoint layout: <base_dir>/<name>/v<version>.
Source code in rome/train/base.py
load_model
¶
load_model(model_config: ModelConfig)
Load model and tokenizer according to the provided model configuration.
Also usable from an inference stream's load_func, which is the point:
the stream and the trainer agree on what a checkpoint means because they
load it the same way.
Source code in rome/train/llm.py
save_model
¶
save_model(model, model_config: ModelConfig, output_dir: str) -> str
Persist weights for cross-task reload; returns the directory written to.
When a LoRA adapter is configured only the adapter is saved — that is the whole reason ROME can hot-swap weights mid-campaign without stalling inference on a multi-gigabyte read.