Skip to content
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

Update generate.py: Add parallel processing for token generation #426

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Utsav-pal
Copy link

@Utsav-pal Utsav-pal commented Jan 28, 2025

This update introduces parallel processing for token generation using torch.multiprocessing.Pool. The new implementation improves inference speed by processing multiple sequences concurrently.

  • Added the generate_parallel() function for parallel token generation.
  • Used multiprocessing to distribute the workload across multiple processes, allowing for faster generation of tokens for multiple prompts.
  • The generate_single_sequence() function was added to handle individual sequence generation logic, which is called by each worker in parallel.
  • The num_workers parameter is introduced to control the number of worker processes (default is 4).
  • Model is shared across processes for efficient memory usage.

These changes are particularly beneficial for batch processing or multi-prompt generation scenarios where multiple sequences need to be generated simultaneously.

vThis update introduces parallel processing for token generation using torch.multiprocessing.Pool.
The new implementation improves inference speed by processing multiple sequences concurrently.
- Added the generate_parallel() function for parallel token generation.
- Used multiprocessing to distribute the workload across multiple processes, allowing for faster generation of tokens for multiple prompts.
- The generate_single_sequence() function was added to handle individual sequence generation logic, which is called by each worker in parallel.
- The num_workers parameter is introduced to control the number of worker processes (default is 4).
- Model is shared across processes for efficient memory usage.

These changes are particularly beneficial for batch processing or multi-prompt generation scenarios where multiple sequences need to be generated simultaneously.
@Some1and2-XC
Copy link

Do you have any benchmarks for this?

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.

2 participants