

Also from Kynth Studios


Also from Kynth Studios


Also from Kynth Studios
1# CLAUDE.md23This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.45## Commands67```bash8# Code style (auto-fix)9make style1011# Code quality check (no modifications)12make quality1314# Run all tests15make test1617# Run a single test file18WANDB_DISABLED=true pytest -vv --import-mode=importlib tests/path/to/test_file.py1920# Run tests matching a pattern21WANDB_DISABLED=true pytest -vv --import-mode=importlib tests/ -k "test_name"2223# License header check24make license2526# Build package27make build28```2930The project uses `uv` as the preferred package manager. Commands automatically use `uv run` / `uvx` if `uv` is available.3132## Architecture3334LlamaFactory has two parallel architectures controlled by the `USE_V1` environment variable:3536- **v0 (default):** `api, webui > chat, eval, train > data, model > hparams > extras`37- **v1 (experimental, `USE_V1=1`):** `trainers > core > accelerator, plugins, config > utils`3839Most active development happens in v0. The v1 architecture lives in `src/llamafactory/v1/`.4041### Entry Points4243CLI entry point is `llamafactory-cli` / `lmf` → `src/llamafactory/cli.py:main()`, which dispatches to `launcher.py` based on `USE_V1`.4445Available subcommands: `train`, `chat`, `api`, `export`, `webchat`, `webui`, `env`, `version`, `help`.4647### Training Flow (v0)4849```50run_exp() [tuner.py]51 → read_args() → parse YAML/JSON config52 → get_train_args() → produces typed argument dataclasses53 → routes to: run_sft / run_dpo / run_ppo / run_rm / run_pt / run_kto54 → optional: export_model()55```5657Training is invoked with a YAML config: `llamafactory-cli train examples/train_lora/llama3_lora_sft.yaml`5859### Configuration System6061All training parameters are YAML/JSON config files. Argument parsing in `src/llamafactory/hparams/parser.py` produces four typed dataclasses:62- `ModelArguments` — model/tokenizer selection, quantization63- `DataArguments` — datasets, templates, preprocessing64- `FinetuningArguments` — LoRA rank/target, training method (sft/dpo/ppo/rm/pt/kto)65- `TrainingArguments` — extends HuggingFace's `TrainingArguments`6667### Key Modules6869| Module | Purpose |70|--------|---------|71| `src/llamafactory/model/loader.py` | Loads model + tokenizer; applies quantization, LoRA, patches |72| `src/llamafactory/model/patcher.py` | Model-specific compatibility patches |73| `src/llamafactory/data/template.py` | Prompt templates; `TEMPLATES` dict maps model family → format |74| `src/llamafactory/data/mm_plugin.py` | Multi-modal (image/video/audio) data handling |75| `src/llamafactory/data/processor/` | Per-stage data processors (supervised, pairwise, pretrain, etc.) |76| `src/llamafactory/train/sft/` | SFT trainer; other stages follow same structure |77| `src/llamafactory/chat/` | Inference engines: `hf_engine`, `vllm_engine`, `sglang_engine`, `kt_engine` |78| `src/llamafactory/extras/constants.py` | Enums and constants used across the project |7980### Adding Support for a New Model81821. Add a prompt template to `src/llamafactory/data/template.py` in the `TEMPLATES` dict832. Add any necessary model patches in `src/llamafactory/model/patcher.py`843. Add multi-modal support in `src/llamafactory/data/mm_plugin.py` if needed8586### Distributed Training8788Multi-GPU automatically uses `torchrun`. Additional backends:89- **Ray:** Optional Ray cluster support90- **HyperParallel FSDP2:** `src/llamafactory/train/hyper_parallel/`91- **Megatron-core:** `src/llamafactory/train/mca/`9293### Testing9495- `tests/` — v0 tests; `tests_v1/` — v1 tests96- Most training tests require GPU hardware97- pytest markers: `@pytest.mark.slow`, `@pytest.mark.runs_on(['cuda'])`98- Always set `WANDB_DISABLED=true` when running tests99100### Code Style101102- Ruff for linting and formatting (line length 119, Google-style docstrings)103- Python 3.11+ syntax104- Double quotes for strings105- All new files must include Apache 2.0 license header (checked by `make license`)106
One repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiyouga/LlamaFactory.github/copilot-instructions.md · 74k | Copilot instructions | setupbuildtestlint-format+5 | 97/100 | 13 days ago |
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| dotCMS/corecore-web/CLAUDE.md · 949 | CLAUDE.md | teststylearchtesting-strategy+3 | 100/100 | 14 days ago | |
| Adit-Jain-srm/NightmareNetCLAUDE.md · 46 | CLAUDE.md | buildtestlint-formatstyle+6 | 100/100 | 14 days ago | |
| tyrchen/geektime-bootcamp-aiw7/genslides/backend/CLAUDE.md · 230 | CLAUDE.md | testlint-formatstylearch+6 | 100/100 | 9 days ago | |
| dotCMS/coreCLAUDE.md · 949 | CLAUDE.md | setupbuildteststyle+7 | 99/100 | today | |
| dotCMS/corecore-web/libs/sdk/react/CLAUDE.md · 949 | CLAUDE.md | setupbuildtestlint-format+9 | 97/100 | 14 days ago | |
| supabase/supabase.claude/CLAUDE.md · 108k | CLAUDE.md | testlint-formatstylearch+1 | 97/100 | 14 days ago | |
| dotCMS/corecore-web/libs/sdk/client/CLAUDE.md · 949 | CLAUDE.md | setupbuildtestlint-format+9 | 97/100 | 14 days ago | |
| modelcontextprotocol/serversCLAUDE.md · 90k | CLAUDE.md | setupbuildtestlint-format+6 | 97/100 | 14 days ago |
A badge carrying the measured quality of the strongest agent config file in this repository, out of 100. It reads from this index every time somebody loads your page, so it changes when the measurement changes and there is nothing to keep up to date. Free, no account, and the value is not something you or we can set by hand.
[](https://rulestack.kynth.studio/configs/hiyouga-llamafactory-ai-claude)Would rather not hotlink us? Every badge is also served in shields.io’s endpoint schema, so shields renders the image and your readers never talk to our domain:
Published by Toolproof, the masthead over this index and eight others. The method behind the number is at toolproof.kynth.studio/methodology, and the whole thing is readable as JSON with no key at /api.