TensorRT-LLM icon indicating copy to clipboard operation
TensorRT-LLM copied to clipboard

how to control GPU memory usage by restrict KV cache allocation?

Open forrestjgq opened this issue 3 years ago • 7 comments

Hi there:

The tensorrt-llm tends to use as much memory for KV cache as it could in startup, but we're planing to run multiple trtllm instances or multiple models. How do I restrict the memory usage for each trtllm instance?

For example, we got an A100 with 80G memory, and try to split it to 2 40Gs for 2 models.

forrestjgq avatar Nov 28 '23 04:11 forrestjgq

I'm not sure if TensorRT-LLM supports MIG.

Perhaps, you could try.

kmati-dev avatar Nov 28 '23 07:11 kmati-dev

You can control that by setting kv_cache_free_gpu_mem_fraction. The number should between 0 ~ 1. When the number is close to 1, it will allocate more memory for kv cache.

byshiue avatar Nov 28 '23 08:11 byshiue

You can control that by setting kv_cache_free_gpu_mem_fraction. The number should between 0 ~ 1. When the number is close to 1, it will allocate more memory for kv cache.

That's working, thanks!

forrestjgq avatar Dec 02 '23 09:12 forrestjgq

Hi @byshiue @forrestjgq , would you kindly tell me, where should I use this parameter? Cannot see it neither in trtllm-build parameters, nor in ModelRunnerCpp.from_dir params, nor in build_config of the model. Am I missing something or there is no support for this parameter when using the Cpp version? Thanks!

Aktsvigun avatar Feb 22 '24 11:02 Aktsvigun

It is a runtime parameter and set here https://github.com/NVIDIA/TensorRT-LLM/blob/main/tensorrt_llm/runtime/model_runner_cpp.py#L169-L172

byshiue avatar Feb 23 '24 09:02 byshiue

Thank you!

Aktsvigun avatar Feb 23 '24 09:02 Aktsvigun

You can control that by setting kv_cache_free_gpu_mem_fraction. The number should between 0 ~ 1. When the number is close to 1, it will allocate more memory for kv cache.

Hey there, I tried to set this parameter in a triton server instance serving a LLaMa3 8B. Going from 0.1 to 0.9 results in no change at all.

From nvidia-smi I still se 17847Mib fully booked. Both with 0.1 and 0.9.

Moreover I expect that a quantized version of the same model results in two different GPUs RAM footprints. Instead, I still see the same ~18gb booked.

How can I manage the ram footprint of the models?

lodm94 avatar Aug 05 '24 14:08 lodm94