Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AI4Finance Foundation FinGPT LoraConfig get peft model

From Leeroopedia
Knowledge Sources
Domains Deep_Learning, Parameter_Efficient_Finetuning
Last Updated 2026-10-18 00:00 GMT

Overview

PEFT library's LoRA configuration and injection API used across FinGPT training workflows to add low-rank adapters to pre-trained models.

Description

The LoraConfig and get_peft_model combination is the standard LoRA injection pattern used in both the Forecaster and Benchmark training pipelines. `LoraConfig` specifies the LoRA hyperparameters (rank, alpha, dropout, target modules, task type), and `get_peft_model` wraps the base model with trainable LoRA adapters.

The target modules are model-specific, determined by `lora_module_dict` in `utils.py`:

  • Forecaster (Llama-2): q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj (7 modules), r=8, alpha=16
  • Benchmark (Llama-2): q_proj, k_proj, v_proj (3 modules), r=8, alpha=32
  • Other models: chatglm2 (query_key_value), qwen (c_attn), mpt (Wqkv), etc.

Usage

Import these when you need to configure and apply LoRA adapters:

  • 'Forecaster training: Full 7-module LoRA on Llama-2-7b-chat with alpha=16.
  • Benchmark training: 3-module LoRA on attention only with alpha=32.
  • Multi-model support: Configurable target modules for 10 base models.

Code Reference

Source Location

  • Repository: FinGPT
  • File: fingpt/FinGPT_Forecaster/train_lora.py (L157-166), fingpt/FinGPT_Benchmark/train_lora.py (L145-154)
  • Helper: fingpt/FinGPT_Forecaster/utils.py (L9-16), fingpt/FinGPT_Benchmark/utils.py (L10-21)

Signature

from peft import LoraConfig, get_peft_model, TaskType

# Forecaster configuration
peft_config = LoraConfig(
    task_type=TaskType.CAUSAL_LM,
    inference_mode=False,
    r=8,
    lora_alpha=16,
    lora_dropout=0.1,
    target_modules=['q_proj', 'k_proj', 'v_proj',
                     'o_proj', 'gate_proj', 'up_proj', 'down_proj'],
    bias='none',
)
model = get_peft_model(model, peft_config)

# Benchmark configuration
peft_config = LoraConfig(
    task_type=TaskType.CAUSAL_LM,
    inference_mode=False,
    r=8,
    lora_alpha=32,
    lora_dropout=0.1,
    target_modules=['q_proj', 'k_proj', 'v_proj'],  # Model-specific
    bias='none',
)
model = get_peft_model(model, peft_config)

Import

from peft import LoraConfig, get_peft_model, TaskType

I/O Contract

Inputs

Name Type Required Description
task_type TaskType Yes CAUSAL_LM for FinGPT
inference_mode bool Yes False for training, True for inference
r int No LoRA rank (default 8)
lora_alpha int No Scaling factor (16 for Forecaster, 32 for Benchmark)
lora_dropout float No Dropout on LoRA inputs (default 0.1)
target_modules list Yes Module names to adapt (from lora_module_dict)
bias str No Bias training mode (default 'none')
model PreTrainedModel Yes Base model to wrap (passed to get_peft_model)

Outputs

Name Type Description
return value PeftModel Base model with trainable LoRA adapters

Usage Examples

Forecaster LoRA Configuration

from peft import LoraConfig, get_peft_model, TaskType
from utils import lora_module_dict

base_model = "llama2"
peft_config = LoraConfig(
    task_type=TaskType.CAUSAL_LM,
    inference_mode=False,
    r=8, lora_alpha=16, lora_dropout=0.1,
    target_modules=lora_module_dict[base_model],
    bias='none',
)
model = get_peft_model(model, peft_config)
model.print_trainable_parameters()
# trainable params: 19,096,064 || all params: 6,761,093,888
# trainable%: 0.2824

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment