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 deepspeed sft main

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

Overview

DeepSpeed-Chat supervised fine-tuning entry point used in the FinGPT RAG instruction-tuning pipeline for distributed model training with custom LoRA injection.

Description

The main function in the DeepSpeed-Chat SFT module is the CLI entry point for supervised fine-tuning in the RAG pipeline. It initializes the DeepSpeed engine, creates the model via `create_hf_model`, optionally injects LoRA via `convert_linear_layer_to_lora`, creates the prompt dataset via `create_prompt_dataset`, and runs the training loop with DeepSpeed's optimizer and scheduler.

Supports Llama models (with `LlamaForCausalLM` and `LlamaTokenizer`) and other models (with `AutoModelForCausalLM` and `AutoTokenizer`). Key CLI arguments include `--model_name_or_path`, `--data_path`, `--lora_dim`, `--lora_module_name`, and `--only_optimize_lora`.

Usage

Run this as a CLI script when you need to perform DeepSpeed-Chat SFT:

  • RAG instruction tuning: Fine-tuning models on financial instruction datasets.
  • Custom LoRA injection: Using DeepSpeed-native LoRA rather than PEFT library.
  • ZeRO Stage 3 training: Training very large models with parameter partitioning.

Code Reference

Source Location

  • Repository: FinGPT
  • File: fingpt/FinGPT_RAG/instruct-FinGPT/training/supervised_finetuning/main.py
  • Lines: L177-259

Signature

def main() -> None
    # Parses CLI args, initializes DeepSpeed, creates model,
    # injects LoRA, creates dataset, trains, saves

Import

# Run as CLI script:
# deepspeed --num_gpus N main.py --model_name_or_path ... --data_path ...

I/O Contract

Inputs (CLI Args)

Name Type Required Description
--model_name_or_path str Yes HuggingFace model ID or local path
--data_path list No Dataset paths (default ['Dahoas/rm-static'])
--data_split str No Train/val/test split (default '6,2,2')
--per_device_train_batch_size int No Batch size per GPU (default 16)
--max_seq_len int No Max sequence length (default 512)
--learning_rate float No Learning rate (default 1e-3)
--num_train_epochs int No Training epochs (default 1)
--lora_dim int No LoRA rank (0 disables LoRA)
--lora_module_name str No Module name pattern for LoRA injection
--only_optimize_lora bool No Freeze all non-LoRA parameters
--zero_stage int No ZeRO optimization stage (0-3)

Outputs

Name Type Description
model checkpoint files Saved via save_hf_format / save_zero_three_model
DeepSpeed checkpoint DeepSpeed engine state

Usage Examples

Run DeepSpeed SFT with LoRA

deepspeed --num_gpus 4 main.py \
    --model_name_or_path meta-llama/Llama-2-7b-hf \
    --data_path "FinGPT/fingpt-fpb" \
    --lora_dim 8 \
    --lora_module_name "q_proj" \
    --only_optimize_lora \
    --per_device_train_batch_size 4 \
    --learning_rate 1e-3 \
    --num_train_epochs 3 \
    --zero_stage 2

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

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