Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Hiyouga LLaMA Factory Ploting

From Leeroopedia


Knowledge Sources
Domains Visualization, Training Monitoring
Last Updated 2026-02-06 19:00 GMT

Overview

Training loss curve visualization utilities providing EMA smoothing, real-time figure generation for LLaMA Board, and post-training PNG export.

Description

This module implements three functions for training metric visualization. smooth applies an exponential moving average (EMA) with a sigmoid-weighted smoothing factor that adapts to the number of data points, following the TensorBoard smoothing convention. gen_loss_plot creates a matplotlib figure with both original and smoothed loss curves for real-time display in the LLaMA Board web UI. plot_loss reads the trainer state JSON file from a checkpoint directory, extracts step-indexed metric histories for specified keys (e.g., "loss"), and saves smoothed plots as PNG files. Both plotting functions use the "agg" backend for headless (non-interactive) rendering.

Usage

Use plot_loss after training completes to generate PNG loss curve images from the saved trainer state. Use gen_loss_plot in the LLaMA Board web UI to generate real-time loss figures during training. Use smooth directly when you need EMA smoothing for any list of scalar values.

Code Reference

Source Location

Signature

def smooth(scalars: list[float]) -> list[float]

def gen_loss_plot(trainer_log: list[dict[str, Any]]) -> "matplotlib.figure.Figure"

def plot_loss(save_dictionary: str, keys: list[str] = ["loss"]) -> None

Import

from llamafactory.extras.ploting import smooth, gen_loss_plot, plot_loss

I/O Contract

Inputs

Name Type Required Description
scalars list[float] Yes List of scalar values to smooth (for smooth)
trainer_log list[dict[str, Any]] Yes List of log entries with "current_steps" and "loss" keys (for gen_loss_plot)
save_dictionary str Yes Path to the checkpoint directory containing trainer_state.json (for plot_loss)
keys list[str] No List of metric keys to plot; defaults to ["loss"] (for plot_loss)

Outputs

Name Type Description
smoothed list[float] EMA-smoothed values (from smooth)
fig matplotlib.figure.Figure Matplotlib figure with original and smoothed loss curves (from gen_loss_plot)
training_{key}.png PNG file Saved plot image at <save_dictionary>/training_{key}.png (from plot_loss)

Usage Examples

from llamafactory.extras.ploting import plot_loss

# Generate loss plots after training
plot_loss(
    save_dictionary="/path/to/checkpoint",
    keys=["loss", "eval_loss"]
)
# Saves: /path/to/checkpoint/training_loss.png
# Saves: /path/to/checkpoint/training_eval_loss.png
from llamafactory.extras.ploting import gen_loss_plot

# Generate a real-time figure for LLaMA Board
trainer_log = [
    {"current_steps": 100, "loss": 2.5},
    {"current_steps": 200, "loss": 2.1},
    {"current_steps": 300, "loss": 1.8},
]
fig = gen_loss_plot(trainer_log)
# fig can be displayed in the web UI
from llamafactory.extras.ploting import smooth

# Apply EMA smoothing to a list of values
raw_losses = [2.5, 2.3, 2.4, 2.1, 1.9, 1.8, 1.7]
smoothed_losses = smooth(raw_losses)

Related Pages

Page Connections

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