Repository: EleutherAI/lm-evaluation-harness
Issue: CUDA Out of Memory
Root cause: Resource Mishandling

## Command
```
lm_eval --model vllm --model_args pretrained=Qwen/Qwen2.5-72B-Instruct,tensor_parallel_size=8,dtype=bfloat16,gpu_memory_utilization=0.8,data_parallel_size=1 --seed 42 --log_samples --output_path results/Qwen_Qwen2.5-72B-Instruct/leaderboard/ --tasks leaderboard --apply_chat_template --fewshot_as_multiturn --batch_size 1
```

GPU: 8xA100 80G

## Other Attempts
- changing `gpu_memory_utilization` to `[0.6, 0.8, 0.9, 0.99]`
- changing `batch_size` to [auto, 1, 2, 4, 16]
- changing data_parallel_size to 2 and tensor_parallel_size to 4

None of the above attempts work

**Even more interesting, when I replaced `--tasks leaderboard` with individual tasks like `leaderboard_gpqa_main` and `leaderboard_mmlu_pro`, it ran normally.**

## Expected Behavior
1. according to official Qwen [documentation](https://qwen.readthedocs.io/en/latest/benchmark/speed_benchmark.html), the model should easily run on **4x80GB VRAM** even on context length of 131072 using vllm. So the evaluation should also run.
2. if individual tasks can run, the task group "leaderboard" should also run


## Error Message
[rank0]:   File ".../lib/python3.11/site-packages/vllm/model_executor/layers/sampler.py", line 904, in get_logprobs
[rank0]:     logprobs[query_indices_gpu],
[rank0]:     ~~~~~~~~^^^^^^^^^^^^^^^^^^^
[rank0]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 7.04 GiB. GPU 0 has a total capacity of 79.19 GiB of which 7.02 GiB is free. Including non-PyTorch memory, this process has 72.15 GiB memory in use. Of the allocated memory 66.29 GiB is allocated by PyTorch, with 48.00 MiB allocated in private pools (e.g., CUDA Graphs), and 186.02 MiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation.  See documentation for Memory Management  (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)

Hi, I face the same issue. Although this happens for me when running loglikelihood requests. Any update on this? 

I am running deepseek distill model (Llama 8B) quantized to W4A16 and context length 8192 on 20 GB VRAM GPU. The hardware should be sufficient to run this model (and it runs when I individually run it via vLLM). Only happens when running the benchmark. So far, I tried with openllm and leaderboard benchmarks. Both fail because of the same error. 

Further analysis: As mentioned by @seermer, some tasks within sub-groups might run. But they fail as a task group.  

An example: In the openllm benchmark, only gsm8k ran. The rest all threw the same error. 

Fixed it by playing around with `gpu_memory_utilisation`. Realized that lm_eval uses GPU memory that is left in addition to what vLLM instance uses. Manually calculated my vLLM instance memory requirement and only allocated the desired via `gpu_memory_utilization` parameter. This gave me additional 10 GB to perform the evaluation :) 

@seermer I would suggest you to compute your GPU memory requirement and try it out. Good luck! 

> Fixed it by playing around with `gpu_memory_utilisation`. Realized that lm_eval uses GPU memory that is left in addition to what vLLM instance uses. Manually calculated my vLLM instance memory requirement and only allocated the desired via `gpu_memory_utilization` parameter. This gave me additional 10 GB to perform the evaluation :)
> 
> [@seermer](https://github.com/seermer) I would suggest you to compute your GPU memory requirement and try it out. Good luck!

Thanks for the info, but unfortunately as I pointed out in my original question, tuning memory utilization does not work for me, I tried multiple values ranging from 0.6 (which leaves 256GB VRAM for lm_eval) all the way to 0.99, none of them work

Same here (see my other issue #2815 )

Hi folks, there are 2-3 options for this you might want to look into:
- Reduce the ```max_num_seqs``` (set it to around 1)
- Reduce the ```gpu_memory_utilization``` (around 0.6 and slowly increase)
- Try ```enable_chunked_prefill=True``` (though idk how that would affect output quality of the eval.)

> Hi folks, there are 2-3 options for this you might want to look into:
> 
> * Reduce the `max_num_seqs` (set it to around 1)
> * Reduce the `gpu_memory_utilization` (around 0.6 and slowly increase)
> * Try `enable_chunked_prefill=True` (though idk how that would affect output quality of the eval.)

I've try all those options but cuda oom on 
```
Running loglikelihood requests:   0%|                                                      | 0/152668 [00:24<?, ?it/s]
```

```
lm_eval   --model vllm   --model_args pretrained="$MODEL",dtype=auto,max_model_len=8192,tensor_parallel_size=2,enable_chunked_prefill=True,gpu_memory_utilization=0.6,max_num_seqs=1   --apply_chat_template   --fewshot_as_multiturn   --tasks leaderboard   --write_out   --batch_size auto   --output_path output_dir   --show_config
```

Facing the same issue. oom error for log likelihood based task. It takes a long time/get's oom for big mmmlu multilingual datasets (eg. mmmlu_bn_bd) and kind of stalls at "Running loglikelihood requests". Frustrating!

what are the flags for constraining GPU memory via the evaluator.evaluate API? even with 8x80GB GPUs i'm running out of memory even with flag HFLM max_memory_per_gpu="60GB". any idea how to set max_num_seqs, gpu_memory_utilization, or enable_chunked_prefill via the evaluate() API?