This document records the changes made in this fork relative to the upstream LLaMA-Factory repo and upstream PEFT. It is meant to be a precise, searchable reference for what we added or modified to support the multi-project workflow and custom PEFT tuners.
If you need a short summary: this fork vendors PEFT v0.17.1, adds custom PEFT tuners (CoLA, HydraLoRA, AdaMole, MoLA, MoELPR), and extends LLaMA-Factory to support language routing metadata and extra loss terms used by those tuners.
- LLaMA-Factory base: the current state of this repository before these changes were applied.
- PEFT base: vendored copy of upstream PEFT v0.17.1 under
src/peft/.
-
PEFT is vendored in-tree
- Added:
src/peft/(full upstream PEFT v0.17.1 source). - Removed:
peftdependency fromrequirements.txt. - Rationale: keep a single, shared, controlled PEFT implementation for both downstream projects and avoid version drift.
- Added:
-
Custom PEFT tuners integrated
- Added tuners and configs:
- CoLA:
ColaConfig,ColaModel - HydraLoRA:
HydraLoraConfig,HydraLoraModel - AdaMole:
AdaMoleConfig,AdaMoleModel - MoLA:
MolaConfig,MolaModel(registered underadamoe_1path) - MoELPR:
MoelprConfig,MoelprModel
- CoLA:
- Added metrics helpers:
src/peft/metrics.py - Registered new PEFT types:
COLA,HYDRALORA,ADAMOLE,MOLA,MOELPR
- All of these are wired into PEFT registries and
peft/__init__.py.
- Added tuners and configs:
-
Language routing / multilingual support
- Added language metadata plumbing in LLaMA-Factory:
- dataset fields, collator behavior, and model adapter config use
language_idsto route tokens to experts.
- dataset fields, collator behavior, and model adapter config use
- Added
src/llamafactory/extras/language.pywith helpers for language maps and ID conversions.
- Added language metadata plumbing in LLaMA-Factory:
-
Training loop support for additional losses
- Extra loss terms used by AdaMole / MoLA / MoELPR added to SFT trainer.
New / updated files
src/peft/(vendored upstream PEFT v0.17.1)src/peft/metrics.py- Adds metrics recording helpers.
- Includes
record_cola_metricsandrecord_hydralora_metrics.
Updated PEFT type system
src/peft/utils/peft_types.py- Adds the new PEFT method types:
COLA,HYDRALORA,ADAMOLE,MOLA,MOELPR.
- Adds the new PEFT method types:
New tuners and configs
src/peft/tuners/cola/- Implements CoLA layers and model wrapper.
src/peft/tuners/hydralora/- Implements HydraLoRA layers and model wrapper.
src/peft/tuners/adamole/- Implements AdaMole layers and model wrapper.
src/peft/tuners/adamoe_1/- Implements MoLA layers and model wrapper (registered as
mola).
- Implements MoLA layers and model wrapper (registered as
src/peft/tuners/moelpr/- Implements MoELPR layers and model wrapper.
Registry updates
src/peft/tuners/__init__.py- Exposes all custom tuners and configs.
src/peft/__init__.py- Exports new config/model classes at the top level.
src/peft/tuners/*/__init__.py- Registers tuners via
register_peft_method. - Uses
prefix="lora_"for all new tuners to match adapter naming.
- Registers tuners via
Loading/saving and forward args
src/peft/utils/save_and_load.py- Adds new tuners into LoRA-like handling.
- Uses
getattr(config, "use_dora", False)to avoid missing fields.
src/peft/peft_model.py- Adds
language_idsandfamily_idstospecial_peft_forward_args.
- Adds
CoLA / Hydra-specific changes
src/peft/tuners/cola/model.py- Passes
language_to_subgroup_idsinto the layer forward.
- Passes
src/peft/tuners/hydralora/model.py- Same
language_to_subgroup_idssupport as CoLA.
- Same
src/peft/tuners/cola/config.py- Accepts
random_ab/random_baand mapsrandomtorandom_ab.
- Accepts
Language metadata helpers
src/llamafactory/extras/language.py- Implements:
load_language_mapload_language_groupingsbuild_language_vocablanguage_to_idsLANGUAGE_PAD_ID
- Implements:
Data args
src/llamafactory/hparams/data_args.py- Adds:
language_columnlanguage_map_language_metadatacacheget_language_metadata
- Adds:
Dataset parsing and conversion
src/llamafactory/data/parser.py- Adds dataset attribute
language. - Extends column parsing to include it.
- Adds dataset attribute
src/llamafactory/data/converter.py- Adds
_extract_language. - Adds
_languageto outputs for Alpaca / ShareGPT / OpenAI formats.
- Adds
Data processor
src/llamafactory/data/processor/supervised.py- Adds
language_idsin features usinglanguage_to_ids. - Adds
LANGUAGE_PAD_IDfor packed sequences.
- Adds
Collator
src/llamafactory/data/collator.py- Collects
language_idsand includes them in the batch tensor when present.
- Collects
Finetuning args
src/llamafactory/hparams/finetuning_args.py- Adds finetuning types:
cola,hydralora,adamole,mola,moelpr. - Adds configuration fields for:
- CoLA and HydraLoRA
- AdaMole, MoLA, MoELPR
- Language routing and auxiliary loss weights
- Adds validation for MoELPR stage settings and LoRA-like tuners.
- Adds finetuning types:
Argument parsing sync
src/llamafactory/hparams/parser.py- Adds
_sync_language_metadatato alignlanguage_mapandlanguage_columnbetweendata_argsandfinetuning_args. - Loosens adapter validation to allow new finetuning types.
- Adds
Adapter setup for new tuners
src/llamafactory/model/adapter.py- Adds imports for the new PEFT configs.
- Adds helper functions:
_build_language_metadata_parse_optional_int_list
- Adds setup functions:
_setup_cola_tuning_setup_hydralora_tuning_setup_adamole_tuning_setup_mola_tuning_setup_moelpr_tuning
- Wires these into
init_adapter. - Disables Unsloth/KTransformers for custom tuners to avoid incompatibility.
Trainer support
-
src/llamafactory/train/sft/trainer.py- Adds extra loss terms for AdaMole/MoLA/MoELPR.
- Adds language prior loss and MoELPR masks where required.
- Imports
torch.nn.functional as F.
-
src/llamafactory/train/sft/workflow.py- Sets up MoELPR stage-2 language IDs using
data_args.language_map.
- Sets up MoELPR stage-2 language IDs using
-
src/llamafactory/train/trainer_utils.py- Treats all PEFT-style finetuning types as "no ref model" for PPO/DPO ref model creation.
Constants
src/llamafactory/extras/constants.py- Extends
METHODSandPEFT_METHODSto include all custom tuners.
- Extends
Accelerate configs
examples/accelerate/fsdp_2gpu_config.yamlexamples/accelerate/fsdp_4gpu_config.yaml- Added custom FSDP configs used by
HTYLLM-PG/approaches/CoLA/scripts/comparison/run_multilingual_ablation.sh.
- Added custom FSDP configs used by
requirements.txt- Removed
peftdependency because it is vendored insrc/peft/.
- Removed
- This fork intentionally keeps the LLaMA-Factory base version unchanged while upgrading PEFT to v0.17.1 and merging custom tuners.
- The custom tuners are LoRA-like and are registered with
prefix="lora_"for compatibility with adapter naming and saving/loading behavior. - Language routing is opt-in; it uses
language_columnandlanguage_mapto generatelanguage_idsused by custom tuners.
- Import test:
python -c "import llamafactory, peft; print('ok')"
- Sanity check that new tuning types parse:
finetuning_type=colaorfinetuning_type=moelpr
- CoLA / HydraLoRA code: derived from
HTYLLM-PGextensions. - AdaMole / MoLA / MoELPR code: derived from
moe-studyextensions.