Environment:AI4Finance Foundation FinGPT HuggingFace Transformers
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, NLP |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
HuggingFace Transformers library (>=4.32.0) providing `AutoModelForCausalLM`, `AutoTokenizer`, `Trainer`, `TrainingArguments`, and `BitsAndBytesConfig` for model loading, training, and quantization.
Description
This environment covers the Transformers library dependency used across all FinGPT training and inference code. It provides the `AutoModelForCausalLM.from_pretrained` API for loading base models, `Trainer` and `TrainingArguments` for supervised fine-tuning, `DataCollatorForSeq2Seq` for batch collation, `BitsAndBytesConfig` for 4-bit quantization, and `TensorBoardCallback` for logging. The minimum version constraint is `>=4.32.0` (root `requirements.txt`); the RAG subproject pins `==4.34.0`.
Usage
Use this environment for any model loading (`from_pretrained`), tokenization, training via HuggingFace `Trainer`, or quantized inference. Required by benchmark training, forecaster training, benchmark evaluation, and inference implementations.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Any | Cross-platform |
| Hardware | CPU or GPU | GPU needed for training; CPU works for small inference |
| Disk | 1-50GB | For model weights and cache |
Dependencies
Python Packages
- `transformers` >= 4.32.0
- `tokenizers` >= 0.14.0
- `safetensors` >= 0.3.3
- `huggingface-hub` >= 0.16.4
- `torch` >= 2.0.1
- `peft` >= 0.5.0
- `accelerate` >= 0.23.0
Credentials
- `HF_TOKEN`: Required for gated models (see Environment:AI4Finance_Foundation_FinGPT_HuggingFace_Hub).
Quick Install
pip install "transformers>=4.32.0" tokenizers>=0.14.0 safetensors>=0.3.3 huggingface-hub>=0.16.4 torch>=2.0.1 peft>=0.5.0 accelerate>=0.23.0
Code Evidence
Transformer imports from `fingpt/FinGPT_Benchmark/train_lora.py:10-17`:
from transformers import (
AutoTokenizer,
AutoModel,
AutoModelForCausalLM,
TrainingArguments,
Trainer,
DataCollatorForSeq2Seq
)
BitsAndBytesConfig for 4-bit quantization from `fingpt/FinGPT_Benchmark/benchmarks/benchmarks.py:53-59`:
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",
)
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `trust_remote_code=True required` | Custom model architecture | Pass `trust_remote_code=True` to `from_pretrained` |
| `tokenizer.pad_token is None` | Model lacks pad token | Auto-set via `tokenizer.add_special_tokens({'pad_token': '[PAD]'})` |
| `KeyError: 'out_text_0'` | Template count mismatch | Ensure `sentiment_templates.txt` has all expected templates |
Compatibility Notes
- Version pinning: Root requirements specify `>=4.32.0`; RAG subproject pins `==4.34.0`. Use the pinned version for RAG workflows.
- Qwen models: Require special token override (`eos_token_id` and `pad_token_id`).
- MPT models: Require `padding_side="right"` and disable `gradient_checkpointing`.
Related Pages
- Implementation:AI4Finance_Foundation_FinGPT_AutoModelForCausalLM_from_pretrained
- Implementation:AI4Finance_Foundation_FinGPT_Trainer_TrainingArguments
- Implementation:AI4Finance_Foundation_FinGPT_tokenize
- Implementation:AI4Finance_Foundation_FinGPT_model_generate
- Implementation:AI4Finance_Foundation_FinGPT_GenerationEvalCallback