├── LLaMA-Factory ├── .dockerignore ├── .env.local ├── .gitattributes ├── .github │ ├── CODE_OF_CONDUCT.md │ ├── CONTRIBUTING.md │ ├── ISSUE_TEMPLATE │ │ └── bug-report.yml │ ├── PULL_REQUEST_TEMPLATE.md │ ├── SECURITY.md │ └── workflows │ │ ├── label_issue.yml │ │ ├── publish.yml │ │ └── tests.yml ├── .gitignore ├── .pre-commit-config.yaml ├── CITATION.cff ├── LICENSE ├── MANIFEST.in ├── Makefile ├── README.md ├── README_zh.md ├── assets │ ├── benchmark.svg │ ├── logo.png │ ├── wechat.jpg │ └── wechat_npu.jpg ├── data │ ├── README.md │ ├── README_zh.md │ ├── alpaca_en_demo.json │ ├── alpaca_zh_demo.json │ ├── belle_multiturn │ │ └── belle_multiturn.py │ ├── c4_demo.json │ ├── dataset_info.json │ ├── dpo_en_demo.json │ ├── dpo_zh_demo.json │ ├── glaive_toolcall_en_demo.json │ ├── glaive_toolcall_zh_demo.json │ ├── hh_rlhf_en │ │ └── hh_rlhf_en.py │ ├── identity.json │ ├── kto_en_demo.json │ ├── mllm_demo.json │ ├── mllm_demo_data │ │ ├── 1.jpg │ │ ├── 1.mp4 │ │ ├── 2.avi │ │ ├── 2.jpg │ │ ├── 3.jpg │ │ └── 3.mp4 │ ├── mllm_video_demo.json │ ├── train_sft_Base.json │ ├── ultra_chat │ │ └── ultra_chat.py │ └── wiki_demo.txt ├── docker │ ├── docker-cuda │ │ ├── Dockerfile │ │ └── docker-compose.yml │ ├── docker-npu │ │ ├── Dockerfile │ │ └── docker-compose.yml │ └── docker-rocm │ │ ├── Dockerfile │ │ └── docker-compose.yml ├── evaluation │ ├── ceval │ │ ├── ceval.py │ │ ├── ceval.zip │ │ └── mapping.json │ ├── cmmlu │ │ ├── cmmlu.py │ │ ├── cmmlu.zip │ │ └── mapping.json │ └── mmlu │ │ ├── mapping.json │ │ ├── mmlu.py │ │ └── mmlu.zip ├── examples │ ├── README.md │ ├── README_zh.md │ ├── accelerate │ │ └── fsdp_config.yaml │ ├── deepspeed │ │ ├── ds_z0_config.json │ │ ├── ds_z2_config.json │ │ ├── ds_z2_offload_config.json │ │ ├── ds_z3_config.json │ │ └── ds_z3_offload_config.json │ ├── extras │ │ ├── adam_mini │ │ │ └── qwen2_full_sft.yaml │ │ ├── badam │ │ │ └── llama3_full_sft.yaml │ │ ├── fsdp_qlora │ │ │ ├── llama3_lora_sft.yaml │ │ │ └── train.sh │ │ ├── galore │ │ │ └── llama3_full_sft.yaml │ │ ├── llama_pro │ │ │ ├── expand.sh │ │ │ └── llama3_freeze_sft.yaml │ │ ├── loraplus │ │ │ └── llama3_lora_sft.yaml │ │ ├── mod │ │ │ └── llama3_full_sft.yaml │ │ └── pissa │ │ │ ├── init.sh │ │ │ └── llama3_lora_sft.yaml │ ├── inference │ │ ├── llama3.yaml │ │ ├── llama3_lora_sft.yaml │ │ ├── llama3_vllm.yaml │ │ ├── llava1_5.yaml │ │ └── qwen2_vl.yaml │ ├── merge_lora │ │ ├── llama3_gptq.yaml │ │ ├── llama3_lora_sft.yaml │ │ └── qwen2vl_lora_sft.yaml │ ├── train_full │ │ ├── llama3_full_predict.yaml │ │ ├── llama3_full_sft_ds3.yaml │ │ └── qwen2vl_full_sft.yaml │ ├── train_lora │ │ ├── llama3_lora_dpo.yaml │ │ ├── llama3_lora_eval.yaml │ │ ├── llama3_lora_kto.yaml │ │ ├── llama3_lora_ppo.yaml │ │ ├── llama3_lora_predict.yaml │ │ ├── llama3_lora_pretrain.yaml │ │ ├── llama3_lora_reward.yaml │ │ ├── llama3_lora_sft.yaml │ │ ├── llama3_lora_sft_ds0.yaml │ │ ├── llama3_lora_sft_ds3.yaml │ │ ├── llama3_preprocess.yaml │ │ ├── llava1_5_lora_sft.yaml │ │ ├── qwen2vl_lora_dpo.yaml │ │ └── qwen2vl_lora_sft.yaml │ └── train_qlora │ │ ├── llama3_lora_sft_aqlm.yaml │ │ ├── llama3_lora_sft_awq.yaml │ │ ├── llama3_lora_sft_gptq.yaml │ │ └── llama3_lora_sft_otfq.yaml ├── pyproject.toml ├── requirements.txt ├── scripts │ ├── cal_flops.py │ ├── cal_lr.py │ ├── cal_mfu.py │ ├── cal_ppl.py │ ├── length_cdf.py │ ├── llama_pro.py │ ├── llamafy_baichuan2.py │ ├── llamafy_qwen.py │ ├── loftq_init.py │ ├── pissa_init.py │ ├── test_image.py │ └── test_toolcall.py ├── setup.py ├── src │ ├── api.py │ ├── llamafactory │ │ ├── __init__.py │ │ ├── api │ │ │ ├── __init__.py │ │ │ ├── app.py │ │ │ ├── chat.py │ │ │ ├── common.py │ │ │ └── protocol.py │ │ ├── chat │ │ │ ├── __init__.py │ │ │ ├── base_engine.py │ │ │ ├── chat_model.py │ │ │ ├── hf_engine.py │ │ │ └── vllm_engine.py │ │ ├── cli.py │ │ ├── data │ │ │ ├── __init__.py │ │ │ ├── aligner.py │ │ │ ├── collator.py │ │ │ ├── data_utils.py │ │ │ ├── formatter.py │ │ │ ├── loader.py │ │ │ ├── mm_plugin.py │ │ │ ├── parser.py │ │ │ ├── preprocess.py │ │ │ ├── processors │ │ │ │ ├── __init__.py │ │ │ │ ├── feedback.py │ │ │ │ ├── pairwise.py │ │ │ │ ├── pretrain.py │ │ │ │ ├── processor_utils.py │ │ │ │ ├── supervised.py │ │ │ │ └── unsupervised.py │ │ │ ├── template.py │ │ │ └── tool_utils.py │ │ ├── eval │ │ │ ├── __init__.py │ │ │ ├── evaluator.py │ │ │ └── template.py │ │ ├── extras │ │ │ ├── __init__.py │ │ │ ├── constants.py │ │ │ ├── env.py │ │ │ ├── logging.py │ │ │ ├── misc.py │ │ │ ├── packages.py │ │ │ └── ploting.py │ │ ├── hparams │ │ │ ├── __init__.py │ │ │ ├── data_args.py │ │ │ ├── evaluation_args.py │ │ │ ├── finetuning_args.py │ │ │ ├── generating_args.py │ │ │ ├── model_args.py │ │ │ └── parser.py │ │ ├── launcher.py │ │ ├── model │ │ │ ├── __init__.py │ │ │ ├── adapter.py │ │ │ ├── loader.py │ │ │ ├── model_utils │ │ │ │ ├── __init__.py │ │ │ │ ├── attention.py │ │ │ │ ├── checkpointing.py │ │ │ │ ├── embedding.py │ │ │ │ ├── liger_kernel.py │ │ │ │ ├── longlora.py │ │ │ │ ├── misc.py │ │ │ │ ├── mod.py │ │ │ │ ├── moe.py │ │ │ │ ├── packing.py │ │ │ │ ├── quantization.py │ │ │ │ ├── rope.py │ │ │ │ ├── unsloth.py │ │ │ │ ├── valuehead.py │ │ │ │ └── visual.py │ │ │ └── patcher.py │ │ ├── train │ │ │ ├── __init__.py │ │ │ ├── callbacks.py │ │ │ ├── dpo │ │ │ │ ├── __init__.py │ │ │ │ ├── trainer.py │ │ │ │ └── workflow.py │ │ │ ├── kto │ │ │ │ ├── __init__.py │ │ │ │ ├── trainer.py │ │ │ │ └── workflow.py │ │ │ ├── ppo │ │ │ │ ├── __init__.py │ │ │ │ ├── ppo_utils.py │ │ │ │ ├── trainer.py │ │ │ │ └── workflow.py │ │ │ ├── pt │ │ │ │ ├── __init__.py │ │ │ │ ├── trainer.py │ │ │ │ └── workflow.py │ │ │ ├── rm │ │ │ │ ├── __init__.py │ │ │ │ ├── metric.py │ │ │ │ ├── trainer.py │ │ │ │ └── workflow.py │ │ │ ├── sft │ │ │ │ ├── __init__.py │ │ │ │ ├── metric.py │ │ │ │ ├── trainer.py │ │ │ │ └── workflow.py │ │ │ ├── test_utils.py │ │ │ ├── trainer_utils.py │ │ │ └── tuner.py │ │ └── webui │ │ │ ├── __init__.py │ │ │ ├── chatter.py │ │ │ ├── common.py │ │ │ ├── components │ │ │ ├── __init__.py │ │ │ ├── chatbot.py │ │ │ ├── data.py │ │ │ ├── eval.py │ │ │ ├── export.py │ │ │ ├── infer.py │ │ │ ├── top.py │ │ │ └── train.py │ │ │ ├── css.py │ │ │ ├── engine.py │ │ │ ├── interface.py │ │ │ ├── locales.py │ │ │ ├── manager.py │ │ │ ├── runner.py │ │ │ └── utils.py │ ├── train.py │ └── webui.py └── tests │ ├── data │ ├── processors │ │ ├── test_feedback.py │ │ ├── test_pairwise.py │ │ ├── test_processor_utils.py │ │ ├── test_supervised.py │ │ └── test_unsupervised.py │ ├── test_collator.py │ ├── test_formatter.py │ ├── test_mm_plugin.py │ └── test_template.py │ ├── e2e │ ├── test_chat.py │ └── test_train.py │ ├── eval │ └── test_eval_template.py │ └── model │ ├── model_utils │ ├── test_attention.py │ ├── test_checkpointing.py │ └── test_packing.py │ ├── test_base.py │ ├── test_freeze.py │ ├── test_full.py │ ├── test_lora.py │ └── test_pissa.py ├── License.txt ├── README.md ├── assets ├── AutoMathCritique.jpg ├── case_study_1.pdf-1-10.jpg └── train-test-flowchart.png └── selfimprove ├── critic.py ├── data_filter.py ├── evaluate-all.sh ├── inference-all.sh ├── inference.py ├── meta-llama ├── Meta-Llama-3-8B-all-sftdata_0_new.json ├── Meta-Llama-3-8B-all-sftdata_0_origin.json ├── Meta-Llama-3-8B-gsm8k-sftdata_0_new.json ├── Meta-Llama-3-8B-gsm8k-sftdata_0_origin.json ├── Meta-Llama-3-8B-math-sftdata_0_new.json └── Meta-Llama-3-8B-math-sftdata_0_origin.json ├── process.py └── test_filter.py /LLaMA-Factory/.dockerignore: -------------------------------------------------------------------------------- 1 | .vscode 2 | .git 3 | .github 4 | .venv 5 | cache 6 | data 7 | docker 8 | saves 9 | hf_cache 10 | ms_cache 11 | om_cache 12 | output 13 | .dockerignore 14 | .gitattributes 15 | .gitignore 16 | -------------------------------------------------------------------------------- /LLaMA-Factory/.env.local: -------------------------------------------------------------------------------- 1 | # Note: actually we do not support .env, just for reference 2 | # api 3 | API_HOST= 4 | API_PORT= 5 | API_KEY= 6 | API_MODEL_NAME= 7 | FASTAPI_ROOT_PATH= 8 | MAX_CONCURRENT= 9 | # general 10 | DISABLE_VERSION_CHECK= 11 | FORCE_CHECK_IMPORTS= 12 | LLAMAFACTORY_VERBOSITY= 13 | USE_MODELSCOPE_HUB= 14 | USE_OPENMIND_HUB= 15 | RECORD_VRAM= 16 | # torchrun 17 | FORCE_TORCHRUN= 18 | MASTER_ADDR= 19 | MASTER_PORT= 20 | NNODES= 21 | NODE_RANK= 22 | NPROC_PER_NODE= 23 | # wandb 24 | WANDB_DISABLED= 25 | WANDB_PROJECT= 26 | WANDB_API_KEY= 27 | # gradio ui 28 | GRADIO_SHARE= 29 | GRADIO_SERVER_NAME= 30 | GRADIO_SERVER_PORT= 31 | GRADIO_ROOT_PATH= 32 | GRADIO_IPV6= 33 | # setup 34 | ENABLE_SHORT_CONSOLE=1 35 | # reserved (do not use) 36 | LLAMABOARD_ENABLED= 37 | LLAMABOARD_WORKDIR= 38 | -------------------------------------------------------------------------------- /LLaMA-Factory/.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /LLaMA-Factory/.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to LLaMA Factory 2 | 3 | Everyone is welcome to contribute, and we value everybody's contribution. Code contributions are not the only way to help the community. Answering questions, helping others, and improving the documentation are also immensely valuable. 4 | 5 | It also helps us if you spread the word! Reference the library in blog posts about the awesome projects it made possible, shout out on Twitter every time it has helped you, or simply ⭐️ the repository to say thank you. 6 | 7 | However you choose to contribute, please be mindful and respect our [code of conduct](CODE_OF_CONDUCT.md). 8 | 9 | **This guide was heavily inspired by [transformers guide to contributing](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md).** 10 | 11 | ## Ways to contribute 12 | 13 | There are several ways you can contribute to LLaMA Factory: 14 | 15 | * Fix outstanding issues with the existing code. 16 | * Submit issues related to bugs or desired new features. 17 | * Contribute to the examples or to the documentation. 18 | 19 | ### Style guide 20 | 21 | LLaMA Factory follows the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html), check it for details. 22 | 23 | ### Create a Pull Request 24 | 25 | 1. Fork the [repository](https://github.com/hiyouga/LLaMA-Factory) by clicking on the [Fork](https://github.com/hiyouga/LLaMA-Factory/fork) button on the repository's page. This creates a copy of the code under your GitHub user account. 26 | 27 | 2. Clone your fork to your local disk, and add the base repository as a remote: 28 | 29 | ```bash 30 | git clone git@github.com:[username]/LLaMA-Factory.git 31 | cd LLaMA-Factory 32 | git remote add upstream https://github.com/hiyouga/LLaMA-Factory.git 33 | ``` 34 | 35 | 3. Create a new branch to hold your development changes: 36 | 37 | ```bash 38 | git checkout -b dev_your_branch 39 | ``` 40 | 41 | 4. Set up a development environment by running the following command in a virtual environment: 42 | 43 | ```bash 44 | pip install -e ".[dev]" 45 | ``` 46 | 47 | If LLaMA Factory was already installed in the virtual environment, remove it with `pip uninstall llamafactory` before reinstalling it in editable mode with the -e flag. 48 | 49 | 5. Check code before commit: 50 | 51 | ```bash 52 | make commit 53 | make style && make quality 54 | make test 55 | ``` 56 | 57 | 6. Submit changes: 58 | 59 | ```bash 60 | git add . 61 | git commit -m "commit message" 62 | git fetch upstream 63 | git rebase upstream/main 64 | git push -u origin dev_your_branch 65 | ``` 66 | 67 | 7. Create a merge request from your branch `dev_your_branch` at [origin repo](https://github.com/hiyouga/LLaMA-Factory). 68 | -------------------------------------------------------------------------------- /LLaMA-Factory/.github/ISSUE_TEMPLATE/bug-report.yml: -------------------------------------------------------------------------------- 1 | name: "\U0001F41B Bug / Help" 2 | description: Create a report to help us improve the LLaMA Factory 3 | body: 4 | - type: markdown 5 | attributes: 6 | value: | 7 | Issues included in **FAQs** or those with **insufficient** information may be closed without a response. 8 | 包含在**常见问题**内或提供信息**不完整**的 issues 可能不会被回复。 9 | 10 | - type: checkboxes 11 | id: reminder 12 | attributes: 13 | label: Reminder 14 | description: | 15 | Please ensure you have read the README carefully and searched the existing issues (including FAQs). 16 | 请确保您已经认真阅读了 README 并且搜索过现有的 issues(包括常见问题)。 17 | 18 | options: 19 | - label: I have read the README and searched the existing issues. 20 | required: true 21 | 22 | - type: textarea 23 | id: system-info 24 | validations: 25 | required: true 26 | attributes: 27 | label: System Info 28 | description: | 29 | Please share your system info with us. You can run the command **llamafactory-cli env** and copy-paste its output below. 30 | 请提供您的系统信息。您可以在命令行运行 **llamafactory-cli env** 并将其输出复制到该文本框中。 31 | 32 | placeholder: llamafactory version, platform, python version, ... 33 | 34 | - type: textarea 35 | id: reproduction 36 | validations: 37 | required: true 38 | attributes: 39 | label: Reproduction 40 | description: | 41 | Please provide code snippets, error messages and stack traces that reproduces the problem. 42 | 请提供运行参数,错误信息以及异常堆栈以便于我们复现该问题。 43 | Remember to use Markdown tags to correctly format your code. 44 | 请合理使用 Markdown 标签来格式化您的文本。 45 | 46 | placeholder: | 47 | ```bash 48 | llamafactory-cli train ... 49 | ``` 50 | 51 | - type: textarea 52 | id: expected-behavior 53 | validations: 54 | required: false 55 | attributes: 56 | label: Expected behavior 57 | description: | 58 | Please provide a clear and concise description of what you would expect to happen. 59 | 请提供您原本的目的,即这段代码的期望行为。 60 | 61 | - type: textarea 62 | id: others 63 | validations: 64 | required: false 65 | attributes: 66 | label: Others 67 | -------------------------------------------------------------------------------- /LLaMA-Factory/.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | # What does this PR do? 2 | 3 | Fixes # (issue) 4 | 5 | ## Before submitting 6 | 7 | - [ ] Did you read the [contributor guideline](https://github.com/hiyouga/LLaMA-Factory/blob/main/.github/CONTRIBUTING.md)? 8 | - [ ] Did you write any new necessary tests? 9 | -------------------------------------------------------------------------------- /LLaMA-Factory/.github/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Reporting Security Issues 2 | 3 | To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/hiyouga/LLaMA-Factory/security/advisories/new) tab. 4 | 5 | We will send a response indicating the next steps in handling your report. After the initial reply to your report, the security team will keep you informed of the progress towards a fix and full announcement, and may ask for additional information or guidance. 6 | 7 | Report security bugs in third-party modules to the person or team maintaining the module. 8 | -------------------------------------------------------------------------------- /LLaMA-Factory/.github/workflows/label_issue.yml: -------------------------------------------------------------------------------- 1 | name: label_issue 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | 8 | jobs: 9 | label_issue: 10 | runs-on: ubuntu-latest 11 | 12 | permissions: 13 | issues: write 14 | 15 | steps: 16 | - env: 17 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 18 | ISSUE_URL: ${{ github.event.issue.html_url }} 19 | ISSUE_TITLE: ${{ github.event.issue.title }} 20 | run: | 21 | LABEL=pending 22 | NPU_KEYWORDS=(npu huawei ascend 华为 昇腾) 23 | ISSUE_TITLE_LOWER=$(echo $ISSUE_TITLE | tr '[:upper:]' '[:lower:]') 24 | for KEYWORD in ${NPU_KEYWORDS[@]}; do 25 | if [[ $ISSUE_TITLE_LOWER == *$KEYWORD* ]] && [[ $ISSUE_TITLE_LOWER != *input* ]]; then 26 | LABEL=pending,npu 27 | break 28 | fi 29 | done 30 | gh issue edit $ISSUE_URL --add-label $LABEL 31 | -------------------------------------------------------------------------------- /LLaMA-Factory/.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: publish 2 | 3 | on: 4 | release: 5 | types: 6 | - published 7 | 8 | jobs: 9 | publish: 10 | name: Upload release to PyPI 11 | 12 | runs-on: ubuntu-latest 13 | 14 | environment: 15 | name: release 16 | url: https://pypi.org/p/llamafactory 17 | 18 | permissions: 19 | id-token: write 20 | 21 | steps: 22 | - name: Checkout 23 | uses: actions/checkout@v4 24 | 25 | - name: Set up Python 26 | uses: actions/setup-python@v5 27 | with: 28 | python-version: "3.8" 29 | 30 | - name: Install dependencies 31 | run: | 32 | python -m pip install --upgrade pip 33 | python -m pip install build 34 | 35 | - name: Build package 36 | run: | 37 | python -m build 38 | 39 | - name: Publish package 40 | uses: pypa/gh-action-pypi-publish@release/v1 41 | -------------------------------------------------------------------------------- /LLaMA-Factory/.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: tests 2 | 3 | on: 4 | push: 5 | branches: 6 | - "main" 7 | paths: 8 | - "**.py" 9 | - "requirements.txt" 10 | - ".github/workflows/*.yml" 11 | pull_request: 12 | branches: 13 | - "main" 14 | paths: 15 | - "**.py" 16 | - "requirements.txt" 17 | - ".github/workflows/*.yml" 18 | 19 | jobs: 20 | tests: 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | python-version: 25 | - "3.8" # TODO: remove py38 in next transformers release 26 | - "3.9" 27 | - "3.10" 28 | - "3.11" 29 | os: 30 | - "ubuntu-latest" 31 | - "windows-latest" 32 | - "macos-13" 33 | 34 | runs-on: ${{ matrix.os }} 35 | 36 | environment: 37 | name: tests 38 | 39 | env: 40 | HF_TOKEN: ${{ secrets.HF_TOKEN }} 41 | OS_NAME: ${{ matrix.os }} 42 | 43 | steps: 44 | - name: Checkout 45 | uses: actions/checkout@v4 46 | 47 | - name: Set up Python 48 | uses: actions/setup-python@v5 49 | with: 50 | python-version: ${{ matrix.python-version }} 51 | cache: "pip" 52 | cache-dependency-path: "setup.py" 53 | 54 | - name: Install dependencies 55 | run: | 56 | python -m pip install --upgrade pip 57 | python -m pip install ".[torch,dev]" 58 | 59 | - name: Check quality 60 | run: | 61 | make style && make quality 62 | 63 | - name: Test with pytest 64 | run: | 65 | make test 66 | -------------------------------------------------------------------------------- /LLaMA-Factory/.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/pre-commit/pre-commit-hooks 3 | rev: v5.0.0 4 | hooks: 5 | - id: check-ast 6 | - id: check-added-large-files 7 | args: ['--maxkb=25000'] 8 | - id: check-merge-conflict 9 | - id: check-yaml 10 | - id: debug-statements 11 | - id: end-of-file-fixer 12 | - id: trailing-whitespace 13 | args: [--markdown-linebreak-ext=md] 14 | - id: no-commit-to-branch 15 | args: ['--branch', 'main'] 16 | 17 | - repo: https://github.com/asottile/pyupgrade 18 | rev: v3.17.0 19 | hooks: 20 | - id: pyupgrade 21 | args: [--py38-plus] 22 | 23 | - repo: https://github.com/astral-sh/ruff-pre-commit 24 | rev: v0.6.9 25 | hooks: 26 | - id: ruff 27 | args: [--fix] 28 | - id: ruff-format 29 | -------------------------------------------------------------------------------- /LLaMA-Factory/CITATION.cff: -------------------------------------------------------------------------------- 1 | cff-version: 1.2.0 2 | date-released: 2024-03 3 | message: "If you use this software, please cite it as below." 4 | authors: 5 | - family-names: "Zheng" 6 | given-names: "Yaowei" 7 | - family-names: "Zhang" 8 | given-names: "Richong" 9 | - family-names: "Zhang" 10 | given-names: "Junhao" 11 | - family-names: "Ye" 12 | given-names: "Yanhan" 13 | - family-names: "Luo" 14 | given-names: "Zheyan" 15 | - family-names: "Feng" 16 | given-names: "Zhangchi" 17 | - family-names: "Ma" 18 | given-names: "Yongqiang" 19 | title: "LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models" 20 | url: "https://arxiv.org/abs/2403.13372" 21 | preferred-citation: 22 | type: conference-paper 23 | conference: 24 | name: "Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 3: System Demonstrations)" 25 | authors: 26 | - family-names: "Zheng" 27 | given-names: "Yaowei" 28 | - family-names: "Zhang" 29 | given-names: "Richong" 30 | - family-names: "Zhang" 31 | given-names: "Junhao" 32 | - family-names: "Ye" 33 | given-names: "Yanhan" 34 | - family-names: "Luo" 35 | given-names: "Zheyan" 36 | - family-names: "Feng" 37 | given-names: "Zhangchi" 38 | - family-names: "Ma" 39 | given-names: "Yongqiang" 40 | title: "LlamaFactory: Unified Efficient Fine-Tuning of 100+ Language Models" 41 | url: "https://arxiv.org/abs/2403.13372" 42 | year: 2024 43 | publisher: "Association for Computational Linguistics" 44 | address: "Bangkok, Thailand" 45 | -------------------------------------------------------------------------------- /LLaMA-Factory/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include LICENSE requirements.txt 2 | -------------------------------------------------------------------------------- /LLaMA-Factory/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: build commit quality style test 2 | 3 | check_dirs := scripts src tests setup.py 4 | 5 | build: 6 | pip install build && python -m build 7 | 8 | commit: 9 | pre-commit install 10 | pre-commit run --all-files 11 | 12 | quality: 13 | ruff check $(check_dirs) 14 | ruff format --check $(check_dirs) 15 | 16 | style: 17 | ruff check $(check_dirs) --fix 18 | ruff format $(check_dirs) 19 | 20 | test: 21 | CUDA_VISIBLE_DEVICES= WANDB_DISABLED=true pytest -vv tests/ 22 | -------------------------------------------------------------------------------- /LLaMA-Factory/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/assets/logo.png -------------------------------------------------------------------------------- /LLaMA-Factory/assets/wechat.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/assets/wechat.jpg -------------------------------------------------------------------------------- /LLaMA-Factory/assets/wechat_npu.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/assets/wechat_npu.jpg -------------------------------------------------------------------------------- /LLaMA-Factory/data/belle_multiturn/belle_multiturn.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | import datasets 5 | 6 | 7 | _HF_ENDPOINT = os.getenv("HF_ENDPOINT", "https://huggingface.co") 8 | 9 | _DESCRIPTION = "BELLE multiturn chat dataset." 10 | 11 | _CITATION = """\ 12 | @article{belle2023exploring, 13 | title={Exploring the Impact of Instruction Data Scaling on Large Language Models: An Empirical Study on Real-World Use Cases}, 14 | author={Yunjie Ji, Yong Deng, Yan Gong, Yiping Peng, Qiang Niu, Lei Zhang, Baochang Ma, Xiangang Li}, 15 | journal={arXiv preprint arXiv:2303.14742}, 16 | year={2023} 17 | } 18 | """ 19 | 20 | _HOMEPAGE = f"{_HF_ENDPOINT}/datasets/BelleGroup/multiturn_chat_0.8M" 21 | _LICENSE = "gpl-3.0" 22 | _URL = f"{_HF_ENDPOINT}/datasets/BelleGroup/multiturn_chat_0.8M/resolve/main/multiturn_chat_0.8M.json" 23 | 24 | 25 | class BelleMultiturn(datasets.GeneratorBasedBuilder): 26 | VERSION = datasets.Version("0.0.0") 27 | 28 | def _info(self): 29 | features = datasets.Features( 30 | {"conversations": [{"from": datasets.Value("string"), "value": datasets.Value("string")}]} 31 | ) 32 | return datasets.DatasetInfo( 33 | description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION 34 | ) 35 | 36 | def _split_generators(self, dl_manager: datasets.DownloadManager): 37 | file_path = dl_manager.download(_URL) 38 | return [datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": file_path})] 39 | 40 | def _generate_examples(self, filepath: str): 41 | with open(filepath, encoding="utf-8") as f: 42 | for key, row in enumerate(f): 43 | data = json.loads(row) 44 | conversations = [] 45 | prompt = data["instruction"].strip() 46 | response = data["output"].strip() 47 | 48 | assist_idx = prompt.rfind("Assistant:") 49 | human_idx = prompt.rfind("Human:") 50 | query = prompt[human_idx + 6 : assist_idx].strip() 51 | prompt = prompt[:human_idx].strip() 52 | conversations.insert(0, {"from": "gpt", "value": response}) 53 | conversations.insert(0, {"from": "human", "value": query}) 54 | 55 | while prompt.rfind("Assistant:") != -1: 56 | assist_idx = prompt.rfind("Assistant:") 57 | human_idx = prompt.rfind("Human:") 58 | if human_idx != -1: 59 | old_query = prompt[human_idx + 6 : assist_idx].strip() 60 | old_resp = prompt[assist_idx + 10 :].strip() 61 | conversations.insert(0, {"from": "gpt", "value": old_resp}) 62 | conversations.insert(0, {"from": "human", "value": old_query}) 63 | else: 64 | break 65 | prompt = prompt[:human_idx].strip() 66 | 67 | yield key, {"conversations": conversations} 68 | -------------------------------------------------------------------------------- /LLaMA-Factory/data/mllm_demo.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "messages": [ 4 | { 5 | "content": "Who are they?", 6 | "role": "user" 7 | }, 8 | { 9 | "content": "They're Kane and Gretzka from Bayern Munich.", 10 | "role": "assistant" 11 | }, 12 | { 13 | "content": "What are they doing?", 14 | "role": "user" 15 | }, 16 | { 17 | "content": "They are celebrating on the soccer field.", 18 | "role": "assistant" 19 | } 20 | ], 21 | "images": [ 22 | "mllm_demo_data/1.jpg" 23 | ] 24 | }, 25 | { 26 | "messages": [ 27 | { 28 | "content": "Who is he?", 29 | "role": "user" 30 | }, 31 | { 32 | "content": "He's Thomas Muller from Bayern Munich.", 33 | "role": "assistant" 34 | }, 35 | { 36 | "content": "Why is he on the ground?", 37 | "role": "user" 38 | }, 39 | { 40 | "content": "Because he's sliding on his knees to celebrate.", 41 | "role": "assistant" 42 | } 43 | ], 44 | "images": [ 45 | "mllm_demo_data/2.jpg" 46 | ] 47 | }, 48 | { 49 | "messages": [ 50 | { 51 | "content": "Please describe this image", 52 | "role": "user" 53 | }, 54 | { 55 | "content": "Chinese astronaut Gui Haichao is giving a speech.", 56 | "role": "assistant" 57 | }, 58 | { 59 | "content": "What has he accomplished?", 60 | "role": "user" 61 | }, 62 | { 63 | "content": "He was appointed to be a payload specialist on Shenzhou 16 mission in June 2022, thus becoming the first Chinese civilian of Group 3 in space on 30 May 2023. He is responsible for the on-orbit operation of space science experimental payloads.", 64 | "role": "assistant" 65 | } 66 | ], 67 | "images": [ 68 | "mllm_demo_data/3.jpg" 69 | ] 70 | }, 71 | { 72 | "messages": [ 73 | { 74 | "content": "他们是谁?", 75 | "role": "user" 76 | }, 77 | { 78 | "content": "他们是拜仁慕尼黑的凯恩和格雷茨卡。", 79 | "role": "assistant" 80 | }, 81 | { 82 | "content": "他们在做什么?", 83 | "role": "user" 84 | }, 85 | { 86 | "content": "他们在足球场上庆祝。", 87 | "role": "assistant" 88 | } 89 | ], 90 | "images": [ 91 | "mllm_demo_data/1.jpg" 92 | ] 93 | }, 94 | { 95 | "messages": [ 96 | { 97 | "content": "他是谁?", 98 | "role": "user" 99 | }, 100 | { 101 | "content": "他是来自拜仁慕尼黑的托马斯·穆勒。", 102 | "role": "assistant" 103 | }, 104 | { 105 | "content": "他为什么在地上?", 106 | "role": "user" 107 | }, 108 | { 109 | "content": "因为他正在双膝跪地滑行庆祝。", 110 | "role": "assistant" 111 | } 112 | ], 113 | "images": [ 114 | "mllm_demo_data/2.jpg" 115 | ] 116 | }, 117 | { 118 | "messages": [ 119 | { 120 | "content": "请描述这张图片", 121 | "role": "user" 122 | }, 123 | { 124 | "content": "中国宇航员桂海潮正在讲话。", 125 | "role": "assistant" 126 | }, 127 | { 128 | "content": "他取得过哪些成就?", 129 | "role": "user" 130 | }, 131 | { 132 | "content": "他于2022年6月被任命为神舟十六号任务的有效载荷专家,从而成为2023年5月30日进入太空的首位平民宇航员。他负责在轨操作空间科学实验有效载荷。", 133 | "role": "assistant" 134 | } 135 | ], 136 | "images": [ 137 | "mllm_demo_data/3.jpg" 138 | ] 139 | } 140 | ] 141 | -------------------------------------------------------------------------------- /LLaMA-Factory/data/mllm_demo_data/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/data/mllm_demo_data/1.jpg -------------------------------------------------------------------------------- /LLaMA-Factory/data/mllm_demo_data/1.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/data/mllm_demo_data/1.mp4 -------------------------------------------------------------------------------- /LLaMA-Factory/data/mllm_demo_data/2.avi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/data/mllm_demo_data/2.avi -------------------------------------------------------------------------------- /LLaMA-Factory/data/mllm_demo_data/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/data/mllm_demo_data/2.jpg -------------------------------------------------------------------------------- /LLaMA-Factory/data/mllm_demo_data/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/data/mllm_demo_data/3.jpg -------------------------------------------------------------------------------- /LLaMA-Factory/data/mllm_demo_data/3.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/WooooDyy/MathCritique/569e62eb4864610b4190c37ff4ea28364e474563/LLaMA-Factory/data/mllm_demo_data/3.mp4 -------------------------------------------------------------------------------- /LLaMA-Factory/data/mllm_video_demo.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "messages": [ 4 | { 5 | "content": "