diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/CODE_OF_CONDUCT.md b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000000000000000000000000000000000000..c2035cea5425b8de8e88a563214d05dfd415352a --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +`hoshihiyouga AT gmail DOT com`. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/CONTRIBUTING.md b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/CONTRIBUTING.md new file mode 100644 index 0000000000000000000000000000000000000000..507d666a23fc35f51b931e4f032c6d4b07872a45 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/CONTRIBUTING.md @@ -0,0 +1,67 @@ +# Contributing to LLaMA Factory + +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. + +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. + +However you choose to contribute, please be mindful and respect our [code of conduct](CODE_OF_CONDUCT.md). + +**This guide was heavily inspired by [transformers guide to contributing](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md).** + +## Ways to contribute + +There are several ways you can contribute to LLaMA Factory: + +* Fix outstanding issues with the existing code. +* Submit issues related to bugs or desired new features. +* Contribute to the examples or to the documentation. + +### Style guide + +LLaMA Factory follows the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html), check it for details. + +### Create a Pull Request + +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. + +2. Clone your fork to your local disk, and add the base repository as a remote: + +```bash +git clone git@github.com:[username]/LLaMA-Factory.git +cd LLaMA-Factory +git remote add upstream https://github.com/hiyouga/LLaMA-Factory.git +``` + +3. Create a new branch to hold your development changes: + +```bash +git checkout -b dev_your_branch +``` + +4. Set up a development environment by running the following command in a virtual environment: + +```bash +pip install -e ".[dev]" +``` + +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. + +5. Check code before commit: + +```bash +make commit +make style && make quality +make test +``` + +6. Submit changes: + +```bash +git add . +git commit -m "commit message" +git fetch upstream +git rebase upstream/main +git push -u origin dev_your_branch +``` + +7. Create a merge request from your branch `dev_your_branch` at [origin repo](https://github.com/hiyouga/LLaMA-Factory). diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/1-bug-report.yml b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/1-bug-report.yml new file mode 100644 index 0000000000000000000000000000000000000000..7ffb427ce263792ab8cea5252a1a85b03d75ac89 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/1-bug-report.yml @@ -0,0 +1,63 @@ +name: "\U0001F41B Bug / help" +description: Create a report to help us improve the LLaMA Factory +labels: ["bug", "pending"] +body: + - type: markdown + attributes: + value: | + Issues included in **[FAQs](https://github.com/hiyouga/LLaMA-Factory/issues/4614)** or those with **insufficient** information may be closed without a response. + 已经包含在 **[常见问题](https://github.com/hiyouga/LLaMA-Factory/issues/4614)** 内或提供信息**不完整**的 issues 可能不会被回复。 + + - type: markdown + attributes: + value: | + Please do not create issues that are not related to framework bugs under this category, use **[Discussions](https://github.com/hiyouga/LLaMA-Factory/discussions/categories/q-a)** instead. + 请勿在此分类下创建和框架 bug 无关的 issues,请使用 **[讨论区](https://github.com/hiyouga/LLaMA-Factory/discussions/categories/q-a)**。 + + - type: checkboxes + id: reminder + attributes: + label: Reminder + description: | + Please ensure you have read the above rules carefully and searched the existing issues (including FAQs). + 请确保您已经认真阅读了上述规则并且搜索过现有的 issues(包括常见问题)。 + + options: + - label: I have read the above rules and searched the existing issues. + required: true + + - type: textarea + id: system-info + validations: + required: true + attributes: + label: System Info + description: | + Please share your system info with us. You can run the command **llamafactory-cli env** and copy-paste its output below. + 请提供您的系统信息。您可以在命令行运行 **llamafactory-cli env** 并将其输出复制到该文本框中。 + + placeholder: llamafactory version, platform, python version, ... + + - type: textarea + id: reproduction + validations: + required: true + attributes: + label: Reproduction + description: | + Please provide entry arguments, error messages and stack traces that reproduces the problem. + 请提供入口参数,错误日志以及异常堆栈以便于我们复现问题。 + Remember to wrap your log messages with \`\`\`. + 请务必使用 Markdown 标签 \`\`\` 来包裹您的日志信息。 + + value: | + ```text + Put your message here. + ``` + + - type: textarea + id: others + validations: + required: false + attributes: + label: Others diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/2-feature-request.yml b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/2-feature-request.yml new file mode 100644 index 0000000000000000000000000000000000000000..5d72271ebc8db3d10bf7e9c6af209e857566bde6 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/2-feature-request.yml @@ -0,0 +1,41 @@ +name: "\U0001F680 Feature request" +description: Submit a request for a new feature +labels: ["enhancement", "pending"] +body: + - type: markdown + attributes: + value: | + Please do not create issues that are not related to new features under this category. + 请勿在此分类下创建和新特性无关的 issues。 + + - type: checkboxes + id: reminder + attributes: + label: Reminder + description: | + Please ensure you have read the above rules carefully and searched the existing issues. + 请确保您已经认真阅读了上述规则并且搜索过现有的 issues。 + + options: + - label: I have read the above rules and searched the existing issues. + required: true + + - type: textarea + id: description + validations: + required: true + attributes: + label: Description + description: | + A clear and concise description of the feature proposal. + 请详细描述您希望加入的新功能特性。 + + - type: textarea + id: contribution + validations: + required: false + attributes: + label: Pull Request + description: | + Have you already created the relevant PR and submitted the code? + 您是否已经创建了相关 PR 并提交了代码? diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/config.yml b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000000000000000000000000000000000000..3ba13e0cec6cbbfd462e9ebf529dd2093148cd69 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/PULL_REQUEST_TEMPLATE.md b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000000000000000000000000000000000000..d23d6be3cfb8e2db888b19becedf075c7aa527be --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,8 @@ +# What does this PR do? + +Fixes # (issue) + +## Before submitting + +- [ ] Did you read the [contributor guideline](https://github.com/hiyouga/LLaMA-Factory/blob/main/.github/CONTRIBUTING.md)? +- [ ] Did you write any new necessary tests? diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/SECURITY.md b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/SECURITY.md new file mode 100644 index 0000000000000000000000000000000000000000..d34728ebfeb22e9fda2f3e76ff133014b648ab3c --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/SECURITY.md @@ -0,0 +1,7 @@ +# Reporting Security Issues + +To report a security issue, please use the GitHub Security Advisory ["Report a Vulnerability"](https://github.com/hiyouga/LLaMA-Factory/security/advisories/new) tab. + +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. + +Report security bugs in third-party modules to the person or team maintaining the module. diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/label_issue.yml b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/label_issue.yml new file mode 100644 index 0000000000000000000000000000000000000000..b7469f6a1fd2adfd1bd868548014b0bf9a22cd1e --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/label_issue.yml @@ -0,0 +1,32 @@ +name: label_issue + +on: + issues: + types: + - opened + +jobs: + label_issue: + runs-on: ubuntu-latest + + permissions: + issues: write + + steps: + - env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + ISSUE_URL: ${{ github.event.issue.html_url }} + ISSUE_TITLE: ${{ github.event.issue.title }} + run: | + LABEL="" + NPU_KEYWORDS=(npu huawei ascend 华为 昇腾) + ISSUE_TITLE_LOWER=$(echo $ISSUE_TITLE | tr '[:upper:]' '[:lower:]') + for KEYWORD in ${NPU_KEYWORDS[@]}; do + if [[ $ISSUE_TITLE_LOWER == *$KEYWORD* ]] && [[ $ISSUE_TITLE_LOWER != *input* ]]; then + LABEL="npu" + break + fi + done + if [ -n "$LABEL" ]; then + gh issue edit $ISSUE_URL --add-label $LABEL + fi diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/publish.yml b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/publish.yml new file mode 100644 index 0000000000000000000000000000000000000000..5d7320639053637989556fb7b2238da2b5bda82c --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/publish.yml @@ -0,0 +1,40 @@ +name: publish + +on: + release: + types: + - published + +jobs: + publish: + name: Upload release to PyPI + + runs-on: ubuntu-latest + + environment: + name: release + url: https://pypi.org/p/llamafactory + + permissions: + id-token: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.9" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install build + + - name: Build package + run: | + python -m build + + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/tests.yml b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/tests.yml new file mode 100644 index 0000000000000000000000000000000000000000..fdcd3eab28e884f420a750a31736ecdfa2b51767 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/.github/workflows/tests.yml @@ -0,0 +1,62 @@ +name: tests + +on: + push: + branches: + - "main" + paths: + - "**.py" + - "requirements.txt" + - ".github/workflows/*.yml" + pull_request: + branches: + - "main" + paths: + - "**.py" + - "requirements.txt" + - ".github/workflows/*.yml" + +jobs: + tests: + strategy: + fail-fast: false + matrix: + python-version: + - "3.9" + - "3.10" + - "3.11" + - "3.12" + os: + - "ubuntu-latest" + - "windows-latest" + - "macos-13" + + runs-on: ${{ matrix.os }} + + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + OS_NAME: ${{ matrix.os }} + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + cache: "pip" + cache-dependency-path: "setup.py" + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install ".[torch,dev]" + + - name: Check quality + run: | + make style && make quality + + - name: Test with pytest + run: | + make test diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z0_config.json b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z0_config.json new file mode 100644 index 0000000000000000000000000000000000000000..46c5ea474ea896f4eeb8d3e33472fc0c9dbfeac7 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z0_config.json @@ -0,0 +1,28 @@ +{ + "train_batch_size": "auto", + "train_micro_batch_size_per_gpu": "auto", + "gradient_accumulation_steps": "auto", + "gradient_clipping": "auto", + "zero_allow_untested_optimizer": true, + "fp16": { + "enabled": "auto", + "loss_scale": 0, + "loss_scale_window": 1000, + "initial_scale_power": 16, + "hysteresis": 2, + "min_loss_scale": 1 + }, + "bf16": { + "enabled": "auto" + }, + "zero_optimization": { + "stage": 0, + "allgather_partitions": true, + "allgather_bucket_size": 5e8, + "overlap_comm": true, + "reduce_scatter": true, + "reduce_bucket_size": 5e8, + "contiguous_gradients": true, + "round_robin_gradients": true + } +} diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z2_config.json b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z2_config.json new file mode 100644 index 0000000000000000000000000000000000000000..c2ffe80dbe1886f582287f7326d9805b0b6c03a1 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z2_config.json @@ -0,0 +1,28 @@ +{ + "train_batch_size": "auto", + "train_micro_batch_size_per_gpu": "auto", + "gradient_accumulation_steps": "auto", + "gradient_clipping": "auto", + "zero_allow_untested_optimizer": true, + "fp16": { + "enabled": "auto", + "loss_scale": 0, + "loss_scale_window": 1000, + "initial_scale_power": 16, + "hysteresis": 2, + "min_loss_scale": 1 + }, + "bf16": { + "enabled": "auto" + }, + "zero_optimization": { + "stage": 2, + "allgather_partitions": true, + "allgather_bucket_size": 5e8, + "overlap_comm": true, + "reduce_scatter": true, + "reduce_bucket_size": 5e8, + "contiguous_gradients": true, + "round_robin_gradients": true + } +} diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z2_offload_config.json b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z2_offload_config.json new file mode 100644 index 0000000000000000000000000000000000000000..93f1519a7b5e6599c8c4aacce7bca6e0837f6174 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z2_offload_config.json @@ -0,0 +1,32 @@ +{ + "train_batch_size": "auto", + "train_micro_batch_size_per_gpu": "auto", + "gradient_accumulation_steps": "auto", + "gradient_clipping": "auto", + "zero_allow_untested_optimizer": true, + "fp16": { + "enabled": "auto", + "loss_scale": 0, + "loss_scale_window": 1000, + "initial_scale_power": 16, + "hysteresis": 2, + "min_loss_scale": 1 + }, + "bf16": { + "enabled": "auto" + }, + "zero_optimization": { + "stage": 2, + "offload_optimizer": { + "device": "cpu", + "pin_memory": true + }, + "allgather_partitions": true, + "allgather_bucket_size": 5e8, + "overlap_comm": true, + "reduce_scatter": true, + "reduce_bucket_size": 5e8, + "contiguous_gradients": true, + "round_robin_gradients": true + } +} diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z3_config.json b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z3_config.json new file mode 100644 index 0000000000000000000000000000000000000000..6acbe52063a58e8825d7a5660fd26db8b2477b7f --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z3_config.json @@ -0,0 +1,30 @@ +{ + "train_batch_size": "auto", + "train_micro_batch_size_per_gpu": "auto", + "gradient_accumulation_steps": "auto", + "gradient_clipping": "auto", + "zero_allow_untested_optimizer": true, + "fp16": { + "enabled": "auto", + "loss_scale": 0, + "loss_scale_window": 1000, + "initial_scale_power": 16, + "hysteresis": 2, + "min_loss_scale": 1 + }, + "bf16": { + "enabled": "auto" + }, + "zero_optimization": { + "stage": 3, + "overlap_comm": true, + "contiguous_gradients": true, + "sub_group_size": 1e9, + "reduce_bucket_size": "auto", + "stage3_prefetch_bucket_size": "auto", + "stage3_param_persistence_threshold": "auto", + "stage3_max_live_parameters": 1e9, + "stage3_max_reuse_distance": 1e9, + "stage3_gather_16bit_weights_on_model_save": true + } +} diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z3_offload_config.json b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z3_offload_config.json new file mode 100644 index 0000000000000000000000000000000000000000..b92f96a935f86acb8fffcbefceba2b8c1db9a69f --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/deepspeed/ds_z3_offload_config.json @@ -0,0 +1,38 @@ +{ + "train_batch_size": "auto", + "train_micro_batch_size_per_gpu": "auto", + "gradient_accumulation_steps": "auto", + "gradient_clipping": "auto", + "zero_allow_untested_optimizer": true, + "fp16": { + "enabled": "auto", + "loss_scale": 0, + "loss_scale_window": 1000, + "initial_scale_power": 16, + "hysteresis": 2, + "min_loss_scale": 1 + }, + "bf16": { + "enabled": "auto" + }, + "zero_optimization": { + "stage": 3, + "offload_optimizer": { + "device": "cpu", + "pin_memory": true + }, + "offload_param": { + "device": "cpu", + "pin_memory": true + }, + "overlap_comm": true, + "contiguous_gradients": true, + "sub_group_size": 1e9, + "reduce_bucket_size": "auto", + "stage3_prefetch_bucket_size": "auto", + "stage3_param_persistence_threshold": "auto", + "stage3_max_live_parameters": 1e9, + "stage3_max_reuse_distance": 1e9, + "stage3_gather_16bit_weights_on_model_save": true + } +} diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/adam_mini/qwen2_full_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/adam_mini/qwen2_full_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..e1c14e07dcb5acb1075b2990cd5869ad211c6082 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/adam_mini/qwen2_full_sft.yaml @@ -0,0 +1,40 @@ +### model +model_name_or_path: Qwen/Qwen2-1.5B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: full +use_adam_mini: true + +### dataset +dataset: identity,alpaca_en_demo +template: qwen +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/qwen2-1_5b/full/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-5 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/apollo/llama3_full_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/apollo/llama3_full_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..9b782b67325c4b528f74b01c494a6c35ff139af7 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/apollo/llama3_full_sft.yaml @@ -0,0 +1,45 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: full +use_apollo: true +apollo_layerwise: true # choices: [true, false], use false for DDP training +apollo_target: all +apollo_rank: 128 +apollo_scale: 32.0 +apollo_scale_type: channel + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/full/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 1 # use 1 for layerwise apollo +learning_rate: 1.0e-5 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +pure_bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/badam/llama3_full_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/badam/llama3_full_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..57d6729df738417b45e9fc9595b16c6839e4faee --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/badam/llama3_full_sft.yaml @@ -0,0 +1,43 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: full +use_badam: true +badam_mode: layer +badam_switch_mode: ascending +badam_switch_interval: 50 +badam_verbose: 2 +# deepspeed: examples/deepspeed/ds_z3_config.json + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/full/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-5 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/fsdp_qlora/llama3_lora_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/fsdp_qlora/llama3_lora_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..f50fe7250a5035361c79a83511086c39fc79bb76 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/fsdp_qlora/llama3_lora_sft.yaml @@ -0,0 +1,42 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +quantization_bit: 4 +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/fsdp_qlora/train.sh b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/fsdp_qlora/train.sh new file mode 100644 index 0000000000000000000000000000000000000000..fac8cdee8781750d96e29999ab8a6b9b4f1bc322 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/fsdp_qlora/train.sh @@ -0,0 +1,6 @@ +#!/bin/bash +# DO NOT use GPTQ/AWQ model in FSDP+QLoRA + +CUDA_VISIBLE_DEVICES=0,1 accelerate launch \ + --config_file examples/accelerate/fsdp_config.yaml \ + src/train.py examples/extras/fsdp_qlora/llama3_lora_sft.yaml diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/galore/llama3_full_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/galore/llama3_full_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7540da4fb8c482bf6d8ca434a5e096647dcd4ecc --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/galore/llama3_full_sft.yaml @@ -0,0 +1,44 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: full +use_galore: true +galore_layerwise: true # choices: [true, false], use false for DDP training +galore_target: all +galore_rank: 128 +galore_scale: 2.0 + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/full/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 1 # use 1 for layerwise galore +learning_rate: 1.0e-5 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +pure_bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/llama_pro/expand.sh b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/llama_pro/expand.sh new file mode 100644 index 0000000000000000000000000000000000000000..9f3c013cf2479464637d90e020ca76aea8558b05 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/llama_pro/expand.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +python scripts/llama_pro.py \ + --model_name_or_path meta-llama/Meta-Llama-3-8B-Instruct \ + --output_dir models/llama3-8b-pro \ + --num_expand 8 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/llama_pro/llama3_freeze_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/llama_pro/llama3_freeze_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6d51ceee517a02ca97cf8e8d531c7b1a0f9b2ffe --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/llama_pro/llama3_freeze_sft.yaml @@ -0,0 +1,42 @@ +### model +model_name_or_path: models/llama3-8b-pro +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: freeze +freeze_trainable_layers: 8 +freeze_trainable_modules: all +use_llama_pro: true + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b-pro/freeze/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/loraplus/llama3_lora_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/loraplus/llama3_lora_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..cbecf63291d0a8b61de6905215a946ff9d63fdec --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/loraplus/llama3_lora_sft.yaml @@ -0,0 +1,42 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all +loraplus_lr_ratio: 16.0 + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/mod/llama3_full_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/mod/llama3_full_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4799a826669c8fa3d5be7f4f08484dd5060ad7a4 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/mod/llama3_full_sft.yaml @@ -0,0 +1,41 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: full +mixture_of_depths: convert + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b-mod/full/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +optim: paged_adamw_8bit +learning_rate: 1.0e-5 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +pure_bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/nlg_eval/llama3_lora_predict.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/nlg_eval/llama3_lora_predict.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2d0dfad35399f8146cd9854291ee9b46c945a8f9 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/nlg_eval/llama3_lora_predict.yaml @@ -0,0 +1,29 @@ +# The batch generation can be SLOW using this config. +# For faster inference, we recommend to use `scripts/vllm_infer.py`. + +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +adapter_name_or_path: saves/llama3-8b/lora/sft +trust_remote_code: true + +### method +stage: sft +do_predict: true +finetuning_type: lora + +### dataset +eval_dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 50 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/predict +overwrite_output_dir: true + +### eval +per_device_eval_batch_size: 1 +predict_with_generate: true +ddp_timeout: 180000000 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/pissa/init.sh b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/pissa/init.sh new file mode 100644 index 0000000000000000000000000000000000000000..11e1e3576433aedf7471124f705e6e4e2fe2d331 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/pissa/init.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +python scripts/pissa_init.py \ + --model_name_or_path meta-llama/Meta-Llama-3-8B-Instruct \ + --output_dir models/llama3-8b-pissa diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/pissa/llama3_lora_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/pissa/llama3_lora_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5827f6a514539bcc82357dadff5a699f19930175 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/extras/pissa/llama3_lora_sft.yaml @@ -0,0 +1,44 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all +pissa_init: true +pissa_iter: 16 +pissa_convert: true + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/.ipynb_checkpoints/qwen2_vl-checkpoint.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/.ipynb_checkpoints/qwen2_vl-checkpoint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4b0791eeede42b3b6042fa5a6a3693ed1af4c595 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/.ipynb_checkpoints/qwen2_vl-checkpoint.yaml @@ -0,0 +1,4 @@ +model_name_or_path: ../saves/qwen2_vl-7b/lora/sft +template: qwen2_vl +infer_backend: huggingface # choices: [huggingface, vllm] +trust_remote_code: true diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2851e9a370d368b70f13767918e2d0249b077d4d --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3.yaml @@ -0,0 +1,4 @@ +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +template: llama3 +infer_backend: huggingface # choices: [huggingface, vllm] +trust_remote_code: true diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_full_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_full_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d4555ca818d722749ae372ac550558d03a57cde3 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_full_sft.yaml @@ -0,0 +1,4 @@ +model_name_or_path: saves/llama3-8b/full/sft +template: llama3 +infer_backend: huggingface # choices: [huggingface, vllm] +trust_remote_code: true diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_lora_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_lora_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7796c52690f71393b8f21a9f979f01a8ead75034 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_lora_sft.yaml @@ -0,0 +1,5 @@ +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +adapter_name_or_path: saves/llama3-8b/lora/sft +template: llama3 +infer_backend: huggingface # choices: [huggingface, vllm] +trust_remote_code: true diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_vllm.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_vllm.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4379956c1604f4e97df86e7278d1894c3418b5c8 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llama3_vllm.yaml @@ -0,0 +1,5 @@ +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +template: llama3 +infer_backend: vllm +vllm_enforce_eager: true +trust_remote_code: true diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llava1_5.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llava1_5.yaml new file mode 100644 index 0000000000000000000000000000000000000000..2e934ddc8033ab88412804fa26a6a6d6f4ba7815 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/llava1_5.yaml @@ -0,0 +1,4 @@ +model_name_or_path: llava-hf/llava-1.5-7b-hf +template: llava +infer_backend: huggingface # choices: [huggingface, vllm] +trust_remote_code: true diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/qwen2_vl.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/qwen2_vl.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4b0791eeede42b3b6042fa5a6a3693ed1af4c595 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/inference/qwen2_vl.yaml @@ -0,0 +1,4 @@ +model_name_or_path: ../saves/qwen2_vl-7b/lora/sft +template: qwen2_vl +infer_backend: huggingface # choices: [huggingface, vllm] +trust_remote_code: true diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_full/llama3_full_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_full/llama3_full_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8ceea70ce7cf206077d2efc5778620368b4dcd95 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_full/llama3_full_sft.yaml @@ -0,0 +1,40 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: full +deepspeed: examples/deepspeed/ds_z3_config.json # choices: [ds_z0_config.json, ds_z2_config.json, ds_z3_config.json] + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/full/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 2 +learning_rate: 1.0e-5 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_full/qwen2vl_full_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_full/qwen2vl_full_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..bdf28fe947143b53444f5c7db1b7fd8a0d4356bf --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_full/qwen2vl_full_sft.yaml @@ -0,0 +1,45 @@ +### model +model_name_or_path: Qwen/Qwen2-VL-7B-Instruct +image_max_pixels: 262144 +video_max_pixels: 16384 +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: full +freeze_vision_tower: true # choices: [true, false] +freeze_multi_modal_projector: true # choices: [true, false] +train_mm_proj_only: false # choices: [true, false] +deepspeed: examples/deepspeed/ds_z3_config.json # choices: [ds_z0_config.json, ds_z2_config.json, ds_z3_config.json] + +### dataset +dataset: mllm_demo,identity,alpaca_en_demo +template: qwen2_vl +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/qwen2_vl-7b/full/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 2 +learning_rate: 1.0e-5 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/.ipynb_checkpoints/qwen2vl_lora_sft-checkpoint.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/.ipynb_checkpoints/qwen2vl_lora_sft-checkpoint.yaml new file mode 100644 index 0000000000000000000000000000000000000000..482fe35309feb73c5723a645d41d771fc727c098 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/.ipynb_checkpoints/qwen2vl_lora_sft-checkpoint.yaml @@ -0,0 +1,43 @@ +### model +model_name_or_path: ../Qwen/Qwen2-VL-7B +image_max_pixels: 262144 +video_max_pixels: 16384 +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: samples_120 +template: qwen2_vl +cutoff_len: 4096 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: ../finetune_checkpoints/qwen2_vl-7b_lora_sft_checkpoint +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_dpo.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_dpo.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6cef3995a7c5a3b4c4d3fe1e3712733fa9df3a10 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_dpo.yaml @@ -0,0 +1,43 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: dpo +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all +pref_beta: 0.1 +pref_loss: sigmoid # choices: [sigmoid (dpo), orpo, simpo] + +### dataset +dataset: dpo_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/dpo +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 5.0e-6 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_eval.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_eval.yaml new file mode 100644 index 0000000000000000000000000000000000000000..60d7c2f39f931b8445f393f69acacef1c5990203 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_eval.yaml @@ -0,0 +1,19 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +adapter_name_or_path: saves/llama3-8b/lora/sft +trust_remote_code: true + +### method +finetuning_type: lora + +### dataset +task: mmlu_test # choices: [mmlu_test, ceval_validation, cmmlu_test] +template: fewshot +lang: en +n_shot: 5 + +### output +save_dir: saves/llama3-8b/lora/eval + +### eval +batch_size: 4 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_kto.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_kto.yaml new file mode 100644 index 0000000000000000000000000000000000000000..980381ab66e867a672c76b02f2aaff2665590925 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_kto.yaml @@ -0,0 +1,42 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: kto +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all +pref_beta: 0.1 + +### dataset +dataset: kto_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/kto +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 5.0e-6 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_ppo.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_ppo.yaml new file mode 100644 index 0000000000000000000000000000000000000000..4efc3009f537c632131a335adbdc1fb9a6520778 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_ppo.yaml @@ -0,0 +1,41 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +reward_model: saves/llama3-8b/lora/reward +trust_remote_code: true + +### method +stage: ppo +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/ppo +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-5 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### generate +max_new_tokens: 512 +top_k: 0 +top_p: 0.9 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_pretrain.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_pretrain.yaml new file mode 100644 index 0000000000000000000000000000000000000000..8efe3d6a33a3459459f2a9bc47e308fae2dd9def --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_pretrain.yaml @@ -0,0 +1,40 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: pt +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: c4_demo +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/pretrain +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_reward.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_reward.yaml new file mode 100644 index 0000000000000000000000000000000000000000..247c69df388b68a085c6317b3499f096629288eb --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_reward.yaml @@ -0,0 +1,41 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: rm +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: dpo_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/reward +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a695318248182562830ea274701cc03ecc9fa9f8 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft.yaml @@ -0,0 +1,41 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft_ds3.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft_ds3.yaml new file mode 100644 index 0000000000000000000000000000000000000000..7bf91ec382706bf12c8c18ed759bda8214d8fbb5 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft_ds3.yaml @@ -0,0 +1,42 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all +deepspeed: examples/deepspeed/ds_z3_config.json # choices: [ds_z0_config.json, ds_z2_config.json, ds_z3_config.json] + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 2 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft_ray.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft_ray.yaml new file mode 100644 index 0000000000000000000000000000000000000000..58856a164a6bb0e363eaecd419697d62ff3f4678 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_lora_sft_ray.yaml @@ -0,0 +1,49 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct # or use local absolute path +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +dataset_dir: REMOTE:llamafactory/demo_data # or use local absolute path +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: tmp_dir +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### ray +ray_run_name: llama3_8b_sft_lora +ray_num_workers: 4 # number of GPUs to use +resources_per_worker: + GPU: 1 +placement_strategy: PACK + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_preprocess.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_preprocess.yaml new file mode 100644 index 0000000000000000000000000000000000000000..fbaf01f0f5a1156c87f229a8e2d02babb19cb9f0 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llama3_preprocess.yaml @@ -0,0 +1,23 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 +tokenized_path: saves/llama3-8b/dataset/sft + +### output +output_dir: saves/llama3-8b/lora/sft +overwrite_output_dir: true diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llava1_5_lora_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llava1_5_lora_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..24d09d915a5346fe3a8184618418036f59db3ab8 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/llava1_5_lora_sft.yaml @@ -0,0 +1,41 @@ +### model +model_name_or_path: llava-hf/llava-1.5-7b-hf +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: mllm_demo +template: llava +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llava1_5-7b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/qwen2vl_lora_dpo.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/qwen2vl_lora_dpo.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6fed819ed2ee598376412abaf8c92d7c1859d50d --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/qwen2vl_lora_dpo.yaml @@ -0,0 +1,45 @@ +### model +model_name_or_path: Qwen/Qwen2-VL-7B-Instruct +image_max_pixels: 262144 +video_max_pixels: 16384 +trust_remote_code: true + +### method +stage: dpo +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all +pref_beta: 0.1 +pref_loss: sigmoid # choices: [sigmoid (dpo), orpo, simpo] + +### dataset +dataset: rlhf_v +template: qwen2_vl +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/qwen2_vl-7b/lora/dpo +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 5.0e-6 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/qwen2vl_lora_sft.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/qwen2vl_lora_sft.yaml new file mode 100644 index 0000000000000000000000000000000000000000..d13ecb43580d5b4d52d458dc21eea52b01d89fbb --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_lora/qwen2vl_lora_sft.yaml @@ -0,0 +1,43 @@ +### model +model_name_or_path: ../Qwen/Qwen2-VL-7B +image_max_pixels: 262144 +video_max_pixels: 16384 +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: samples_120 +template: qwen2_vl +cutoff_len: 4096 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: ../finetune_checkpoints/qwen2_vl-7b_lora_sft_checkpoint +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 5 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_aqlm.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_aqlm.yaml new file mode 100644 index 0000000000000000000000000000000000000000..c035a504fd482898f078458334aca3ab62105f96 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_aqlm.yaml @@ -0,0 +1,41 @@ +### model +model_name_or_path: ISTA-DASLab/Meta-Llama-3-8B-Instruct-AQLM-2Bit-1x16 +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_awq.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_awq.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a9a970f0359523c0605985b54b68eaa5e428387e --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_awq.yaml @@ -0,0 +1,41 @@ +### model +model_name_or_path: TechxGenus/Meta-Llama-3-8B-Instruct-AWQ +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_bnb_npu.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_bnb_npu.yaml new file mode 100644 index 0000000000000000000000000000000000000000..5b768a98424e0cb78a19b1c6d85ffff87c9d4fe8 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_bnb_npu.yaml @@ -0,0 +1,44 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +quantization_bit: 4 +quantization_method: bitsandbytes +double_quantization: false +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_gptq.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_gptq.yaml new file mode 100644 index 0000000000000000000000000000000000000000..6c45e845410172f85648db4efe436a5df94edb27 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_gptq.yaml @@ -0,0 +1,41 @@ +### model +model_name_or_path: TechxGenus/Meta-Llama-3-8B-Instruct-GPTQ +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_otfq.yaml b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_otfq.yaml new file mode 100644 index 0000000000000000000000000000000000000000..cfe930e456a5192e242c8d7f719d4353fd3e38a8 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/examples/train_qlora/llama3_lora_sft_otfq.yaml @@ -0,0 +1,43 @@ +### model +model_name_or_path: meta-llama/Meta-Llama-3-8B-Instruct +quantization_bit: 4 +quantization_method: bitsandbytes # choices: [bitsandbytes (4/8), hqq (2/3/4/5/6/8), eetq (8)] +trust_remote_code: true + +### method +stage: sft +do_train: true +finetuning_type: lora +lora_rank: 8 +lora_target: all + +### dataset +dataset: identity,alpaca_en_demo +template: llama3 +cutoff_len: 2048 +max_samples: 1000 +overwrite_cache: true +preprocessing_num_workers: 16 + +### output +output_dir: saves/llama3-8b/lora/sft +logging_steps: 10 +save_steps: 500 +plot_loss: true +overwrite_output_dir: true + +### train +per_device_train_batch_size: 1 +gradient_accumulation_steps: 8 +learning_rate: 1.0e-4 +num_train_epochs: 3.0 +lr_scheduler_type: cosine +warmup_ratio: 0.1 +bf16: true +ddp_timeout: 180000000 + +### eval +# val_size: 0.1 +# per_device_eval_batch_size: 1 +# eval_strategy: steps +# eval_steps: 500 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/api.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/api.py new file mode 100644 index 0000000000000000000000000000000000000000..61215459ed91c6fa529a719cb9dac57223754d2e --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/api.py @@ -0,0 +1,33 @@ +# Copyright 2025 the LlamaFactory team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +import uvicorn + +from llamafactory.api.app import create_app +from llamafactory.chat import ChatModel + + +def main(): + chat_model = ChatModel() + app = create_app(chat_model) + api_host = os.getenv("API_HOST", "0.0.0.0") + api_port = int(os.getenv("API_PORT", "8000")) + print(f"Visit http://localhost:{api_port}/docs for API document.") + uvicorn.run(app, host=api_host, port=api_port) + + +if __name__ == "__main__": + main() diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__init__.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..2cfc5a3887f194ceb82acf6240b7c22a1c779b42 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__init__.py @@ -0,0 +1,47 @@ +# Copyright 2025 the LlamaFactory team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +r""" +Efficient fine-tuning of large language models. + +Level: + api, webui > chat, eval, train > data, model > hparams > extras + +Dependency graph: + main: + transformers>=4.41.2,<=4.49.0,!=4.46.*,!=4.47.*,!=4.48.0 + datasets>=2.16.0,<=3.2.0 + accelerate>=0.34.0,<=1.2.1 + peft>=0.11.1,<=0.12.0 + trl>=0.8.6,<=0.9.6 + attention: + transformers>=4.42.4 (gemma+fa2) + longlora: + transformers>=4.41.2,<4.48.0 + packing: + transformers>=4.43.0 + +Disable version checking: DISABLE_VERSION_CHECK=1 +Enable VRAM recording: RECORD_VRAM=1 +Force check imports: FORCE_CHECK_IMPORTS=1 +Force using torchrun: FORCE_TORCHRUN=1 +Set logging verbosity: LLAMAFACTORY_VERBOSITY=WARN +Use modelscope: USE_MODELSCOPE_HUB=1 +Use openmind: USE_OPENMIND_HUB=1 +""" + +from .extras.env import VERSION + + +__version__ = VERSION diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/__init__.cpython-310.pyc b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..febfcef10e35ddac7fcf82702caccf77305ccd02 Binary files /dev/null and b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/__init__.cpython-310.pyc differ diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/cli.cpython-310.pyc b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/cli.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..cd8968d4c489936f5bea10fed0af9e68339e70b7 Binary files /dev/null and b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/cli.cpython-310.pyc differ diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/launcher.cpython-310.pyc b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/launcher.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..e5dbeb3d36261be81259bb37c7e7593d04f16b80 Binary files /dev/null and b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/__pycache__/launcher.cpython-310.pyc differ diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/cli.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/cli.py new file mode 100644 index 0000000000000000000000000000000000000000..177618bb542702e55fd49a9d4ecf093644284faf --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/cli.py @@ -0,0 +1,126 @@ +# Copyright 2025 the LlamaFactory team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import random +import subprocess +import sys +from enum import Enum, unique + +from . import launcher +from .api.app import run_api +from .chat.chat_model import run_chat +from .eval.evaluator import run_eval +from .extras import logging +from .extras.env import VERSION, print_env +from .extras.misc import get_device_count, is_env_enabled, use_ray +from .train.tuner import export_model, run_exp +from .webui.interface import run_web_demo, run_web_ui + + +USAGE = ( + "-" * 70 + + "\n" + + "| Usage: |\n" + + "| llamafactory-cli api -h: launch an OpenAI-style API server |\n" + + "| llamafactory-cli chat -h: launch a chat interface in CLI |\n" + + "| llamafactory-cli eval -h: evaluate models |\n" + + "| llamafactory-cli export -h: merge LoRA adapters and export model |\n" + + "| llamafactory-cli train -h: train models |\n" + + "| llamafactory-cli webchat -h: launch a chat interface in Web UI |\n" + + "| llamafactory-cli webui: launch LlamaBoard |\n" + + "| llamafactory-cli version: show version info |\n" + + "-" * 70 +) + +WELCOME = ( + "-" * 58 + + "\n" + + f"| Welcome to LLaMA Factory, version {VERSION}" + + " " * (21 - len(VERSION)) + + "|\n|" + + " " * 56 + + "|\n" + + "| Project page: https://github.com/hiyouga/LLaMA-Factory |\n" + + "-" * 58 +) + +logger = logging.get_logger(__name__) + + +@unique +class Command(str, Enum): + API = "api" + CHAT = "chat" + ENV = "env" + EVAL = "eval" + EXPORT = "export" + TRAIN = "train" + WEBDEMO = "webchat" + WEBUI = "webui" + VER = "version" + HELP = "help" + + +def main(): + command = sys.argv.pop(1) if len(sys.argv) != 1 else Command.HELP + if command == Command.API: + run_api() + elif command == Command.CHAT: + run_chat() + elif command == Command.ENV: + print_env() + elif command == Command.EVAL: + run_eval() + elif command == Command.EXPORT: + export_model() + elif command == Command.TRAIN: + force_torchrun = is_env_enabled("FORCE_TORCHRUN") + if force_torchrun or (get_device_count() > 1 and not use_ray()): + master_addr = os.getenv("MASTER_ADDR", "127.0.0.1") + master_port = os.getenv("MASTER_PORT", str(random.randint(20001, 29999))) + logger.info_rank0(f"Initializing distributed tasks at: {master_addr}:{master_port}") + process = subprocess.run( + ( + "torchrun --nnodes {nnodes} --node_rank {node_rank} --nproc_per_node {nproc_per_node} " + "--master_addr {master_addr} --master_port {master_port} {file_name} {args}" + ) + .format( + nnodes=os.getenv("NNODES", "1"), + node_rank=os.getenv("NODE_RANK", "0"), + nproc_per_node=os.getenv("NPROC_PER_NODE", str(get_device_count())), + master_addr=master_addr, + master_port=master_port, + file_name=launcher.__file__, + args=" ".join(sys.argv[1:]), + ) + .split() + ) + sys.exit(process.returncode) + else: + run_exp() + elif command == Command.WEBDEMO: + run_web_demo() + elif command == Command.WEBUI: + run_web_ui() + elif command == Command.VER: + print(WELCOME) + elif command == Command.HELP: + print(USAGE) + else: + raise NotImplementedError(f"Unknown command: {command}.") + + +if __name__ == "__main__": + main() diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__init__.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/__init__.cpython-310.pyc b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b41746511bf9a6136d68bd7b8db5c880af093223 Binary files /dev/null and b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/__init__.cpython-310.pyc differ diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/evaluator.cpython-310.pyc b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/evaluator.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c5ac9ad3b3b20082b1bf2e501b488336f6257768 Binary files /dev/null and b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/evaluator.cpython-310.pyc differ diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/template.cpython-310.pyc b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/template.cpython-310.pyc new file mode 100644 index 0000000000000000000000000000000000000000..db6c19262457577e484aa638f284a3ac0820636c Binary files /dev/null and b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/__pycache__/template.cpython-310.pyc differ diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/evaluator.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/evaluator.py new file mode 100644 index 0000000000000000000000000000000000000000..99758dd2cf8d7a598cb0dda79b1c17f37c4cf9a9 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/evaluator.py @@ -0,0 +1,158 @@ +# Copyright 2025 the LlamaFactory team. +# +# This code is inspired by the Dan's test library. +# https://github.com/hendrycks/test/blob/master/evaluate_flan.py +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# MIT License +# +# Copyright (c) 2020 Dan Hendrycks +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +import json +import os +from typing import TYPE_CHECKING, Any, Dict, List, Optional + +import numpy as np +import torch +from datasets import load_dataset +from tqdm import tqdm, trange +from transformers.utils import cached_file + +from ..data import get_template_and_fix_tokenizer +from ..extras.constants import CHOICES, SUBJECTS +from ..hparams import get_eval_args +from ..model import load_model, load_tokenizer +from .template import get_eval_template + + +if TYPE_CHECKING: + from numpy.typing import NDArray + + +class Evaluator: + def __init__(self, args: Optional[Dict[str, Any]] = None) -> None: + self.model_args, self.data_args, self.eval_args, finetuning_args = get_eval_args(args) + self.tokenizer = load_tokenizer(self.model_args)["tokenizer"] + self.tokenizer.padding_side = "right" # avoid overflow issue in batched inference for llama2 + self.template = get_template_and_fix_tokenizer(self.tokenizer, self.data_args) + self.model = load_model(self.tokenizer, self.model_args, finetuning_args) + self.eval_template = get_eval_template(self.eval_args.lang) + self.choice_inputs = [self.tokenizer.encode(ch, add_special_tokens=False)[-1] for ch in CHOICES] + + @torch.inference_mode() + def batch_inference(self, batch_input: Dict[str, "torch.Tensor"]) -> List[str]: + logits = self.model(**batch_input).logits + lengths = torch.sum(batch_input["attention_mask"], dim=-1) + word_probs = torch.stack([logits[i, lengths[i] - 1] for i in range(len(lengths))], dim=0) + choice_probs = torch.nn.functional.softmax(word_probs[:, self.choice_inputs], dim=-1).detach() + return [chr(ord("A") + offset.item()) for offset in torch.argmax(choice_probs, dim=-1)] + + def eval(self) -> None: + eval_task = self.eval_args.task.split("_")[0] + eval_split = self.eval_args.task.split("_")[1] + + mapping = cached_file( + path_or_repo_id=os.path.join(self.eval_args.task_dir, eval_task), + filename="mapping.json", + cache_dir=self.model_args.cache_dir, + token=self.model_args.hf_hub_token, + ) + + with open(mapping, encoding="utf-8") as f: + categorys: Dict[str, Dict[str, str]] = json.load(f) + + category_corrects = {subj: np.array([], dtype="bool") for subj in SUBJECTS} + pbar = tqdm(categorys.keys(), desc="Processing subjects", position=0) + results = {} + for subject in pbar: + dataset = load_dataset( + path=os.path.join(self.eval_args.task_dir, eval_task), + name=subject, + cache_dir=self.model_args.cache_dir, + download_mode=self.eval_args.download_mode, + token=self.model_args.hf_hub_token, + trust_remote_code=self.model_args.trust_remote_code, + ) + pbar.set_postfix_str(categorys[subject]["name"]) + inputs, outputs, labels = [], [], [] + for i in trange(len(dataset[eval_split]), desc="Formatting batches", position=1, leave=False): + support_set = ( + dataset["train"].shuffle().select(range(min(self.eval_args.n_shot, len(dataset["train"])))) + ) + messages = self.eval_template.format_example( + target_data=dataset[eval_split][i], + support_set=support_set, + subject_name=categorys[subject]["name"], + ) + + input_ids, _ = self.template.encode_oneturn(tokenizer=self.tokenizer, messages=messages) + inputs.append({"input_ids": input_ids, "attention_mask": [1] * len(input_ids)}) + labels.append(messages[-1]["content"]) + + for i in trange( + 0, len(inputs), self.eval_args.batch_size, desc="Predicting batches", position=1, leave=False + ): + batch_input = self.tokenizer.pad( + inputs[i : i + self.eval_args.batch_size], return_attention_mask=True, return_tensors="pt" + ).to(self.model.device) + preds = self.batch_inference(batch_input) + outputs += preds + + corrects = np.array(outputs) == np.array(labels) + category_name = categorys[subject]["category"] + category_corrects[category_name] = np.concatenate([category_corrects[category_name], corrects], axis=0) + category_corrects["Average"] = np.concatenate([category_corrects["Average"], corrects], axis=0) + results[subject] = {str(i): outputs[i] for i in range(len(outputs))} + + pbar.close() + self._save_results(category_corrects, results) + + def _save_results(self, category_corrects: Dict[str, "NDArray"], results: Dict[str, Dict[int, str]]) -> None: + score_info = "\n".join( + [ + f"{category_name:>15}: {100 * np.mean(category_correct):.2f}" + for category_name, category_correct in category_corrects.items() + if len(category_correct) + ] + ) + print(score_info) + if self.eval_args.save_dir is not None: + os.makedirs(self.eval_args.save_dir, exist_ok=False) + with open(os.path.join(self.eval_args.save_dir, "results.json"), "w", encoding="utf-8", newline="\n") as f: + json.dump(results, f, indent=2) + + with open(os.path.join(self.eval_args.save_dir, "results.log"), "w", encoding="utf-8", newline="\n") as f: + f.write(score_info) + + +def run_eval() -> None: + Evaluator().eval() diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/template.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/template.py new file mode 100644 index 0000000000000000000000000000000000000000..e145409705f14b00cbbcbd60e12a2bb7de2626d2 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/eval/template.py @@ -0,0 +1,81 @@ +# Copyright 2025 the LlamaFactory team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from dataclasses import dataclass +from typing import Dict, List, Sequence, Tuple + +from ..data import Role +from ..extras.constants import CHOICES + + +@dataclass +class EvalTemplate: + system: str + choice: str + answer: str + + def _parse_example(self, example: Dict[str, str]) -> Tuple[str, str]: + r""" + input: a dict with keys {"question", "A", "B", "C", "D", "answer"} + output: a tuple of (prompt, response) + """ + candidates = [self.choice.format(choice=ch, content=example[ch]) for ch in CHOICES if ch in example] + return "".join([example["question"]] + candidates + [self.answer]), example["answer"] + + def format_example( + self, target_data: Dict[str, str], support_set: Sequence[Dict[str, str]], subject_name: str + ) -> List[Dict[str, str]]: + r""" + Converts dataset examples to messages. + """ + messages = [] + for k in range(len(support_set)): + prompt, response = self._parse_example(support_set[k]) + messages.append({"role": Role.USER.value, "content": prompt}) + messages.append({"role": Role.ASSISTANT.value, "content": response}) + + prompt, response = self._parse_example(target_data) + messages.append({"role": Role.USER.value, "content": prompt}) + messages.append({"role": Role.ASSISTANT.value, "content": response}) + messages[0]["content"] = self.system.format(subject=subject_name) + messages[0]["content"] + return messages + + +eval_templates: Dict[str, "EvalTemplate"] = {} + + +def _register_eval_template(name: str, system: str, choice: str, answer: str) -> None: + eval_templates[name] = EvalTemplate(system=system, choice=choice, answer=answer) + + +def get_eval_template(name: str) -> "EvalTemplate": + eval_template = eval_templates.get(name, None) + assert eval_template is not None, f"Template {name} does not exist." + return eval_template + + +_register_eval_template( + name="en", + system="The following are multiple choice questions (with answers) about {subject}.\n\n", + choice="\n{choice}. {content}", + answer="\nAnswer:", +) + + +_register_eval_template( + name="zh", + system="以下是中国关于{subject}考试的单项选择题,请选出其中的正确答案。\n\n", + choice="\n{choice}. {content}", + answer="\n答案:", +) diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/__init__.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/logging.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/logging.py new file mode 100644 index 0000000000000000000000000000000000000000..8f98b05534a0ba81e6dbc910e4c2c02029e24f13 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/logging.py @@ -0,0 +1,173 @@ +# Copyright 2024 Optuna, HuggingFace Inc. and the LlamaFactory team. +# +# This code is inspired by the HuggingFace's transformers library. +# https://github.com/huggingface/transformers/blob/v4.40.0/src/transformers/utils/logging.py +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import logging +import os +import sys +import threading +from concurrent.futures import ThreadPoolExecutor +from functools import lru_cache +from typing import Optional + +from .constants import RUNNING_LOG + + +_thread_lock = threading.RLock() +_default_handler: Optional["logging.Handler"] = None +_default_log_level: "logging._Level" = logging.INFO + + +class LoggerHandler(logging.Handler): + r""" + Redirects the logging output to the logging file for LLaMA Board. + """ + + def __init__(self, output_dir: str) -> None: + super().__init__() + self._formatter = logging.Formatter( + fmt="[%(levelname)s|%(asctime)s] %(filename)s:%(lineno)s >> %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", + ) + self.setLevel(logging.INFO) + os.makedirs(output_dir, exist_ok=True) + self.running_log = os.path.join(output_dir, RUNNING_LOG) + if os.path.exists(self.running_log): + os.remove(self.running_log) + + self.thread_pool = ThreadPoolExecutor(max_workers=1) + + def _write_log(self, log_entry: str) -> None: + with open(self.running_log, "a", encoding="utf-8") as f: + f.write(log_entry + "\n\n") + + def emit(self, record) -> None: + if record.name == "httpx": + return + + log_entry = self._formatter.format(record) + self.thread_pool.submit(self._write_log, log_entry) + + def close(self) -> None: + self.thread_pool.shutdown(wait=True) + return super().close() + + +class _Logger(logging.Logger): + r""" + A logger that supports rank0 logging. + """ + + def info_rank0(self, *args, **kwargs) -> None: + self.info(*args, **kwargs) + + def warning_rank0(self, *args, **kwargs) -> None: + self.warning(*args, **kwargs) + + def warning_rank0_once(self, *args, **kwargs) -> None: + self.warning(*args, **kwargs) + + +def _get_default_logging_level() -> "logging._Level": + r""" + Returns the default logging level. + """ + env_level_str = os.environ.get("LLAMAFACTORY_VERBOSITY", None) + if env_level_str: + if env_level_str.upper() in logging._nameToLevel: + return logging._nameToLevel[env_level_str.upper()] + else: + raise ValueError(f"Unknown logging level: {env_level_str}.") + + return _default_log_level + + +def _get_library_name() -> str: + return __name__.split(".")[0] + + +def _get_library_root_logger() -> "_Logger": + return logging.getLogger(_get_library_name()) + + +def _configure_library_root_logger() -> None: + r""" + Configures root logger using a stdout stream handler with an explicit format. + """ + global _default_handler + + with _thread_lock: + if _default_handler: # already configured + return + + formatter = logging.Formatter( + fmt="[%(levelname)s|%(asctime)s] %(name)s:%(lineno)s >> %(message)s", + datefmt="%Y-%m-%d %H:%M:%S", + ) + _default_handler = logging.StreamHandler(sys.stdout) + _default_handler.setFormatter(formatter) + library_root_logger = _get_library_root_logger() + library_root_logger.addHandler(_default_handler) + library_root_logger.setLevel(_get_default_logging_level()) + library_root_logger.propagate = False + + +def get_logger(name: Optional[str] = None) -> "_Logger": + r""" + Returns a logger with the specified name. It it not supposed to be accessed externally. + """ + if name is None: + name = _get_library_name() + + _configure_library_root_logger() + return logging.getLogger(name) + + +def add_handler(handler: "logging.Handler") -> None: + r""" + Adds a handler to the root logger. + """ + _configure_library_root_logger() + _get_library_root_logger().addHandler(handler) + + +def remove_handler(handler: logging.Handler) -> None: + r""" + Removes a handler to the root logger. + """ + _configure_library_root_logger() + _get_library_root_logger().removeHandler(handler) + + +def info_rank0(self: "logging.Logger", *args, **kwargs) -> None: + if int(os.getenv("LOCAL_RANK", "0")) == 0: + self.info(*args, **kwargs) + + +def warning_rank0(self: "logging.Logger", *args, **kwargs) -> None: + if int(os.getenv("LOCAL_RANK", "0")) == 0: + self.warning(*args, **kwargs) + + +@lru_cache(None) +def warning_rank0_once(self: "logging.Logger", *args, **kwargs) -> None: + if int(os.getenv("LOCAL_RANK", "0")) == 0: + self.warning(*args, **kwargs) + + +logging.Logger.info_rank0 = info_rank0 +logging.Logger.warning_rank0 = warning_rank0 +logging.Logger.warning_rank0_once = warning_rank0_once diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/misc.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/misc.py new file mode 100644 index 0000000000000000000000000000000000000000..f637d728ab35bc1b87d09e11b6c5b83e5f5c7078 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/misc.py @@ -0,0 +1,308 @@ +# Copyright 2024 HuggingFace Inc. and the LlamaFactory team. +# +# This code is inspired by the HuggingFace's PEFT library. +# https://github.com/huggingface/peft/blob/v0.10.0/src/peft/peft_model.py +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import gc +import os +from typing import TYPE_CHECKING, Any, Dict, Literal, Sequence, Tuple, Union + +import torch +import torch.distributed as dist +import transformers.dynamic_module_utils +from transformers import InfNanRemoveLogitsProcessor, LogitsProcessorList +from transformers.dynamic_module_utils import get_relative_imports +from transformers.utils import ( + is_torch_bf16_gpu_available, + is_torch_cuda_available, + is_torch_mps_available, + is_torch_npu_available, + is_torch_xpu_available, +) +from transformers.utils.versions import require_version + +from . import logging +from .packages import is_transformers_version_greater_than + + +_is_fp16_available = is_torch_npu_available() or is_torch_cuda_available() +try: + _is_bf16_available = is_torch_bf16_gpu_available() or (is_torch_npu_available() and torch.npu.is_bf16_supported()) +except Exception: + _is_bf16_available = False + + +if TYPE_CHECKING: + from numpy.typing import NDArray + + from ..hparams import ModelArguments + + +logger = logging.get_logger(__name__) + + +class AverageMeter: + r""" + Computes and stores the average and current value. + """ + + def __init__(self): + self.reset() + + def reset(self): + self.val = 0 + self.avg = 0 + self.sum = 0 + self.count = 0 + + def update(self, val, n=1): + self.val = val + self.sum += val * n + self.count += n + self.avg = self.sum / self.count + + +def check_version(requirement: str, mandatory: bool = False) -> None: + r""" + Optionally checks the package version. + """ + if is_env_enabled("DISABLE_VERSION_CHECK") and not mandatory: + logger.warning_rank0_once("Version checking has been disabled, may lead to unexpected behaviors.") + return + + if mandatory: + hint = f"To fix: run `pip install {requirement}`." + else: + hint = f"To fix: run `pip install {requirement}` or set `DISABLE_VERSION_CHECK=1` to skip this check." + + require_version(requirement, hint) + + +def check_dependencies() -> None: + r""" + Checks the version of the required packages. + """ + check_version("transformers>=4.41.2,<=4.49.0,!=4.46.0,!=4.46.1,!=4.46.2,!=4.46.3,!=4.47.0,!=4.47.1,!=4.48.0") + check_version("datasets>=2.16.0,<=3.2.0") + check_version("accelerate>=0.34.0,<=1.2.1") + check_version("peft>=0.11.1,<=0.12.0") + check_version("trl>=0.8.6,<=0.9.6") + if is_transformers_version_greater_than("4.46.0") and not is_transformers_version_greater_than("4.48.1"): + logger.warning_rank0_once("There are known bugs in transformers v4.46.0-v4.48.0, please use other versions.") + + +def calculate_tps(dataset: Sequence[Dict[str, Any]], metrics: Dict[str, float], stage: Literal["sft", "rm"]) -> float: + r""" + Calculates effective tokens per second. + """ + effective_token_num = 0 + for data in dataset: + if stage == "sft": + effective_token_num += len(data["input_ids"]) + elif stage == "rm": + effective_token_num += len(data["chosen_input_ids"]) + len(data["rejected_input_ids"]) + + result = effective_token_num * metrics["epoch"] / metrics["train_runtime"] + return result / dist.get_world_size() if dist.is_initialized() else result + + +def count_parameters(model: "torch.nn.Module") -> Tuple[int, int]: + r""" + Returns the number of trainable parameters and number of all parameters in the model. + """ + trainable_params, all_param = 0, 0 + for param in model.parameters(): + num_params = param.numel() + # if using DS Zero 3 and the weights are initialized empty + if num_params == 0 and hasattr(param, "ds_numel"): + num_params = param.ds_numel + + # Due to the design of 4bit linear layers from bitsandbytes, multiply the number of parameters by itemsize + if param.__class__.__name__ == "Params4bit": + if hasattr(param, "quant_storage") and hasattr(param.quant_storage, "itemsize"): + num_bytes = param.quant_storage.itemsize + elif hasattr(param, "element_size"): # for older pytorch version + num_bytes = param.element_size() + else: + num_bytes = 1 + + num_params = num_params * 2 * num_bytes + + all_param += num_params + if param.requires_grad: + trainable_params += num_params + + return trainable_params, all_param + + +def get_current_device() -> "torch.device": + r""" + Gets the current available device. + """ + if is_torch_xpu_available(): + device = "xpu:{}".format(os.environ.get("LOCAL_RANK", "0")) + elif is_torch_npu_available(): + device = "npu:{}".format(os.environ.get("LOCAL_RANK", "0")) + elif is_torch_mps_available(): + device = "mps:{}".format(os.environ.get("LOCAL_RANK", "0")) + elif is_torch_cuda_available(): + device = "cuda:{}".format(os.environ.get("LOCAL_RANK", "0")) + else: + device = "cpu" + + return torch.device(device) + + +def get_device_count() -> int: + r""" + Gets the number of available GPU or NPU devices. + """ + if is_torch_xpu_available(): + return torch.xpu.device_count() + elif is_torch_npu_available(): + return torch.npu.device_count() + elif is_torch_cuda_available(): + return torch.cuda.device_count() + else: + return 0 + + +def get_logits_processor() -> "LogitsProcessorList": + r""" + Gets logits processor that removes NaN and Inf logits. + """ + logits_processor = LogitsProcessorList() + logits_processor.append(InfNanRemoveLogitsProcessor()) + return logits_processor + + +def get_peak_memory() -> Tuple[int, int]: + r""" + Gets the peak memory usage for the current device (in Bytes). + """ + if is_torch_npu_available(): + return torch.npu.max_memory_allocated(), torch.npu.max_memory_reserved() + elif is_torch_cuda_available(): + return torch.cuda.max_memory_allocated(), torch.cuda.max_memory_reserved() + else: + return 0, 0 + + +def has_tokenized_data(path: "os.PathLike") -> bool: + r""" + Checks if the path has a tokenized dataset. + """ + return os.path.isdir(path) and len(os.listdir(path)) > 0 + + +def infer_optim_dtype(model_dtype: "torch.dtype") -> "torch.dtype": + r""" + Infers the optimal dtype according to the model_dtype and device compatibility. + """ + if _is_bf16_available and model_dtype == torch.bfloat16: + return torch.bfloat16 + elif _is_fp16_available: + return torch.float16 + else: + return torch.float32 + + +def is_gpu_or_npu_available() -> bool: + r""" + Checks if the GPU or NPU is available. + """ + return is_torch_npu_available() or is_torch_cuda_available() + + +def is_env_enabled(env_var: str, default: str = "0") -> bool: + r""" + Checks if the environment variable is enabled. + """ + return os.getenv(env_var, default).lower() in ["true", "y", "1"] + + +def numpify(inputs: Union["NDArray", "torch.Tensor"]) -> "NDArray": + r""" + Casts a torch tensor or a numpy array to a numpy array. + """ + if isinstance(inputs, torch.Tensor): + inputs = inputs.cpu() + if inputs.dtype == torch.bfloat16: # numpy does not support bfloat16 until 1.21.4 + inputs = inputs.to(torch.float32) + + inputs = inputs.numpy() + + return inputs + + +def skip_check_imports() -> None: + r""" + Avoids flash attention import error in custom model files. + """ + if not is_env_enabled("FORCE_CHECK_IMPORTS"): + transformers.dynamic_module_utils.check_imports = get_relative_imports + + +def torch_gc() -> None: + r""" + Collects GPU or NPU memory. + """ + gc.collect() + if is_torch_xpu_available(): + torch.xpu.empty_cache() + elif is_torch_npu_available(): + torch.npu.empty_cache() + elif is_torch_mps_available(): + torch.mps.empty_cache() + elif is_torch_cuda_available(): + torch.cuda.empty_cache() + + +def try_download_model_from_other_hub(model_args: "ModelArguments") -> str: + if (not use_modelscope() and not use_openmind()) or os.path.exists(model_args.model_name_or_path): + return model_args.model_name_or_path + + if use_modelscope(): + check_version("modelscope>=1.11.0", mandatory=True) + from modelscope import snapshot_download # type: ignore + + revision = "master" if model_args.model_revision == "main" else model_args.model_revision + return snapshot_download( + model_args.model_name_or_path, + revision=revision, + cache_dir=model_args.cache_dir, + ) + + if use_openmind(): + check_version("openmind>=0.8.0", mandatory=True) + from openmind.utils.hub import snapshot_download # type: ignore + + return snapshot_download( + model_args.model_name_or_path, + revision=model_args.model_revision, + cache_dir=model_args.cache_dir, + ) + + +def use_modelscope() -> bool: + return is_env_enabled("USE_MODELSCOPE_HUB") + + +def use_openmind() -> bool: + return is_env_enabled("USE_OPENMIND_HUB") + + +def use_ray() -> bool: + return is_env_enabled("USE_RAY") diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/ploting.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/ploting.py new file mode 100644 index 0000000000000000000000000000000000000000..d05970d24491c32fc0317979b268478c162530eb --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/extras/ploting.py @@ -0,0 +1,101 @@ +# Copyright 2025 the LlamaFactory team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import math +import os +from typing import Any, Dict, List + +from transformers.trainer import TRAINER_STATE_NAME + +from . import logging +from .packages import is_matplotlib_available + + +if is_matplotlib_available(): + import matplotlib.figure + import matplotlib.pyplot as plt + + +logger = logging.get_logger(__name__) + + +def smooth(scalars: List[float]) -> List[float]: + r""" + EMA implementation according to TensorBoard. + """ + if len(scalars) == 0: + return [] + + last = scalars[0] + smoothed = [] + weight = 1.8 * (1 / (1 + math.exp(-0.05 * len(scalars))) - 0.5) # a sigmoid function + for next_val in scalars: + smoothed_val = last * weight + (1 - weight) * next_val + smoothed.append(smoothed_val) + last = smoothed_val + return smoothed + + +def gen_loss_plot(trainer_log: List[Dict[str, Any]]) -> "matplotlib.figure.Figure": + r""" + Plots loss curves in LlamaBoard. + """ + plt.close("all") + plt.switch_backend("agg") + fig = plt.figure() + ax = fig.add_subplot(111) + steps, losses = [], [] + for log in trainer_log: + if log.get("loss", None): + steps.append(log["current_steps"]) + losses.append(log["loss"]) + + ax.plot(steps, losses, color="#1f77b4", alpha=0.4, label="original") + ax.plot(steps, smooth(losses), color="#1f77b4", label="smoothed") + ax.legend() + ax.set_xlabel("step") + ax.set_ylabel("loss") + return fig + + +def plot_loss(save_dictionary: str, keys: List[str] = ["loss"]) -> None: + r""" + Plots loss curves and saves the image. + """ + plt.switch_backend("agg") + with open(os.path.join(save_dictionary, TRAINER_STATE_NAME), encoding="utf-8") as f: + data = json.load(f) + + for key in keys: + steps, metrics = [], [] + for i in range(len(data["log_history"])): + if key in data["log_history"][i]: + steps.append(data["log_history"][i]["step"]) + metrics.append(data["log_history"][i][key]) + + if len(metrics) == 0: + logger.warning_rank0(f"No metric {key} to plot.") + continue + + plt.figure() + plt.plot(steps, metrics, color="#1f77b4", alpha=0.4, label="original") + plt.plot(steps, smooth(metrics), color="#1f77b4", label="smoothed") + plt.title(f"training {key} of {save_dictionary}") + plt.xlabel("step") + plt.ylabel(key) + plt.legend() + figure_path = os.path.join(save_dictionary, "training_{}.png".format(key.replace("/", "_"))) + plt.savefig(figure_path, format="png", dpi=100) + print("Figure saved at:", figure_path) diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/launcher.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/launcher.py new file mode 100644 index 0000000000000000000000000000000000000000..169b042ab023308bd3d25bd03e6658e3e0f4b9da --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/llamafactory/launcher.py @@ -0,0 +1,23 @@ +# Copyright 2025 the LlamaFactory team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from llamafactory.train.tuner import run_exp # use absolute import + + +def launch(): + run_exp() + + +if __name__ == "__main__": + launch() diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/train.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/train.py new file mode 100644 index 0000000000000000000000000000000000000000..eba846a024a72853948ee2757e69b44551c63b12 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/train.py @@ -0,0 +1,28 @@ +# Copyright 2025 the LlamaFactory team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from llamafactory.train.tuner import run_exp + + +def main(): + run_exp() + + +def _mp_fn(index): + # For xla_spawn (TPUs) + run_exp() + + +if __name__ == "__main__": + main() diff --git a/InternVL/Qwen2.5-VL/LLaMA-Factory/src/webui.py b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/webui.py new file mode 100644 index 0000000000000000000000000000000000000000..088f2365ad87dd934d68fa175056cb9b89a5c3a9 --- /dev/null +++ b/InternVL/Qwen2.5-VL/LLaMA-Factory/src/webui.py @@ -0,0 +1,29 @@ +# Copyright 2025 the LlamaFactory team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os + +from llamafactory.extras.misc import is_env_enabled +from llamafactory.webui.interface import create_ui + + +def main(): + gradio_ipv6 = is_env_enabled("GRADIO_IPV6") + gradio_share = is_env_enabled("GRADIO_SHARE") + server_name = os.getenv("GRADIO_SERVER_NAME", "[::]" if gradio_ipv6 else "0.0.0.0") + create_ui().queue().launch(share=gradio_share, server_name=server_name, inbrowser=True) + + +if __name__ == "__main__": + main()