vllm-project / vllm

A high-throughput and memory-efficient inference and serving engine for LLMs
https://docs.vllm.ai
Apache License 2.0
29.81k stars 4.5k forks source link

[Bug]: OOM when running llama3.1-8B-Instruct #8372

Open UrielShapiro opened 1 month ago

UrielShapiro commented 1 month ago

Your current environment

Hello, I'm trying to download llama3.1-8B-Instruct to my PC and each time i try, i get the following error:

[rank0]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 1002.00 MiB. GPU 0 has a total capacity of 15.59 GiB of which 940.12 MiB is free. Including non-PyTorch memory, this process has 14.30 GiB memory in use. Of the allocated memory 14.01 GiB is allocated by PyTorch, and 15.49 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)

The code i'm running to download the model:

from vllm import LLM

llm = LLM(model="meta-llama/Meta-Llama-3.1-8B-Instruct") 

I have CUDA 12.6, cuDNN and the latest GPU drivers installed. This is the output of nvidia-smi when trying to download the model:

Wed Sep 11 18:17:23 2024       
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 560.35.03              Driver Version: 560.35.03      CUDA Version: 12.6     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 4080 ...    On  |   00000000:01:00.0  On |                  N/A |
| 31%   45C    P0             38W /  320W |     797MiB /  16376MiB |      0%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI        PID   Type   Process name                              GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A      1283      G   /usr/lib/xorg/Xorg                            178MiB |
|    0   N/A  N/A      2216      G   /usr/bin/gnome-shell                           88MiB |
|    0   N/A  N/A      6072      G   ...irefox/4848/usr/lib/firefox/firefox          0MiB |
|    0   N/A  N/A     41029      G   ...erProcess --variations-seed-version         27MiB |
+-----------------------------------------------------------------------------------------+

I got RTX 4080 SUPER 16GB, i7-14700F, 64GB RAM. I'm pretty sure my setup is strong enough for this model.

I can say it confidently because i tried to run it using ollama and it worked perfectly.

I did a lot of searching on how to make it work but nothing helped. I tried setting the environment variable PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True and using --gpu-memory-utilization (when running using the vllm serve command) with numbers from 0.6 to 0.9.

I've added the output of python collect_env.py below.

Thank you in advance!

The output of `python collect_env.py` ```text Collecting environment information... PyTorch version: 2.4.0+cu121 Is debug build: False CUDA used to build PyTorch: 12.1 ROCM used to build PyTorch: N/A OS: Ubuntu 22.04.4 LTS (x86_64) GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 Clang version: Could not collect CMake version: Could not collect Libc version: glibc-2.35 Python version: 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-6.8.0-40-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: 11.5.119 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4080 SUPER Nvidia driver version: 560.35.03 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.9.4.0 /usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.4.0 /usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.4.0 /usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.4.0 /usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.4.0 /usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.4.0 /usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.4.0 /usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.4.0 HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: True CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 28 On-line CPU(s) list: 0-27 Vendor ID: GenuineIntel Model name: Intel(R) Core(TM) i7-14700F CPU family: 6 Model: 183 Thread(s) per core: 2 Core(s) per socket: 20 Socket(s): 1 Stepping: 1 CPU max MHz: 5400.0000 CPU min MHz: 800.0000 BogoMIPS: 4224.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 768 KiB (20 instances) L1i cache: 1 MiB (20 instances) L2 cache: 28 MiB (11 instances) L3 cache: 33 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-27 Vulnerability Gather data sampling: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Reg file data sampling: Mitigation; Clear Register File Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Versions of relevant libraries: [pip3] numpy==1.26.4 [pip3] nvidia-cublas-cu12==12.1.3.1 [pip3] nvidia-cuda-cupti-cu12==12.1.105 [pip3] nvidia-cuda-nvrtc-cu12==12.1.105 [pip3] nvidia-cuda-runtime-cu12==12.1.105 [pip3] nvidia-cudnn-cu12==9.1.0.70 [pip3] nvidia-cufft-cu12==11.0.2.54 [pip3] nvidia-curand-cu12==10.3.2.106 [pip3] nvidia-cusolver-cu12==11.4.5.107 [pip3] nvidia-cusparse-cu12==12.1.0.106 [pip3] nvidia-ml-py==12.560.30 [pip3] nvidia-nccl-cu12==2.20.5 [pip3] nvidia-nvjitlink-cu12==12.6.68 [pip3] nvidia-nvtx-cu12==12.1.105 [pip3] pyzmq==26.2.0 [pip3] torch==2.4.0 [pip3] torchvision==0.19.0 [pip3] transformers==4.44.2 [pip3] triton==3.0.0 [conda] Could not collect ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: 0.6.0@32e7db25365415841ebc7c4215851743fbb1bad1 vLLM Build Flags: CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X 0-27 0 N/A Legend: X = Self SYS = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI) NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node PHB = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU) PXB = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge) PIX = Connection traversing at most a single PCIe bridge NV# = Connection traversing a bonded set of # NVLinks```

🐛 Describe the bug

When downloading a model i get this error:

[W911 18:28:06.876627027 CUDAAllocatorConfig.h:28] Warning: expandable_segments not supported on this platform (function operator())
[rank0]: Traceback (most recent call last):
[rank0]:   File "/home/llm-user/Desktop/VSCode/LLM/8BTest.py", line 31, in <module>
[rank0]:     llm = LLM(model="meta-llama/Meta-Llama-3.1-8B-Instruct")  # Name or path of your model
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/entrypoints/llm.py", line 177, in __init__
[rank0]:     self.llm_engine = LLMEngine.from_engine_args(
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 538, in from_engine_args
[rank0]:     engine = cls(
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/engine/llm_engine.py", line 305, in __init__
[rank0]:     self.model_executor = executor_class(
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/executor/executor_base.py", line 47, in __init__
[rank0]:     self._init_executor()
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/executor/gpu_executor.py", line 40, in _init_executor
[rank0]:     self.driver_worker.load_model()
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/worker/worker.py", line 182, in load_model
[rank0]:     self.model_runner.load_model()
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/worker/model_runner.py", line 917, in load_model
[rank0]:     self.model = get_model(model_config=self.model_config,
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/model_executor/model_loader/__init__.py", line 19, in get_model
[rank0]:     return loader.load_model(model_config=model_config,
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/model_executor/model_loader/loader.py", line 341, in load_model
[rank0]:     model = _initialize_model(model_config, self.load_config,
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/model_executor/model_loader/loader.py", line 170, in _initialize_model
[rank0]:     return build_model(
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/model_executor/model_loader/loader.py", line 155, in build_model
[rank0]:     return model_class(config=hf_config,
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/model_executor/models/llama.py", line 400, in __init__
[rank0]:     self.lm_head = ParallelLMHead(
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/model_executor/layers/vocab_parallel_embedding.py", line 443, in __init__
[rank0]:     super().__init__(num_embeddings, embedding_dim, params_dtype,
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/model_executor/layers/vocab_parallel_embedding.py", line 260, in __init__
[rank0]:     self.linear_method.create_weights(self,
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/vllm/model_executor/layers/vocab_parallel_embedding.py", line 28, in create_weights
[rank0]:     weight = Parameter(torch.empty(sum(output_partition_sizes),
[rank0]:   File "/home/llm-user/.local/lib/python3.10/site-packages/torch/utils/_device.py", line 79, in __torch_function__
[rank0]:     return func(*args, **kwargs)
[rank0]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 1002.00 MiB. GPU 0 has a total capacity of 15.59 GiB of which 940.12 MiB is free. Including non-PyTorch memory, this process has 14.30 GiB memory in use. Of the allocated memory 14.01 GiB is allocated by PyTorch, and 15.49 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)

Code to replicate the issue:

from vllm import LLM

llm = LLM(model="meta-llama/Meta-Llama-3.1-8B-Instruct") 

Before submitting a new issue...

vipulgote1999 commented 1 month ago

Hi , Few suggestion you should use quantize version...llama3.1 8B itself has size of over 16GB....so it is not going to fit in your gpu

Still u can use it with few parameters cpu offloding in GB, quantization AWQ/8Bit Bits and Bytes /GGUF, 32k or less max sequence length, etc.