agentleFS
hiyougahiyouga/LLaMA-Factory/.ai/CLAUDE.md

LLaMA-Factory

CLAUDE.md76k starsChanged 48 days agoApache-2.0View on GitHub

The project uses uv as the preferred package manager. Commands automatically use uv run / uvx if uv is available. LlamaFactory has two parallel architectures controlled by the USE_V1 environment variable: Most active development happens in v0. The v1 architecture lives in src/llamafactory/v1/. CLI entry point is llamafactory-cli / lmf → src/llamafactory/cli.py:main(), which dispatches to launcher.py based on USE_V1. Available subcommands: train, chat, api, export, webchat, webui, env, version, help. Training is invoked with a YAML config: llamafactory-cli train examples/trainlora/llama3lora_sft.yaml

We split this CLAUDE.md into the rules it gives an agent

6 rules. About 0 are common, 0 are distinctive, and 6 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 6

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All training parameters are YAML/JSON config files.

    line 61
  2. Very specific:

    Add a prompt template to src/llamafactory/data/template.py in the TEMPLATES dict

    line 82
  3. Very specific:

    Add any necessary model patches in src/llamafactory/model/patcher.py

    line 83
  4. Very specific:

    Add multi-modal support in src/llamafactory/data/mm_plugin.py if needed

    line 84
  5. Very specific:

    Always set WANDB_DISABLED=true when running tests

    line 98
  6. Very specific:

    All new files must include Apache 2.0 license header (checked by make license)

    line 105

≈ “Common” is an estimate: at least 1 in 5 of the 25,680 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Commands

# Code style (auto-fix)
make style

# Code quality check (no modifications)
make quality

# Run all tests
make test

# Run a single test file
WANDB_DISABLED=true pytest -vv --import-mode=importlib tests/path/to/test_file.py

# Run tests matching a pattern
WANDB_DISABLED=true pytest -vv --import-mode=importlib tests/ -k "test_name"

# License header check
make license

# Build package
make build

The project uses uv as the preferred package manager. Commands automatically use uv run / uvx if uv is available.

Architecture

LlamaFactory has two parallel architectures controlled by the USE_V1 environment variable:

  • v0 (default): api, webui > chat, eval, train > data, model > hparams > extras
  • v1 (experimental, USE_V1=1): trainers > core > accelerator, plugins, config > utils

Most active development happens in v0. The v1 architecture lives in src/llamafactory/v1/.

Entry Points

CLI entry point is llamafactory-cli / lmf → src/llamafactory/cli.py:main(), which dispatches to launcher.py based on USE_V1.

Available subcommands: train, chat, api, export, webchat, webui, env, version, help.

Training Flow (v0)

run_exp() [tuner.py]
  → read_args() → parse YAML/JSON config
  → get_train_args() → produces typed argument dataclasses
  → routes to: run_sft / run_dpo / run_ppo / run_rm / run_pt / run_kto
  → optional: export_model()

Training is invoked with a YAML config: llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml

Configuration System

All training parameters are YAML/JSON config files. Argument parsing in src/llamafactory/hparams/parser.py produces four typed dataclasses:

  • ModelArguments — model/tokenizer selection, quantization
  • DataArguments — datasets, templates, preprocessing
  • FinetuningArguments — LoRA rank/target, training method (sft/dpo/ppo/rm/pt/kto)
  • TrainingArguments — extends HuggingFace's TrainingArguments

Key Modules

ModulePurpose
src/llamafactory/model/loader.pyLoads model + tokenizer; applies quantization, LoRA, patches
src/llamafactory/model/patcher.pyModel-specific compatibility patches
src/llamafactory/data/template.pyPrompt templates; TEMPLATES dict maps model family → format
src/llamafactory/data/mm_plugin.pyMulti-modal (image/video/audio) data handling
src/llamafactory/data/processor/Per-stage data processors (supervised, pairwise, pretrain, etc.)
src/llamafactory/train/sft/SFT trainer; other stages follow same structure
src/llamafactory/chat/Inference engines: hf_engine, vllm_engine, sglang_engine, kt_engine
src/llamafactory/extras/constants.pyEnums and constants used across the project

Adding Support for a New Model

  1. Add a prompt template to src/llamafactory/data/template.py in the TEMPLATES dict
  2. Add any necessary model patches in src/llamafactory/model/patcher.py
  3. Add multi-modal support in src/llamafactory/data/mm_plugin.py if needed

Distributed Training

Multi-GPU automatically uses torchrun. Additional backends:

  • Ray: Optional Ray cluster support
  • HyperParallel FSDP2: src/llamafactory/train/hyper_parallel/
  • Megatron-core: src/llamafactory/train/mca/

Testing

  • tests/ — v0 tests; tests_v1/ — v1 tests
  • Most training tests require GPU hardware
  • pytest markers: @pytest.mark.slow, @pytest.mark.runs_on(['cuda'])
  • Always set WANDB_DISABLED=true when running tests

Code Style

  • Ruff for linting and formatting (line length 119, Google-style docstrings)
  • Python 3.11+ syntax
  • Double quotes for strings
  • All new files must include Apache 2.0 license header (checked by make license)

Download now (ZIP)

Trending

Quiet since August.about the whole repository

Dec 2025: 3 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 3 mentionsMay 2026: 2 mentionsJun 2026: 1 mentionJul 2026: 0 mentionsAug 2026: 2 mentionsSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the hiyouga/LLaMA-Factory repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about hiyouga/LLaMA-Factory

The biggest 5 of 93 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 93

Talked about on GitHub, YouTube, Bluesky, the web and Hacker News (93 times).

On GitHub · 50

45 more on GitHub

On YouTube · 22

17 more on YouTube

On Bluesky · 15

10 more on Bluesky

On the web · 4

  • Other versions1 project uses a version of this.

    Word for word · 1

    1. hiyouga/LlamaFactory★ 76k100% same

    Edited · 0

    None found.

    Wrote their own version · 0

    None found.

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository3 other files it gives its agents.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.