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 Trainer TrainingArguments

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

Overview

HuggingFace Transformers' training loop API used across FinGPT training workflows for managed distributed training with DeepSpeed, gradient accumulation, and mixed-precision.

Description

The Trainer and TrainingArguments combination provides the managed training loop for both the Forecaster and Benchmark pipelines. `TrainingArguments` specifies all hyperparameters (batch size, learning rate, epochs, scheduler, fp16, DeepSpeed config, evaluation strategy), while `Trainer` handles the training loop, gradient accumulation, distributed training, logging (wandb/TensorBoard), and checkpointing.

The Forecaster uses a custom `GenerationEvalCallback` for ROUGE/accuracy evaluation during training. The Benchmark uses `TensorBoardCallback` for logging. Both use `DataCollatorForSeq2Seq` for dynamic padding with `label_pad_token_id=-100`.

Usage

Import these when you need to run managed distributed training:

  • Forecaster training: 8 epochs, lr=1e-4, gradient_accumulation=8, DeepSpeed config, GenerationEvalCallback.
  • Benchmark training: 8 epochs, lr=1e-4, gradient_accumulation=8, DeepSpeed config, TensorBoardCallback.
  • Custom callbacks: GenerationEvalCallback for text generation evaluation during training.

Code Reference

Source Location

  • Repository: FinGPT
  • File: fingpt/FinGPT_Forecaster/train_lora.py (L126-191), fingpt/FinGPT_Benchmark/train_lora.py (L112-182)

Signature

from transformers import TrainingArguments, Trainer, DataCollatorForSeq2Seq

training_args = TrainingArguments(
    output_dir=f'finetuned_models/{run_name}_{timestamp}',
    num_train_epochs=8,
    per_device_train_batch_size=4,
    per_device_eval_batch_size=4,
    gradient_accumulation_steps=8,
    learning_rate=1e-4,
    warmup_ratio=0.05,
    lr_scheduler_type='linear',
    fp16=True,
    deepspeed='config.json',
    evaluation_strategy='steps',
    eval_steps=0.1,
    save_steps=0.1,
    remove_unused_columns=False,
    report_to='wandb',
    run_name=run_name,
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset['train'],
    eval_dataset=dataset['test'],
    tokenizer=tokenizer,
    data_collator=DataCollatorForSeq2Seq(
        tokenizer, padding=True,
        return_tensors="pt",
        label_pad_token_id=-100,
    ),
    callbacks=[...],
)
trainer.train()
model.save_pretrained(training_args.output_dir)

Import

from transformers import TrainingArguments, Trainer, DataCollatorForSeq2Seq

I/O Contract

Inputs

Name Type Required Description
model PeftModel Yes LoRA-wrapped model to train
args TrainingArguments Yes Hyperparameter configuration
train_dataset Dataset Yes Tokenized training data
eval_dataset Dataset Yes Tokenized evaluation data
tokenizer AutoTokenizer Yes Tokenizer for padding
data_collator DataCollatorForSeq2Seq Yes Dynamic padding with label masking
callbacks list No Custom callbacks (GenerationEvalCallback, TensorBoardCallback)

Outputs

Name Type Description
checkpoints files Saved to output_dir every save_steps
logs wandb/TensorBoard Training metrics logged externally
adapter weights files LoRA adapter saved via model.save_pretrained(output_dir)

Usage Examples

Forecaster Training with GenerationEvalCallback

from transformers import TrainingArguments, Trainer, DataCollatorForSeq2Seq

training_args = TrainingArguments(
    output_dir=f'finetuned_models/forecaster_{timestamp}',
    num_train_epochs=8,
    per_device_train_batch_size=4,
    gradient_accumulation_steps=8,
    learning_rate=1e-4,
    warmup_ratio=0.05,
    fp16=True,
    deepspeed='./config_new.json',
    evaluation_strategy='steps',
    eval_steps=0.1,
    report_to='wandb',
)

trainer = Trainer(
    model=model,
    args=training_args,
    train_dataset=dataset['train'],
    eval_dataset=dataset['test'],
    tokenizer=tokenizer,
    data_collator=DataCollatorForSeq2Seq(
        tokenizer, padding=True, return_tensors="pt",
    ),
    callbacks=[
        GenerationEvalCallback(
            eval_dataset=eval_subset,
            ignore_until_epoch=round(0.3 * 8),
        )
    ],
)
trainer.train()
model.save_pretrained(training_args.output_dir)

Related Pages

Implements Principle

Uses Heuristic

Requires Environment

Page Connections

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