Loading in 4bit mode on 8GB VRAM - very slow inference

#8
by rc450 - opened

I'm trying to use this model on NVIDIA GeForce RTX 3070 Laptop GPU with 8 GB of VRAM. Since this is 7B model and I'm loading it in 4bit mode I was expecting that it fully fits into 8GB VRAM. However in Windows task manager I see that VRAM is fully used, and additionally ~5 GB of RAM is used. But what is the most problematic - it is very slow inference. Even simple prompts may take up to 40-60 seconds.

Can there be any explanation for that? Am I missing some configuration? Any recommendation?

from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
device = "cuda"
model_path = "ibm-granite/granite-4.0-h-tiny"
tokenizer = AutoTokenizer.from_pretrained(model_path)
quantization_config = BitsAndBytesConfig(load_in_4bit=True)

model = AutoModelForCausalLM.from_pretrained(
model_path,
quantization_config=quantization_config,
device_map=device,
dtype=None,
)
print(model.hf_device_map) # ->>> this prints: {'': device(type='cuda')}

I loaded ibm/granite-4-h-tiny via LM Studio, on single NVIDIA 5060 Ti 16GB.
When setting context window to 1M, I got 5.19 tok/s.
When setting context window to 256K, I got 158.17 tok/s.
AFAIK, if the output tps dropped, it means vram is exhausted, data is transferred between system ram and vram. Lower the value of context window to make all data fully fit in vram, which improves tps.

Sign up or log in to comment