Environment:AI4Finance Foundation FinGPT PyTorch CUDA
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, Infrastructure |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
GPU-accelerated PyTorch runtime with CUDA support for training and inference of large language models.
Description
This environment provides the core GPU-accelerated runtime used by all model training, fine-tuning, and inference implementations in FinGPT. It is built on PyTorch 2.0.1 with CUDA toolkit support, the `bitsandbytes` library for 8-bit/4-bit quantization, and `triton` (on Linux x86_64 NVIDIA systems) for kernel compilation. The stack enables mixed-precision (`fp16`) training via HuggingFace Trainer and DeepSpeed, with `device_map="auto"` for automatic multi-GPU sharding.
Usage
Use this environment for any Model Training, Fine-Tuning, LoRA injection, or Inference workflow that requires GPU acceleration. It is the mandatory prerequisite for running the Trainer_TrainingArguments, AutoModelForCausalLM_from_pretrained, model_generate, and all benchmark evaluation implementations.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Linux (x86_64) | Triton only installed on Linux x86_64; Windows requires WSL2 |
| Hardware | NVIDIA GPU | Minimum 16GB VRAM for 7B models; 40GB+ for 13B models |
| Disk | 50GB SSD | For model weights and dataset caching |
| CUDA | CUDA 11.8+ | Required by PyTorch 2.0.1 and bitsandbytes |
Dependencies
System Packages
- `cuda-toolkit` >= 11.8
- `cudnn` >= 8.6
- `nvidia-ml-py3` (for GPU memory monitoring via pynvml)
Python Packages
- `torch` >= 2.0.1
- `transformers` >= 4.32.0
- `peft` >= 0.5.0
- `bitsandbytes` >= 0.43.1
- `accelerate` >= 0.23.0
- `triton` < 3.0.0 (Linux x86_64 only)
- `sentencepiece`
- `safetensors` >= 0.3.3
- `datasets` >= 2.14.5
Credentials
The following environment variables may be set:
- `HF_TOKEN`: HuggingFace API token for gated model access (e.g., Llama-2).
- `CUDA_VISIBLE_DEVICES`: Optional GPU selection (e.g., `"5,6"`).
Quick Install
# Install core GPU ML stack
pip install torch==2.0.1 transformers>=4.32.0 peft>=0.5.0 bitsandbytes>=0.43.1 accelerate>=0.23.0 sentencepiece datasets>=2.14.5 safetensors nvidia-ml-py3
# Triton (Linux x86_64 with NVIDIA GPU only)
pip install "triton<3.0.0"
Code Evidence
GPU memory management and CUDA cache clearing from `fingpt/FinGPT_Benchmark/benchmarks/benchmarks.py:78-80`:
if torch.cuda.is_available():
torch.cuda.empty_cache()
print(f"GPU Memory after model load: {torch.cuda.memory_allocated() / 1024**3:.2f} GB")
Mixed-precision training configuration from `fingpt/FinGPT_Benchmark/train_lora.py:125-127`:
fp16=True,
# fp16_full_eval=True,
deepspeed=args.ds_config,
GPU memory monitoring via pynvml from `fingpt/FinGPT_Forecaster/app.py:61-68`:
def print_gpu_utilization():
try:
nvmlInit()
handle = nvmlDeviceGetHandleByIndex(0)
info = nvmlDeviceGetMemoryInfo(handle)
print(f"GPU memory occupied: {info.used//1024**2} MB.")
except Exception as e:
print(f"GPU utilization check failed: {e}")
Device selection and distributed setup from `fingpt/FinGPT_RAG/instruct-FinGPT/training/supervised_finetuning/main.py:181-188`:
if args.local_rank == -1:
device = torch.device("cuda")
else:
torch.cuda.set_device(args.local_rank)
device = torch.device("cuda", args.local_rank)
deepspeed.init_distributed()
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `CUDA out of memory` | Insufficient VRAM | Reduce `batch_size`, enable `gradient_checkpointing`, or use 8-bit/4-bit quantization |
| `triton ... not available` | Non-Linux or non-x86_64 platform | Triton only installed on Linux x86_64; CPU-only fallback or use WSL2 |
| `bitsandbytes ImportError` | Missing or incompatible CUDA | Install `bitsandbytes>=0.43.1` and ensure CUDA 11.8+ |
| `num_rows is zero` | Empty dataset or API key issue | Verify API keys are set; run `test_api_keys.py` diagnostic |
Compatibility Notes
- AMD GPUs (ROCm): Not officially supported; bitsandbytes and triton assume NVIDIA CUDA.
- Windows: Not officially supported for training; use WSL2 with Linux CUDA stack.
- Colab/Kaggle: Works but limited by free-tier GPU memory; use quantization fallback chain.
- Multi-GPU: Use `device_map="auto"` for inference and DeepSpeed for distributed training.
Related Pages
- Implementation:AI4Finance_Foundation_FinGPT_AutoModelForCausalLM_from_pretrained
- Implementation:AI4Finance_Foundation_FinGPT_Trainer_TrainingArguments
- Implementation:AI4Finance_Foundation_FinGPT_model_generate
- Implementation:AI4Finance_Foundation_FinGPT_test_fpb
- Implementation:AI4Finance_Foundation_FinGPT_test_fiqa
- Implementation:AI4Finance_Foundation_FinGPT_test_ner
- Implementation:AI4Finance_Foundation_FinGPT_LoraConfig_get_peft_model
- Implementation:AI4Finance_Foundation_FinGPT_deepspeed_sft_main
- Implementation:AI4Finance_Foundation_FinGPT_PeftModel_from_pretrained