Skip to content

Fix mis-aligned prompts and completions in colocate mode #3491

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 24, 2025

Conversation

toslali-ibm
Copy link
Contributor

@toslali-ibm toslali-ibm commented May 24, 2025

What does this PR do?

Fixes #3492

  • Simply slice prompts text back (similar to completions)

See the fixed log completions result:
Screenshot 2025-05-24 at 10 44 03 AM

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a GitHub issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

CC @qgallouedec

Thank @fabianlim for catching this.

@toslali-ibm toslali-ibm marked this pull request as ready for review May 24, 2025 14:44
Copy link
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

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

Good catch, thanks for the fix!
To enhance consistency, maybe using all_prompt_text instead of prompt_text in line 1060 would also work?

@toslali-ibm
Copy link
Contributor Author

Good catch, thanks for the fix! To enhance consistency, maybe using all_prompt_text instead of prompt_text in line 1060 would also work?

Do you mean that we may not need to slice prompts if we use all_prompts_text in generation (if TP > 1, do the gathering, else, all_prompts_text = prompts_text)?

+                all_prompts_text = prompts_text
                 if self.vllm_tensor_parallel_size > 1:
                     # Gather prompts from all ranks in the TP group and flatten.
                     # Each rank starts with its own prompts; after gathering, all ranks see the full group set.
                     orig_size = len(prompts_text)
                     gathered_prompts = [None for _ in range(self.vllm_tensor_parallel_size)]
                     torch.distributed.all_gather_object(gathered_prompts, prompts_text, group=self.tp_group)
-                    prompts_text = [p for sublist in gathered_prompts for p in sublist]
+                    all_prompts_text = [p for sublist in gathered_prompts for p in sublist]
 
                 with profiling_context(self, "vLLM.generate"):
-                    all_outputs = self.llm.generate(prompts_text, sampling_params=sampling_params, use_tqdm=False)
+                    all_outputs = self.llm.generate(all_prompts_text, sampling_params=sampling_params, use_tqdm=False)
 
                 completion_ids = [output.token_ids for outputs in all_outputs for output in outputs.outputs]

Copy link
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

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

Nit

@qgallouedec
Copy link
Member

Can you confirm it also works like this?

toslali-ibm and others added 2 commits May 24, 2025 11:46
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
Co-authored-by: Quentin Gallouédec <45557362+qgallouedec@users.noreply.github.com>
@toslali-ibm
Copy link
Contributor Author

Can you confirm it also works like this?

I can confirm. See below:
config for 4 GPUs:

per_device_train_batch_size: 1
max_steps: 1
num_generations: 2
use_vllm: true
vllm_mode: colocate
vllm_tensor_parallel_size: 2
log_completions: true

Log completions look like the following:
Screenshot 2025-05-24 at 11 51 37 AM

Copy link
Member

@qgallouedec qgallouedec left a comment

Choose a reason for hiding this comment

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

Thanks!

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@qgallouedec qgallouedec merged commit 9ac614f into huggingface:main May 24, 2025
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

In colocate mode -> Prompts and completions are misaligned in logs
3 participants