REINFORCE is a class of policy-gradient methods that optimize the policy directly using sampled returns. These methods are widely used for LLM fine-tuning because of their simplicity and efficiency. Examples include GRPO, Dr. GRPO, RLOO, ReMax, TreeRPO, and REINFORCE++. REINFORCE can be extended to multi-agent settings, where multiple LLM agents respond at each turn and their joint responses receive a shared reward.
All MAREINFORCE trainers share one training loop. At each rollout node, every agent samples \( K \) responses, the trainer scores the index-aligned joint responses with one shared reward, and each agent weights its own log-probabilities by the resulting shared advantages before a buffered optimizer step.
MAREINFORCE#
The policy-gradient surrogate for Multi-Agent REINFORCE (MAREINFORCE), before advantage normalization or reference regularization, can be expressed as:
REINFORCE methods do not use a critic model for value estimation. Their policy-gradient estimates can have high variance due to stochastic sampling and long-term credit assignment. Common approaches to reducing this variance include using an action-independent baseline or averaging over more samples, such as \( K \) samples at each joint history \( \mathbf{h}_t \).
MAGRPO#
Multi-Agent Group-Relative Policy Optimization (MAGRPO) is an instantiation of MAREINFORCE inspired by GRPO, where the group-average baseline is the mean return of \( K \) samples. In the default aligned joint mode, its surrogate before advantage normalization is:
The sampled group mean includes the sample being updated, so it is not the action-independent baseline assumed in the general expression above. In multi-turn training, each branch’s return is its immediate reward plus the mean return of its child node, with no discount applied. In cross mode, each agent’s completion instead receives the sum of returns over all joint combinations containing that completion.
By default, advantage_normalization=True then centers and scales the advantages within each node’s generation group using the population standard deviation, with a minimum denominator of 1e-6. If reference KL regularization is enabled, the sampled reference penalty is subtracted from returns before the baseline and normalization are applied.
The current
MAGRPOTrainerloss slice omits the final completion token, so its implemented sequence score differs from the full sequence log-probability in the surrogate above. The canonical setting isjoint_mode="cross"; the accepted"crossed"alias generates Cartesian combinations but does not apply the same per-completion return aggregation.
num_agents: Configured number of agents, which should match the trainer setupnum_turns: Number of turns per episodenum_train_epochs: Number of training epochsagent_learning_rate: Learning ratelogging_steps: Logging interval in stepsnum_generations: Number of generations to sample per prompt for each agentmax_new_tokens: Maximum number of new tokens to generatetemperature: Temperature for samplingtop_p: Top-p for samplingtop_k: Top-k for samplingdiscount: Retained configuration field; the current MAGRPO implementation computes undiscounted returns and does not use this valuejoint_mode: Joint action composition (alignedfor index-aligned,crossfor Cartesian product)early_termination_threshold: A training branch stops expanding when its node’s mean immediate reward exceeds this threshold (default-0.2;Nonedisables early termination)rollout_buffer_size: Number of node samples to buffer per agent before an updatetrain_batch_size: Number of node samples per optimizer step; defaults torollout_buffer_sizeadvantage_normalization: Whether to center and scale advantages within each node’s generation group (defaultTrue)eval_interval: Evaluation runs at batch indices divisible by N, including the first batch of each epoch;0disables periodic evaluationeval_num_samples: Number of samples to evaluate per evaluation runeval_batch_size: Evaluation DataLoader batch sizeexternal_prompt_passthrough: Whether to use external prompts directly in multi-turn trainingadvantage_mode: Baseline mode (mean,max,rloo,raw)parallel_training: Agent execution mode (noneormp)agent_devices: Agent device placement; required explicitly forparallel_training="mp"reference_kl_enabled: Whether to enable a frozen-reference KL penalty (defaultFalse)reference_kl_coef: Weight of the reference penalty (default0.1)reference_devices: Optional device placement for the reference models
agent_modeloragents: Model identifier string for homogeneous agents, or a list of model identifiers or preloaded models; preloaded models are supplied throughagentsnum_agents: Number of agents created fromagent_model(default2), configured independently ofargs. When onlyagentsis supplied, its length determines the agent counttokenizer: Shared tokenizer or one per agent; optional for model identifiers, required for preloaded modelsreward_func: Callable that returns a list of floats (required)reward_processor: Optional processor to apply to rewards (e.g., scaling)formatters: Single callable or list of per-agent callables for prompt formattingargs: Instance ofMAGRPOConfig(optional)train_dataset: Dataset required when callingtrain()eval_dataset: Evaluation dataset (optional)model_config: Model configuration dictionary (optional)wandb_config: Configuration for Weights & Biases logging (optional)external_transition: Function providing transitions between turns; required whennum_turns > 1(the default is2)eval_logger: Optional task-metrics callback, called aseval_logger(agent_completions_turns=..., batch_items=..., prompts=...); returns one metrics dictionary per evaluated item and is used witheval_aggregatoreval_aggregator: Optional callback, called aseval_aggregator(metrics, num_turns=...); the returnedturn_k/...metrics are logged undereval/. Both evaluation callbacks must be supplied for custom metrics
MAGRPO collects samples into a rollout buffer and recomputes their log-probabilities during updates, without importance sampling or ratio clipping. Samples may therefore predate earlier updates from the same buffer or rollout tree. Since the trainer has no critic model,
value_clip_rangedoes not apply.
The trainer uses a fixed training DataLoader batch size of 1 and requires at least
num_generations=2, including for the raw-return variant. By default,train_batch_size=rollout_buffer_size: each agent averages the losses of its buffered node samples for one optimizer step. Smaller mini-batches produce multiple optimizer steps; a partial buffer is flushed at the end of each epoch.
Other Variants#
CoMLRL also provides other MAREINFORCE variants with different baselines:
- MARLOO: Multi-Agent REINFORCE Leave-One-Out. The baseline is the mean return of the other generations in the same node’s sample group, not the other agents.
- MAReMax: Multi-Agent REINFORCE with Group Max (
MAReMaxConfigandMAReMaxTrainer). The baseline is the maximum sampled group return at the node; this implementation does not generate a separate greedy baseline response.
MAREINFORCETrainer,MARLOOTrainer, andMAReMaxTrainerderive fromcomlrl.trainers.reinforce.MAGRPOTrainer. Their corresponding configuration classes inheritMAGRPOConfig, with defaultadvantage_modevalues ofraw,rloo, andmax, respectively. They share the same trainer interface and configuration fields.
The four trainers differ only in the baseline subtracted from the shared return. For one node with \( K=4 \) joint responses, the animation below compares their advantages before normalization: MAREINFORCE keeps the raw return, as in REINFORCE; MAGRPO subtracts the group mean, as in GRPO; MARLOO subtracts the mean of the other \( K-1 \) returns, as in RLOO, which scales the MAGRPO advantages by \( K/(K-1) \); and MAReMax subtracts the group maximum, so no response receives a positive advantage.
The variant formulas describe advantages before normalization. All variants inherit
advantage_normalization=True, which re-centers even raw returns and max-baseline advantages. Except for the standard-deviation floor and numerical precision, the four modes then yield the same normalized advantages. Users can retain the baseline differences shown above, including the raw-return MAREINFORCE estimator, by settingadvantage_normalization=False.