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

Add max_model_len when initializing VLLM engine #1211

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xu-song
Copy link
Contributor

@xu-song xu-song commented May 29, 2024

Motivation

CUDA out of memory during VLLM inference (8*A100, tensor_parallel_size=8)

[rank0]:   File "/workspace/xusong/opencompass/opencompass/models/vllm.py", line 60, in _load_model
[rank0]:     self.model = LLM(path, **model_kwargs)
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/entrypoints/llm.py", line 123, in __init__
[rank0]:     self.llm_engine = LLMEngine.from_engine_args(
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/engine/llm_engine.py", line 292, in from_engine_args
[rank0]:     engine = cls(
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/engine/llm_engine.py", line 172, in __init__
[rank0]:     self._initialize_kv_caches()
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/engine/llm_engine.py", line 262, in _initialize_kv_caches
[rank0]:     self.model_executor.initialize_cache(num_gpu_blocks, num_cpu_blocks)
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/executor/distributed_gpu_executor.py", line 51, in initialize_cache
[rank0]:     self._run_workers("initialize_cache",
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/executor/ray_gpu_executor.py", line 234, in _run_workers
[rank0]:     driver_worker_output = self.driver_worker.execute_method(
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/worker/worker_base.py", line 146, in execute_method
[rank0]:     raise e
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/worker/worker_base.py", line 137, in execute_method
[rank0]:     return executor(*args, **kwargs)
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/worker/worker.py", line 172, in initialize_cache
[rank0]:     raise_if_cache_size_invalid(num_gpu_blocks,
[rank0]:   File "/usr/local/lib/python3.10/dist-packages/vllm/worker/worker.py", line 340, in raise_if_cache_size_invalid
[rank0]:     raise ValueError(
[rank0]: ValueError: The model's max seq len (32768) is larger than the maximum number of tokens that 
     can be stored in KV cache (29984). Try increasing `gpu_memory_utilization` or decreasing `max_model_len` 
     when initializing the engine.

The default max_length can be very large, such as qwen1.5, internlm2. It is larger than the maximum number of tokens that can be stored in KV cache (29984).

Modification

Instead of increasing gpu_memory_utilization, a better solution should be decreasing max_model_len when initializing the engine.

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects.
  • CLA has been signed and all committers have signed the CLA in this PR.

@xu-song xu-song changed the title Add max_model_len to VLLM initializer Enable max_model_len when when initializing VLLM engine May 29, 2024
@xu-song xu-song changed the title Enable max_model_len when when initializing VLLM engine Enable max_model_len when when initializing VLLM engine May 29, 2024
@xu-song xu-song changed the title Enable max_model_len when when initializing VLLM engine Add max_model_len when initializing VLLM engine May 31, 2024
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