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

Principle:AI4Finance Foundation FinGPT Distributed Training

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

Overview

A training paradigm that distributes model states, gradients, and optimizer states across multiple GPUs and nodes to enable training of large models that exceed single-GPU memory.

Description

Distributed training in FinGPT uses HuggingFace's `Trainer` API with DeepSpeed integration. The `Trainer` abstracts the training loop (forward pass, backward pass, optimizer step, logging, checkpointing) while DeepSpeed provides memory optimizations through ZeRO (Zero Redundancy Optimizer) stages. The training configuration includes gradient accumulation, mixed-precision (fp16) training, learning rate scheduling with warmup, and periodic evaluation.

Key components include `TrainingArguments` for hyperparameter specification, `DataCollatorForSeq2Seq` for dynamic padding, and callback systems for custom evaluation (e.g., `GenerationEvalCallback` for ROUGE/accuracy metrics during Forecaster training).

Usage

Use this principle when:

  • Training models larger than single-GPU memory: 7B-13B parameter models require ZeRO optimization.
  • Multi-GPU training: Distributing training across available GPUs with DeepSpeed.
  • Managed training loops: Using `Trainer` for logging, checkpointing, and evaluation without custom PyTorch loops.

Distributed training is used in both the Forecaster and Benchmark training pipelines.

Theoretical Basis

DeepSpeed ZeRO partitions model training states across data-parallel processes:

  • Stage 1: Partitions optimizer states (8× memory reduction)
  • Stage 2: Partitions optimizer states + gradients (4× memory reduction, 8× with Stage 1)
  • Stage 3: Partitions optimizer states + gradients + parameters (N× reduction, N = GPU count)

The effective batch size is:

Beff=Bper_device×NGPUs×Gaccum

Mixed-precision (fp16) training uses fp16 for forward/backward passes and fp32 for master weights and optimizer states, halving memory for activations.

Key training hyperparameters:

# Abstract: distributed training configuration
TrainingArguments(
    per_device_train_batch_size=4,
    gradient_accumulation_steps=8,  # effective batch = 4 * N_gpu * 8
    learning_rate=1e-4,
    warmup_ratio=0.05,
    lr_scheduler_type="linear",
    fp16=True,
    deepspeed="config.json",  # ZeRO config
)

Practical Guide

  • Use `deepspeed` config for ZeRO Stage 2 (AdamW optimizer) with large models.
  • Set `gradient_accumulation_steps=8` to simulate larger effective batch sizes.
  • Use `evaluation_strategy="steps"` with `eval_steps=0.1` to evaluate at 10% intervals.
  • Configure wandb for experiment tracking (`report_to='wandb'`).
  • Clear CUDA cache (`torch.cuda.empty_cache()`) before and after training.

Related Pages

Implemented By

Uses Heuristic

Page Connections

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