Skip to content

feat: Reward model support #516

Closed

Activity

  1. changed the title [-]Reward model support[/-] [+]feat: Reward model support[/+] on Dec 15, 2025
  2. self-assigned this
    on Jan 5, 2026
  3. ffrujeri commented on Feb 11, 2026

    @ffrujeri
    Contributor

    Design Note: GenRM Reward Model Refactoring

    Date: 2026-02-11
    Status: Draft
    Related PR: #523

    PR #523 is used as a reference for what to implement; we implement cleanly on main. VLLMModel stays generic and unchanged.

    What we're implementing

    1. GenRM Response API Model (Phase 1 — implemented)
      Package with remote and local variants, same GenRM roles and formatting:

      responses_api_models/genrm_model/
      ├── remote/                    # Remote vLLM endpoint
      │   ├── app.py                 # GenRMModel, GenRMModelConfig, GenRMConverter, GenRMModelMixin
      │   ├── configs/
      │   └── tests/
      └── local/                     # Locally managed vLLM (e.g. Ray)
          ├── app.py                 # LocalGenRMModel, LocalGenRMModelConfig (uses GenRMModelMixin)
          ├── configs/
          └── tests/
      

      Config keys: genrm_model.remote (entrypoint remote/app.py), genrm_model.local (entrypoint local/app.py).

    2. GenRM Compare Resource Server (Phase 2 — future)
      resources_servers/genrm_compare/: orchestration only; calls GenRM model via /v1/responses. Co-located strategy and utils.

    3. Type support (Phase 1 — implemented)
      openai_utils.py: NeMoGymChatCompletionCustomRoleMessageParam, extended role literals for response_1, response_2, principle.

    4. VLLMModel unchanged — No GenRM-specific code in base VLLM or LocalVLLM.

    What we're NOT doing

    • Modifying VLLMModel or LocalVLLMModel.
    • Top-level nemo_gym/comparison_strategies.py — strategy lives in genrm_compare package.
    • Complex protocol abstractions for strategy swapping.

    Overview

    GenRM (Generative Reward Model) needs custom chat roles (response_1, response_2, principle) for pairwise comparison. PR #523 added these inside the generic VLLM model, which mixed concerns and broke the OpenAI-style contract. This design keeps the base model generic and adds a dedicated GenRM Response API Model (remote and local) with a dedicated converter.

    Decisions: GenRMModel (remote) and LocalGenRMModel (local) inherit from VLLMModel / LocalVLLMModel and use a shared GenRMModelMixin + GenRMConverter for custom role handling. Comparison strategy is implemented inside the genrm_compare Resource Server. Rollout collection calls genrm_compare; genrm_compare calls the GenRM model.

    Problem (reference: PR #523)

    • GenRM roles were handled in vllm_model/app.py, coupling GenRM to the generic model.
    • Comparison logic and model inference were mixed in the Resource Server.
    • Custom roles belong in a specialized model and converter, not in VLLMConverter.

    Architecture

    Rollout Collection
        ├─→ Policy Model (/v1/responses)
        └─→ GenRM Compare (/compare)  [Phase 2]
                └─→ GenRM Model (/v1/responses)  [Phase 1]
                        remote: VLLMModel + GenRMModelMixin
                        local:  LocalVLLMModel + GenRMModelMixin
                        (GenRMConverter: response_1, response_2, principle)
    

    GenRM model (Phase 1):

    • Remote: GenRMModel = GenRMModelMixin + VLLMModel. Config: base_url, api_key, model, supports_principle_role, etc.
    • Local: LocalGenRMModel = GenRMModelMixin + LocalVLLMModel. Same converter; downloads model and starts vLLM (e.g. Ray).
    • GenRMConverter (in remote app): extends VLLMConverter, overrides _format_message() for response_1 / response_2 / principle; passes other roles to parent.

    GenRM Compare (Phase 2): Resource Server only orchestrates: build pairs, format messages with GenRM roles, call GenRM model /v1/responses, aggregate. No inference inside the Resource Server.

    Type system (openai_utils.py)

    • NeMoGymChatCompletionCustomRoleMessageParam(role, content).
    • Role literals extended to include "response_1" | "response_2" | "principle" where needed for GenRM input/message types.
    • Included in NeMoGymChatCompletionMessageParam union. Logic for custom roles lives only in GenRMConverter.

    Implementation path

    • Phase 1 (done): GenRM model package (remote + local), GenRMConverter, configs, tests; type support in openai_utils.
    • Phase 2: GenRM Compare Resource Server (directory structure, comparison_strategies in-package, app.py calling genrm_model), /compare endpoint, config to use genrm_model.
    • Phase 3: Type support — already done in Phase 1.
    • Phase 4: Rollout collection and Nemo-RL integration with genrm_compare.

    Summary

    • Do: GenRM as its own Response API Model (remote + local); GenRMModelMixin + GenRMConverter; comparison strategy inside genrm_compare package; keep types in openai_utils, logic in GenRMConverter only.
    • Don’t: Change VLLMModel/LocalVLLMModel; add GenRM roles to VLLMConverter; put comparison strategy in nemo_gym/comparison_strategies.py.

    Result: GenRM inference is a proper model (remote or local); genrm_compare only orchestrates and calls that model; base VLLM stays generic.

  4. ffrujeri commented on Feb 12, 2026

    @ffrujeri
    Contributor

    NeMo-RL Integration Design

    Principle: Zero GenRM Code in NeMo-RL

    NeMo-RL is agnostic to comparison strategies, GenRM, and reward-model details. It only requests rollouts; all GenRM behavior is configured and executed in NeMo Gym (agents and resource servers).


    Old Approach (Removed)

    The previous integration violated layering by putting GenRM concepts in NeMo-RL:

    • NeMo-RL defined GenRMCompareConfig and took genrm_config in run_rollouts().
    • NeMo-RL built a comparison_strategy (e.g. GenRMStrategy) and passed it into run_examples(..., comparison_strategy=...).
    • rollouts.py accepted use_genrm_compare, num_generations_per_prompt, genrm_compare_server_name, genrm_agent_names and built genrm_config for the remote call.

    That tied NeMo-RL to GenRM and to NeMo Gym internals.


    Current Approach

    Responsibilities

    Layer Responsibility
    NeMo-RL Calls run_rollouts(examples, tokenizer, timer_prefix). No GenRM types, no GenRM config, no strategy object.
    NeMo Gym rollout_collection For each row, POST to the agent’s /run endpoint. No comparison strategy; single code path.
    Agent (e.g. genrm_simple_agent) Runs policy generation, then calls the configured resource server (e.g. genrm_compare) /verify with the response (and optional principle).
    genrm_compare resource server /verify: buffers by prompt (and optional principle); when a cohort of size num_rollouts_per_prompt is ready, runs comparison, assigns rewards, returns them. /compare: batch API for scripts/tests.

    So: rewards that depend on other rollouts for the same task (RLHF-style) are handled inside the genrm_compare server via cohort buffering in /verify. Rollout collection and NeMo-RL stay generic.

    NeMo-RL interface (current)

    # nemo_rl/environments/nemo_gym.py
    
    @ray.remote(max_restarts=-1, max_task_retries=-1)
    class NemoGym(EnvironmentInterface):
        async def run_rollouts(
            self,
            nemo_gym_examples: list[dict],
            tokenizer: PreTrainedTokenizerBase,
            timer_prefix: str,
        ) -> list[dict]:
            # Single path: run_examples with no strategy or GenRM params
            nemo_gym_result_iterator = self.rch.run_examples(
                examples=nemo_gym_examples,
                head_server_config=self.head_server_config,
            )
            # ... collect results, postprocess, return
    # nemo_rl/experience/rollouts.py
    
    def run_async_nemo_gym_rollout(
        policy_generation: GenerationInterface,
        input_batch: BatchedDataDict[DatumSpec],
        tokenizer: TokenizerType,
        task_to_env: dict[str, EnvironmentInterface],
        generation_config: GenerationConfig,
        max_seq_len: Optional[int] = None,
        max_rollout_turns: Optional[int] = None,
        greedy: bool = False,
        master_config=None,
    ) -> AsyncNemoGymRolloutResult:
        # ...
        results, rollout_loop_timing_metrics = ray.get(
            nemo_gym_environment.run_rollouts.remote(
                nemo_gym_rows, tokenizer, timer_prefix
            )
        )
    • No GenRMCompareConfig, no genrm_config, no comparison_strategy, no GenRM-specific parameters in NeMo-RL or in run_examples.

    Where GenRM is configured (NeMo Gym side)

    • Agent config: The agent used for GRPO (e.g. genrm_simple_agent) is configured in NeMo Gym’s global config to use the genrm_compare resource server (for /verify after generation).
    • genrm_compare server config: In the genrm_compare block (e.g. in resources_servers/genrm_compare/configs/genrm_compare.yaml):
      • num_rollouts_per_prompt: Cohort size per prompt (e.g. 16). When this many verify requests are buffered for the same prompt (and optional principle), the server runs comparison and returns rewards.
      • genrm_model_server, comparison_strategy (circular/all_pairs), num_judges_per_comparison, use_principle, aggregator, length bonuses, etc.
    • Data: Each row’s agent_ref.name must match the agent that is wired to genrm_compare (e.g. genrm_simple_agent). Repeats per prompt (e.g. via num_repeats in rollout collection or by repeating rows in the dataset) should match num_rollouts_per_prompt so cohorts complete.

    No GenRM or comparison-strategy configuration is passed from NeMo-RL; it all lives in NeMo Gym’s config and in the genrm_compare server.


    How the old env/grpo GenRM settings get into Gym (after refactor)

    Previously these were passed as kwargs into run_async_nemo_gym_rollout from master_config["env"] and master_config["grpo"]. They are no longer function arguments. Here is where the equivalent behavior is configured:

    Old (removed) source Where it lives now How it gets to Gym
    use_genrm_compare Not a flag anymore You “enable” GenRM by using an agent that is configured in Gym to call the genrm_compare resource server. Your data’s agent_ref.name must match that agent. No value is passed from NeMo-RL.
    num_generations_per_prompt (grpo) num_rollouts_per_prompt in genrm_compare server config Set env.nemo_gym.genrm_compare.resources_servers.genrm_compare.num_rollouts_per_prompt in your training YAML (same value as grpo.num_generations_per_prompt, e.g. 16). That entire env.nemo_gym dict is passed as initial_global_config_dict when the NemoGym Ray actor is created (grpo.py builds NemoGymConfig(..., initial_global_config_dict=env_configs["nemo_gym"])). Gym’s RunHelper loads that dict and merges it with config_paths, so the genrm_compare server sees num_rollouts_per_prompt. Keep grpo.num_generations_per_prompt for GRPO batch math (e.g. repeat_interleave); set num_rollouts_per_prompt in the same YAML under env.nemo_gym so the server’s cohort size matches.
    genrm_compare_server_name (env) Agent’s resource server in Gym The agent definition (e.g. genrm_simple_agent) in env.nemo_gym or in a config file listed in config_paths specifies which resource server it uses (e.g. resources_server.name: genrm_compare). Not passed from NeMo-RL.
    genrm_agent_names (env) Which agents use genrm_compare Determined by Gym config: any agent that has resources_server pointing to genrm_compare “uses GenRM.” Your data chooses the agent via agent_ref.name. Not passed from NeMo-RL.

    So: env.use_genrm_compare, env.genrm_compare_server_name, and env.genrm_agent_names are no longer read by code; you can remove them from the YAML or keep them as comments. The only value that must be set in env.nemo_gym for GenRM cohort behavior is num_rollouts_per_prompt under the genrm_compare server block (and it should match grpo.num_generations_per_prompt).


    Flow (high level)

    NeMo-RL
      └─► run_rollouts(examples, tokenizer, timer_prefix)
            └─► run_examples(examples, head_server_config)
    
    NeMo Gym rollout_collection
      └─► For each row: POST to agent_ref["name"] /run  (one path only)
    
    Agent (e.g. genrm_simple_agent)
      └─► Generate response → POST to genrm_compare /verify (response + optional principle)
    
    genrm_compare resource server
      └─► /verify: buffer by prompt (and principle); when cohort size = num_rollouts_per_prompt
            → run comparison → return per-rollout rewards
      └─► /compare: batch comparison API (e.g. for scripts/tests)
    

    Enabling / disabling GenRM-style rewards

    • Use GenRM (relative rewards per cohort): Use an agent that is configured to call the genrm_compare resource server’s /verify. Ensure genrm_compare is loaded with num_rollouts_per_prompt (and other options) set as desired. Data should have the right number of rollouts per prompt.
    • Standard rewards: Use an agent that does not call genrm_compare (or that uses a different reward path). No change in NeMo-RL code.

    Migration summary (what was removed from NeMo-RL)

    • GenRMCompareConfig TypedDict and any genrm_config parameter.
    • run_rollouts(..., genrm_config=...) and all logic that built a comparison_strategy and passed it to run_examples(..., comparison_strategy=...).
    • From run_async_nemo_gym_rollout: parameters use_genrm_compare, num_generations_per_prompt, genrm_compare_server_name, genrm_agent_names and the block that built genrm_config and passed it to run_rollouts.remote(..., genrm_config).
    • From call sites (e.g. GRPO, async rollout): all GenRM-specific kwargs; validation that required num_val_generations_per_prompt > 1 when “GenRM compare” was enabled.

    NeMo-RL now only calls run_rollouts(examples, tokenizer, timer_prefix) and run_examples(examples, head_server_config) with no GenRM or strategy parameters.


    Troubleshooting

    • Rewards not relative / cohort behavior wrong: Check genrm_compare server config (num_rollouts_per_prompt, comparison_strategy, etc.) and that the agent used in data is the one wired to genrm_compare’s /verify.
    • Wrong or missing rewards: Confirm genrm_compare and the GenRM model server are running and that agent_ref.name in the data matches the agent that calls genrm_compare.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions