Implementation:Hiyouga LLaMA Factory V1 Arg Utils
| Knowledge Sources | |
|---|---|
| Domains | Configuration, Plugin System, Enums |
| Last Updated | 2026-02-06 19:00 GMT |
Overview
This module defines configuration enums and plugin configuration utilities used across the V1 argument dataclasses.
Description
The module provides four key components: PluginConfig (a dict subclass with a name property for plugin identification), ModelClass (a StrEnum with LLM, CLS, OTHER values for auto-class selection), SampleBackend (a StrEnum with HF, VLLM values for sampling backend selection), and BatchingStrategy (a StrEnum with NORMAL, PADDING_FREE, DYNAMIC_BATCHING, DYNAMIC_PADDING_FREE values for batch assembly strategy). The get_plugin_config function parses plugin configurations from JSON strings or dictionaries, performing automatic type conversion of string values to booleans, integers, and floats via _convert_str_dict.
Usage
Use these enums and utilities when defining or consuming V1 configuration arguments. PluginConfig and get_plugin_config are used to parse user-provided plugin configurations in model, data, trainer, and sampler argument dataclasses. The enum classes standardize configuration values across the V1 training system.
Code Reference
Source Location
- Repository: Hiyouga_LLaMA_Factory
- File: src/llamafactory/v1/config/arg_utils.py
- Lines: 1-103
Signature
class PluginConfig(dict):
@property
def name(self) -> str
PluginArgument = PluginConfig | dict | str | None
class ModelClass(StrEnum):
LLM = "llm"
CLS = "cls"
OTHER = "other"
class SampleBackend(StrEnum):
HF = "hf"
VLLM = "vllm"
class BatchingStrategy(StrEnum):
NORMAL = "normal"
PADDING_FREE = "padding_free"
DYNAMIC_BATCHING = "dynamic_batching"
DYNAMIC_PADDING_FREE = "dynamic_padding_free"
def get_plugin_config(config: PluginArgument) -> PluginConfig | None
Import
from llamafactory.v1.config.arg_utils import (
PluginConfig, PluginArgument, ModelClass, SampleBackend,
BatchingStrategy, get_plugin_config,
)
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| config (get_plugin_config) | PluginArgument | Yes | Plugin configuration as a JSON string (starting with "{"), a dict, a PluginConfig, or None |
Outputs
| Name | Type | Description |
|---|---|---|
| get_plugin_config result | PluginConfig or None | Parsed plugin configuration dict with name property; None if input is None |
| PluginConfig.name | str | The "name" field from the plugin configuration dictionary |
Usage Examples
from llamafactory.v1.config.arg_utils import (
get_plugin_config, ModelClass, SampleBackend, BatchingStrategy,
)
# Parse plugin config from JSON string
config = get_plugin_config('{"name": "fsdp2", "sharding_strategy": "FULL_SHARD"}')
print(config.name) # "fsdp2"
print(config["sharding_strategy"]) # "FULL_SHARD"
# Parse plugin config from dict
config = get_plugin_config({"name": "deepspeed", "stage": "3"})
print(config["stage"]) # 3 (auto-converted from string to int)
# Use enum values
model_cls = ModelClass.LLM # "llm"
backend = SampleBackend.VLLM # "vllm"
strategy = BatchingStrategy.PADDING_FREE # "padding_free"
# None returns None
config = get_plugin_config(None) # None
Related Pages
- Hiyouga_LLaMA_Factory_V1_Config_Model_Args - Model arguments that use ModelClass and PluginConfig
- Hiyouga_LLaMA_Factory_V1_Config_Training_Args - Training arguments that use BatchingStrategy and PluginConfig
- Hiyouga_LLaMA_Factory_V1_Config_Sample_Args - Sample arguments that use SampleBackend
- Hiyouga_LLaMA_Factory_V1_Config_Arg_Parser - Argument parser that processes these configuration types