Implementation:Hiyouga LLaMA Factory WebUI Engine: Difference between revisions
Auto-imported from implementations/Hiyouga_LLaMA_Factory_WebUI_Engine.md |
Sync from local file |
||
| Line 110: | Line 110: | ||
== Related Pages == | == Related Pages == | ||
* [[Hiyouga_LLaMA_Factory_WebUI_Interface]] - Creates Engine instances for both full UI and web demo | * [[Implementation:Hiyouga_LLaMA_Factory_WebUI_Interface]] - Creates Engine instances for both full UI and web demo | ||
* [[Hiyouga_LLaMA_Factory_WebUI_Common]] - Provides create_ds_config, load_config, get_time used by Engine | * [[Implementation:Hiyouga_LLaMA_Factory_WebUI_Common]] - Provides create_ds_config, load_config, get_time used by Engine | ||
* [[Hiyouga_LLaMA_Factory_WebUI_Control]] - Controller callbacks invoked by components managed through Engine | * [[Implementation:Hiyouga_LLaMA_Factory_WebUI_Control]] - Controller callbacks invoked by components managed through Engine | ||
* [[Hiyouga_LLaMA_Factory_WebUI_Top_Component]] - Top panel registered under "top" namespace in Engine.manager | * [[Implementation:Hiyouga_LLaMA_Factory_WebUI_Top_Component]] - Top panel registered under "top" namespace in Engine.manager | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
[[Category:Implementations]] | [[Category:Implementations]] | ||
Latest revision as of 10:41, 27 September 2026
| Knowledge Sources | |
|---|---|
| Domains | WebUI, Orchestration, State Management |
| Last Updated | 2026-02-06 19:00 GMT |
Overview
Central engine class that orchestrates all WebUI subsystems including component management, training execution, chat inference, and application lifecycle.
Description
The engine.py module defines the Engine class, which serves as the core orchestrator for the LLaMA Factory WebUI. On initialization, it creates three key subsystems: a Manager for component registration and lookup, a Runner for managing training and evaluation processes, and a WebChatModel (chatter) for chat inference. In non-demo mode, it also generates DeepSpeed configuration files. The class provides resume() to restore UI state from saved user configuration and detect running training processes, change_lang() to dynamically update all component labels using the LOCALES dictionary, and _update_component() to batch-update Gradio components from a dictionary of property mappings.
Usage
Use this class when initializing the WebUI application. It is instantiated by create_ui and create_web_demo in the interface module and serves as the shared context passed to all tab creation functions.
Code Reference
Source Location
- Repository: Hiyouga_LLaMA_Factory
- File: src/llamafactory/webui/engine.py
- Lines: 1-83
Signature
class Engine:
def __init__(self, demo_mode: bool = False, pure_chat: bool = False) -> None: ...
def _update_component(
self, input_dict: dict[str, dict[str, Any]]
) -> dict["Component", "Component"]: ...
def resume(self): ...
def change_lang(self, lang: str): ...
Import
from llamafactory.webui.engine import Engine
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| demo_mode | bool | No | If True, disables config persistence and DeepSpeed config creation (default: False) |
| pure_chat | bool | No | If True, creates a minimal chat-only interface without training/eval/export tabs (default: False) |
| lang (change_lang) | str | Yes | Language code ("en", "ru", "zh", "ko", "ja") for UI localization |
Outputs
| Name | Type | Description |
|---|---|---|
| self.manager | Manager | Component registry for registering and retrieving Gradio elements by ID |
| self.runner | Runner | Training/evaluation process manager with run, preview, monitor, and abort methods |
| self.chatter | WebChatModel | Chat inference engine with load_model, unload_model, append, and stream methods |
| resume() | Generator[dict] | Yields dictionaries mapping Component instances to updated Component instances with initial values |
| change_lang() | dict[Component, Component] | Dictionary mapping each localized component to its updated version with new language labels |
Usage Examples
# Creating an engine for the full WebUI
from llamafactory.webui.engine import Engine
engine = Engine(demo_mode=False, pure_chat=False)
# engine.manager - register and look up components
# engine.runner - run training/evaluation
# engine.chatter - load models and chat
# Creating an engine for a chat-only demo
from llamafactory.webui.engine import Engine
engine = Engine(pure_chat=True)
# engine.chatter is eagerly initialized (lazy_init=False)
# Wiring resume and language change to the Gradio demo
demo.load(engine.resume, outputs=engine.manager.get_elem_list(), concurrency_limit=None)
lang.change(engine.change_lang, [lang], engine.manager.get_elem_list(), queue=False)
Related Pages
- Implementation:Hiyouga_LLaMA_Factory_WebUI_Interface - Creates Engine instances for both full UI and web demo
- Implementation:Hiyouga_LLaMA_Factory_WebUI_Common - Provides create_ds_config, load_config, get_time used by Engine
- Implementation:Hiyouga_LLaMA_Factory_WebUI_Control - Controller callbacks invoked by components managed through Engine
- Implementation:Hiyouga_LLaMA_Factory_WebUI_Top_Component - Top panel registered under "top" namespace in Engine.manager