Skip to content

Conversation

@gitlost-murali
Copy link
Contributor

@gitlost-murali gitlost-murali commented Nov 10, 2025

Generator class in src/forge/actors/generator.py now takes the number of completions (n) to be specified per request, instead of always using the default from the generator's sampling parameters.

Generator request flexibility and parameter handling

  • The generate method in Generator now accepts an optional n parameter, allowing callers to specify the number of completions to generate per request. If n is not provided, the default from self.sampling_params.n is used.
  • Internal logic in generate creates modified sampling parameters if n is overridden, ensuring all downstream code uses the correct value for n and related settings. This includes passing the updated parameters to tokenization, request processing, and child request creation.

Unit testing

  • Added a new test test_generate_n_parameter_logic to verify that parameter overriding works as expected, including object identity checks and value assertions.

Note: This feature is useful when we extend to multi-turn rollouts where we'd generate the first turn for all K rollouts (default n=K). Later, each rollout would branch out differently - making a dedicated generate call for each turn (using generate.route(n=1))

Add optional n parameter to Generator.generate() to allow overriding
the default sampling_params.n on a per-request basis. Update GRPO
rollout to explicitly request n=1 for single trajectory generation.
Updated the logic for modifying the sampling_params.n attribute to use the __replace__ method for better clarity and consistency. Added a new unit test to verify the behavior of the n parameter logic in the Generator class.
@meta-cla
Copy link

meta-cla bot commented Nov 10, 2025

Hi @gitlost-murali!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@gitlost-murali gitlost-murali changed the title generator n parameter Configurable num_of_rollouts parameter for generator Nov 10, 2025
@meta-cla
Copy link

meta-cla bot commented Nov 10, 2025

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 10, 2025
@gitlost-murali
Copy link
Contributor Author

gitlost-murali commented Nov 13, 2025

Hi @daniellepintz / @felipemello1 / @joecummings

Any update on this MR? Do I need to change something in the MR or what are your thoughts on this MR?

My overall goal is to integrate multi-turn rollouts. A first step into it would be enable generator have n (num_samples) argument as each trajectory can branch differently after the first generation (n = default). Later, I want to integrate an echo env which doesn't change the current training setup. Later, I can add another multi-turn env which would involve maintaining loss mask, interleaved response tokens, etc

@felipemello1
Copy link
Contributor

felipemello1 commented Nov 13, 2025

hey @gitlost-murali , thanks for the PR! I think we can change the API a bit.

My understanding is that you want to be able to set the sampling_params for every generate call. Your current need is to change n, but someone else may want to change the temperature.

What if we do this instead:

async def generate(
        self, 
		prompt: str, 
        *, 
         priority: int = 0, 
         sampling_params: SamplingParams | None = None
    ) -> list[Completion]:
    
    params = sampling_params or self.sampling_params

you would just need to make sure that the logic in post_init still applies

@felipemello1
Copy link
Contributor

regarding multiturn, i just put this PR up. Its WIP, but i am hoping to have a working recipe by early next week #567

  Allows per-request override of any sampling parameter (temperature,
  top_p, n, etc.) instead of just n. Preserves output_kind=FINAL_ONLY
  enforcement from post_init logic.
  Add test to ensure Generator always overrides output_kind to FINAL_ONLY
  when initialized with custom sampling_params dict, protecting against
  accidental removal of this system requirement.
@gitlost-murali gitlost-murali changed the title Configurable num_of_rollouts parameter for generator Configurable sampling parameter for generator Nov 13, 2025
@gitlost-murali
Copy link
Contributor Author

gitlost-murali commented Nov 13, 2025

Thanks! I updated the code to enable passing custom sampling_params. Note; To maintain the post_init logic, the output_kind would be set to RequestOutputKind.FINAL_ONLY

Amazing! Just read the RFC. Let me know if I can contribute somehow to multi-turn rollouts

Copy link
Contributor

@felipemello1 felipemello1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! Will merge after CI is green

@gitlost-murali
Copy link
Contributor Author

There was a linting issue earlier. Sorry about that
Can you re-trigger the CI-checks/auto-merge? Thanks!

@felipemello1
Copy link
Contributor

no worries. You might need

pre-commit install
pre-commit run --all-files

to handle all the linter issues

@felipemello1 felipemello1 merged commit 791af13 into meta-pytorch:main Nov 14, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants