Implementation:Hiyouga LLaMA Factory WebUI Train Component
| Knowledge Sources | |
|---|---|
| Domains | Web UI, Machine Learning, Training Configuration |
| Last Updated | 2026-02-06 19:00 GMT |
Overview
The comprehensive training configuration tab component that builds the Gradio-based form for all training parameter controls, collapsible configuration sections, and action buttons in the LLaMA-Factory WebUI.
Description
train.py (in webui/components) implements the create_train_tab function, which constructs the largest and most feature-rich UI component in LLaMA-Factory's web interface. The function builds an extensive Gradio form organized into the following sections:
- Main training parameters (top row): Training stage dropdown (PT/SFT/RM/PPO/DPO/KTO), dataset directory, dataset multiselect, and a data preview box.
- Core hyperparameters: Learning rate, epochs, max gradient norm, max samples, and compute type (bf16/fp16/fp32/pure_bf16).
- Training sliders: Cutoff length (4-131072), batch size, gradient accumulation steps, validation size, and LR scheduler type.
- Extra settings accordion: Logging steps, save steps, warmup steps, NEFTune alpha, extra JSON args, packing, neat packing, train-on-prompt, mask history, resize vocab, LLaMA Pro, enable thinking, and report-to integration.
- Freeze accordion: Freeze trainable layers, modules, and extra modules configuration.
- LoRA accordion: LoRA rank, alpha, dropout, LoRA+ LR ratio, rsLoRA, DoRA, PiSSA, target modules, and additional target modules.
- RLHF accordion: Preference beta, FTX weight, preference loss function (sigmoid/hinge/IPO/KTO pair/ORPO/SimPO), reward model selection, PPO score normalization, and reward whitening.
- Multimodal accordion: Freeze vision tower, multi-modal projector, language model, and image/video pixel constraints.
- GaLore accordion: GaLore enable, rank, update interval, scale, and target modules.
- APOLLO accordion: APOLLO enable, rank, update interval, scale, and target.
- BAdam accordion: BAdam enable, mode (layer/ratio), switch mode, switch interval, and update ratio.
- SwanLab accordion: SwanLab enable, project, run name, workspace, API key, and mode.
- Action buttons: Command preview, save args, load args, start training, and stop training.
- Output section: Output directory, config path, device count, DeepSpeed stage/offload, progress bar, output log, and loss viewer plot.
The function wires all interactive elements to the Engine runner methods (preview_train, run_train, set_abort, save_args, load_args, check_output_dir) and connects dynamic event handlers for dataset listing, output directory management, checkpoint listing, and configuration persistence.
Usage
This function is called once during WebUI initialization to construct the training tab. It returns a dictionary mapping element names to Gradio components, which are then used by the Engine for state management and event handling.
Code Reference
Source Location
- Repository: Hiyouga_LLaMA_Factory
- File: src/llamafactory/webui/components/train.py
- Lines: 1-447
Signature
def create_train_tab(engine: "Engine") -> dict[str, "Component"]
Import
from llamafactory.webui.components.train import create_train_tab
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| engine | Engine | Yes | The WebUI engine instance providing the manager (for element registration) and runner (for training execution) |
Outputs
| Name | Type | Description |
|---|---|---|
| elem_dict | dict[str, Component] | Dictionary mapping element identifier strings to their corresponding Gradio Component instances; includes all training parameters, buttons, and output elements |
Usage Examples
# Creating the training tab during WebUI initialization
from llamafactory.webui.components.train import create_train_tab
elem_dict = create_train_tab(engine)
# Access specific elements
training_stage = elem_dict["training_stage"]
learning_rate = elem_dict["learning_rate"]
start_btn = elem_dict["start_btn"]
output_box = elem_dict["output_box"]
loss_viewer = elem_dict["loss_viewer"]
Related Pages
- Hiyouga_LLaMA_Factory_WebUI_Runner - Runner class that handles training execution triggered by this component's buttons
- Hiyouga_LLaMA_Factory_WebUI_Locales - Localization strings used for labeling all UI elements in this component