Implementation:Hiyouga LLaMA Factory WebUI Export Component
| Knowledge Sources | |
|---|---|
| Domains | WebUI, Model Export, Quantization, Gradio Components |
| Last Updated | 2026-02-06 19:00 GMT |
Overview
Model export tab component that enables users to export fine-tuned models with optional GPTQ quantization directly from the WebUI.
Description
The export.py module provides two main pieces of functionality. The save_model generator function validates export inputs (model name, path, export directory, quantization settings), constructs the export arguments dictionary including optional GPTQ quantization at 2, 3, 4, or 8 bits, invokes export_model from the training tuner, and performs GPU memory cleanup via torch_gc. The create_export_tab function assembles the Gradio UI with export size slider, GPTQ quantization bit dropdown, quantization dataset path, device selection (cpu/auto), legacy format checkbox, export directory, Hub model ID, and extra args textbox. A can_quantize helper disables quantization when checkpoint adapters are selected.
Usage
Use this component when building the main WebUI to provide model export capabilities. It is instantiated within create_ui in the interface module as the "Export" tab (hidden in demo mode).
Code Reference
Source Location
- Repository: Hiyouga_LLaMA_Factory
- File: src/llamafactory/webui/components/export.py
- Lines: 1-169
Signature
GPTQ_BITS = ["8", "4", "3", "2"]
def can_quantize(checkpoint_path: str | list[str]) -> "gr.Dropdown": ...
def save_model(
lang: str,
model_name: str,
model_path: str,
finetuning_type: str,
checkpoint_path: str | list[str],
template: str,
export_size: int,
export_quantization_bit: str,
export_quantization_dataset: str,
export_device: str,
export_legacy_format: bool,
export_dir: str,
export_hub_model_id: str,
extra_args: str,
) -> Generator[str, None, None]: ...
def create_export_tab(engine: "Engine") -> dict[str, "Component"]: ...
Import
from llamafactory.webui.components.export import create_export_tab, save_model, can_quantize
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| engine | Engine | Yes | The WebUI engine instance providing access to Manager for retrieving top-level element references |
| lang | str | Yes (save_model) | UI language code for localized alert messages |
| model_name | str | Yes (save_model) | Name of the model to export |
| model_path | str | Yes (save_model) | Filesystem or hub path to the base model |
| finetuning_type | str | Yes (save_model) | Finetuning method (lora, full, freeze, etc.) |
| checkpoint_path | str or list[str] | No (save_model) | Path(s) to adapter checkpoint(s) |
| export_quantization_bit | str | No (save_model) | GPTQ quantization bits ("none", "2", "3", "4", "8") |
| export_dir | str | Yes (save_model) | Directory to write the exported model |
Outputs
| Name | Type | Description |
|---|---|---|
| elem_dict | dict[str, Component] | Dictionary of named Gradio components: export_size, export_quantization_bit, export_quantization_dataset, export_device, export_legacy_format, export_dir, export_hub_model_id, extra_args, export_btn, info_box |
| status (save_model) | Generator[str] | Yields progress messages ("Exporting model...", "Model exported successfully.") |
Usage Examples
# Adding the export tab to the main UI (non-demo mode only)
from llamafactory.webui.components.export import create_export_tab
if not demo_mode:
with gr.Tab("Export"):
engine.manager.add_elems("export", create_export_tab(engine))
Related Pages
- Hiyouga_LLaMA_Factory_WebUI_Interface - Main interface that conditionally includes the export tab
- Hiyouga_LLaMA_Factory_WebUI_Common - Provides get_save_dir and load_config used during export
- Hiyouga_LLaMA_Factory_WebUI_Top_Component - Provides model/checkpoint selection inputs consumed by export