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

[Bugfix] Update run_batch.py to handle larger numbers of batches #5774

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

Conversation

w013nad
Copy link

@w013nad w013nad commented Jun 23, 2024

vllm engine appears to error out somewhere between 20k-100k async requests. Refactor to only allow a maximum of 10k concurrent requests with Semaphore. Also added in a tqdm progress bar. Note that this was created under 0.5.0.post1, I am unable to test integration with some of the newer changes, but it should work.

It would be nice to suppress the request output as well and just have the option to have tqdm only but I was unable to figure out how to make that work.

Note that this is my first PR for this project so I'm not entirely sure how all of this works.

FIX #6154


PR Checklist (Click to Expand)

Thank you for your contribution to vLLM! Before submitting the pull request, please ensure the PR meets the following criteria. This helps vLLM maintain the code quality and improve the efficiency of the review process.

PR Title and Classification

Only specific types of PRs will be reviewed. The PR title is prefixed appropriately to indicate the type of change. Please use one of the following:

  • [Bugfix] for bug fixes.
  • [CI/Build] for build or continuous integration improvements.
  • [Doc] for documentation fixes and improvements.
  • [Model] for adding a new model or improving an existing model. Model name should appear in the title.
  • [Frontend] For changes on the vLLM frontend (e.g., OpenAI API server, LLM class, etc.)
  • [Kernel] for changes affecting CUDA kernels or other compute kernels.
  • [Core] for changes in the core vLLM logic (e.g., LLMEngine, AsyncLLMEngine, Scheduler, etc.)
  • [Hardware][Vendor] for hardware-specific changes. Vendor name should appear in the prefix (e.g., [Hardware][AMD]).
  • [Misc] for PRs that do not fit the above categories. Please use this sparingly.

Note: If the PR spans more than one category, please include all relevant prefixes.

Code Quality

The PR need to meet the following code quality standards:

  • We adhere to Google Python style guide and Google C++ style guide.
  • Pass all linter checks. Please use format.sh to format your code.
  • The code need to be well-documented to ensure future contributors can easily understand the code.
  • Include sufficient tests to ensure the project to stay correct and robust. This includes both unit tests and integration tests.
  • Please add documentation to docs/source/ if the PR modifies the user-facing behaviors of vLLM. It helps vLLM user understand and utilize the new features or changes.

Notes for Large Changes

Please keep the changes as concise as possible. For major architectural changes (>500 LOC excluding kernel/data/config/test), we would expect a GitHub issue (RFC) discussing the technical design and justification. Otherwise, we will tag it with rfc-required and might not go through the PR.

What to Expect for the Reviews

The goal of the vLLM team is to be a transparent reviewing machine. We would like to make the review process transparent and efficient and make sure no contributor feel confused or frustrated. However, the vLLM team is small, so we need to prioritize some PRs over others. Here is what you can expect from the review process:

  • After the PR is submitted, the PR will be assigned to a reviewer. Every reviewer will pick up the PRs based on their expertise and availability.
  • After the PR is assigned, the reviewer will provide status update every 2-3 days. If the PR is not reviewed within 7 days, please feel free to ping the reviewer or the vLLM team.
  • After the review, the reviewer will put an action-required label on the PR if there are changes required. The contributor should address the comments and ping the reviewer to re-review the PR.
  • Please respond to all comments within a reasonable time frame. If a comment isn't clear or you disagree with a suggestion, feel free to ask for clarification or discuss the suggestion.

Thank You

Finally, thank you for taking the time to read these guidelines and for your interest in contributing to vLLM. Your contributions make vLLM a great tool for everyone!

vllm engine appears to error out somewhere between 20k-100k async requests. Refactor to only allow a maximum of 10k concurrent requests with Semaphore
@wuisawesome
Copy link
Contributor

@w013nad do you mind sharing the error you got without this PR?

I think we should definitely support this many requests, but wonder if there's an underlying issue that we should fix.

# Read file contents asynchronously
file_contents = (await read_file(input_file)).strip().split("\n")
total_lines = len(file_contents)

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's figure out whether the engine queuing should be fixed instead, but if we decide to limit the requests we submit, I wonder if we should just not create the asyncio requests instead.

Something like

finished_requests = []
response_futures: List[Awaitable[BatchRequestOutput]] = []

for request_json in tqdm(file_contents, total=total_lines, desc="Running requests"):
        request = BatchRequestInput.model_validate_json(request_json.strip())
        response_futures.append(run_request_with_semaphore(request))
        if len(response_futures) >= MAX_CONCURRENT_REQUESTS:
            recently_finished, response_futures = await asyncio.wait(response_futures)
            finished_requests.extend(recently_finished)

finished_requests.extend(await asyncio.gather(*response_futures))

This way we can more accurately track the progress of the job.

@cadedaniel
Copy link
Collaborator

FYI there are ongoing refactors to move engine/api server/worker into own processes. This should enable much higher QPS.

@w013nad
Copy link
Author

w013nad commented Jun 23, 2024

@wuisawesome I'm doing a RAG test running 4500 questions through with a variety of k chunks. The total file size is 1.2GB and 95k requests. I did another test which also had 95k requests, but the queries were much shorter with a total file size of ~200MB, and it worked fine. This indicates it's not the number of requests but the amount of text I'm sending in.

INFO 06-23 22:52:10 async_llm_engine.py:564] Received request cmpl-f96570de404141e09427685b17c752c4: prompt: '<|im_start', params: SamplingParams(n=1, best_of=1, presence_penalty=0.0, frequency_penalty=0.0, repetition_penalty=1.0, temperature=0.01, top_p=1.0, top_k=-1, min_p=0.0, seed=None, use_beam_search=False, length_penalty=1.0, early_stopping=False, stop=[], stop_token_ids=[], include_stop_str_in_output=False, ignore_eos=False, max_tokens=1000, min_tokens=0, logprobs=None, prompt_logprobs=None, skip_special_tokens=True, spaces_between_special_tokens=True, truncate_prompt_tokens=None), prompt_token_ids: [151644, 8948, 198, 2610, 525, 264, 10950, 17847, 13, 151645], lora_request: None.
ERROR 06-23 22:54:02 async_llm_engine.py:535] Engine iteration timed out. This should never happen!
ERROR 06-23 22:54:02 async_llm_engine.py:52] Engine background task failed
ERROR 06-23 22:54:02 async_llm_engine.py:52] Traceback (most recent call last):
ERROR 06-23 22:54:02 async_llm_engine.py:52]   File "/usr/local/lib/python3.10/dist-packages/vllm/engine/async_llm_engine.py", line 506, in engine_step
ERROR 06-23 22:54:02 async_llm_engine.py:52]     request_outputs = await self.engine.step_async()
ERROR 06-23 22:54:02 async_llm_engine.py:52]   File "/usr/local/lib/python3.10/dist-packages/vllm/engine/async_llm_engine.py", line 235, in step_async
ERROR 06-23 22:54:02 async_llm_engine.py:52]     output = await self.model_executor.execute_model_async(
ERROR 06-23 22:54:02 async_llm_engine.py:52]   File "/usr/local/lib/python3.10/dist-packages/vllm/executor/distributed_gpu_executor.py", line 166, in execute_model_async
ERROR 06-23 22:54:02 async_llm_engine.py:52]     return await self._driver_execute_model_async(execute_model_req)
ERROR 06-23 22:54:02 async_llm_engine.py:52]   File "/usr/local/lib/python3.10/dist-packages/vllm/executor/multiproc_gpu_executor.py", line 149, in _driver_execute_model_async
ERROR 06-23 22:54:02 async_llm_engine.py:52]     return await self.driver_exec_model(execute_model_req)
ERROR 06-23 22:54:02 async_llm_engine.py:52] asyncio.exceptions.CancelledError
ERROR 06-23 22:54:02 async_llm_engine.py:52]
ERROR 06-23 22:54:02 async_llm_engine.py:52] During handling of the above exception, another exception occurred:
ERROR 06-23 22:54:02 async_llm_engine.py:52]
ERROR 06-23 22:54:02 async_llm_engine.py:52] Traceback (most recent call last):
ERROR 06-23 22:54:02 async_llm_engine.py:52]   File "/usr/lib/python3.10/asyncio/tasks.py", line 456, in wait_for
ERROR 06-23 22:54:02 async_llm_engine.py:52]     return fut.result()
ERROR 06-23 22:54:02 async_llm_engine.py:52] asyncio.exceptions.CancelledError
ERROR 06-23 22:54:02 async_llm_engine.py:52]
ERROR 06-23 22:54:02 async_llm_engine.py:52] The above exception was the direct cause of the following exception:
ERROR 06-23 22:54:02 async_llm_engine.py:52]
ERROR 06-23 22:54:02 async_llm_engine.py:52] Traceback (most recent call last):
ERROR 06-23 22:54:02 async_llm_engine.py:52]   File "/usr/local/lib/python3.10/dist-packages/vllm/engine/async_llm_engine.py", line 42, in _log_task_completion
ERROR 06-23 22:54:02 async_llm_engine.py:52]     return_value = task.result()
ERROR 06-23 22:54:02 async_llm_engine.py:52]   File "/usr/local/lib/python3.10/dist-packages/vllm/engine/async_llm_engine.py", line 532, in run_engine_loop
ERROR 06-23 22:54:02 async_llm_engine.py:52]     has_requests_in_progress = await asyncio.wait_for(
ERROR 06-23 22:54:02 async_llm_engine.py:52]   File "/usr/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
ERROR 06-23 22:54:02 async_llm_engine.py:52]     raise exceptions.TimeoutError() from exc
ERROR 06-23 22:54:02 async_llm_engine.py:52] asyncio.exceptions.TimeoutError
INFO 06-23 22:54:03 async_llm_engine.py:167] Aborted request cmpl-e0d8265bcc46475d944cd1b0be30b316.

After this, I get 95k lines of

INFO 06-23 22:54:06 async_llm_engine.py:167] Aborted request cmpl-f96570de404141e09427685b17c752c4.

and then it just shuts itself down. Note that the job launching process takes ~20 minutes to launch 95k jobs.

Container was launched with

sudo docker run -d --rm --shm-size=10.24gb --gpus '"device=2"' -v /dgxdata/aiml/:/home/ndurkee --entrypoint /bin/bash arti.bsf.ball.com/docker-group/vllm/vllm-openai:latest -c "python3 -m vllm.entrypoints.openai.run_batch -i /home/ndurkee/ndurkee/openai_example_batch.jsonl -o /home/ndurkee/ndurkee/results_1.jsonl --model /home/ndurkee/Qwen2-7B-Instruct-GPTQ-Int8 -tp 1 --distributed-executor-backend mp --max-log-len 10"

@wuisawesome
Copy link
Contributor

gotcha, this makes sense. @w013nad do you mind making the change to the streaming approach and let's just get this merged in the front end?

Copy link

This pull request has been automatically marked as stale because it has not had any activity within 90 days. It will be automatically closed if no further activity occurs within 30 days. Leave a comment if you feel this pull request should remain open. Thank you!

@github-actions github-actions bot added the stale label Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: expose the tqdm progress bar to enable logging the progress
3 participants