Heuristic:AI4Finance Foundation FinGPT Quantization Fallback Chain
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Deep_Learning, Memory_Management |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Progressively fall back from 8-bit → 4-bit → full precision model loading to handle varying GPU memory constraints during benchmark evaluation.
Description
The benchmark evaluation harness (`benchmarks.py`) implements a three-tier quantization fallback chain when loading models. It first attempts 8-bit quantization (`load_in_8bit=True`) for the best speed/memory trade-off. If that fails (e.g., insufficient VRAM or bitsandbytes issue), it falls back to 4-bit NF4 quantization with double quantization and fp16 compute dtype. If 4-bit also fails, it loads in full precision with `low_cpu_mem_usage=True` and `device_map="auto"` for automatic sharding. This chain ensures models can be loaded across diverse hardware.
Usage
Use this heuristic when VRAM is uncertain or limited, or when deploying benchmark evaluation across heterogeneous GPU types. The fallback chain automatically adapts to available memory.
The Insight (Rule of Thumb)
- Action: Attempt model loading in order: 8-bit → 4-bit NF4 → full precision with memory optimization.
- Value: 8-bit (`load_in_8bit=True`); 4-bit (`load_in_4bit=True`, `bnb_4bit_quant_type="nf4"`, `bnb_4bit_use_double_quant=True`, `bnb_4bit_compute_dtype=torch.float16`); full (`low_cpu_mem_usage=True`).
- Trade-off: 8-bit has best quality/speed; 4-bit uses ~50% less VRAM with slight quality loss; full precision is slowest but highest quality.
- Compatibility: Requires `bitsandbytes>=0.43.1` for 8-bit/4-bit. All paths use `device_map="auto"` and `offload_folder="./offload"`.
Reasoning
Different GPU types (V100 32GB, A100 40GB/80G, consumer 24GB) have vastly different VRAM. A 13B model in full precision requires ~26GB just for weights. 8-bit quantization halves this to ~13GB, and 4-bit NF4 further reduces to ~7GB. The fallback chain ensures evaluation can proceed on any GPU that can fit at least the 4-bit version. Double quantization (`bnb_4bit_use_double_quant=True`) quantizes the quantization constants themselves, saving additional memory.
Code Evidence
8-bit first attempt from `fingpt/FinGPT_Benchmark/benchmarks/benchmarks.py:39-48`:
try:
print("Attempting to load model with 8-bit quantization...")
model = AutoModelForCausalLM.from_pretrained(
model_name, trust_remote_code=True,
load_in_8bit=True,
device_map="auto",
offload_folder=offload_folder,
)
4-bit fallback from `fingpt/FinGPT_Benchmark/benchmarks/benchmarks.py:50-65`:
except Exception as e:
print(f"8-bit loading failed: {e}")
from transformers import BitsAndBytesConfig
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_compute_dtype=torch.float16,
bnb_4bit_use_double_quant=True,
bnb_4bit_quant_type="nf4",
)
model = AutoModelForCausalLM.from_pretrained(
model_name, trust_remote_code=True,
quantization_config=bnb_config,
device_map="auto",
offload_folder=offload_folder,
)
Full precision fallback from `fingpt/FinGPT_Benchmark/benchmarks/benchmarks.py:67-75`:
except Exception as e2:
print(f"4-bit loading failed: {e2}")
model = AutoModelForCausalLM.from_pretrained(
model_name, trust_remote_code=True,
device_map="auto",
offload_folder=offload_folder,
low_cpu_mem_usage=True,
)