From a1b1931b4a428f008328f86a71e8d6011c77cfe9 Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Fri, 26 Dec 2025 22:47:23 +0800 Subject: [PATCH] [breaking] migrate from setuptools to uv (#9673) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: hiyouga <16256802+hiyouga@users.noreply.github.com> --- .github/workflows/docker.yml | 8 +- .github/workflows/tests.yml | 15 +-- .github/workflows/tests_npu.yml | 12 ++- MANIFEST.in | 2 +- Makefile | 20 ++-- README.md | 11 +-- docker/docker-cuda/Dockerfile | 11 +-- docker/docker-cuda/Dockerfile.megatron | 12 +-- docker/docker-npu/Dockerfile | 11 +-- docker/docker-rocm/Dockerfile | 11 +-- examples/requirements/adam-mini.txt | 1 + examples/requirements/apollo.txt | 1 + examples/requirements/aqlm.txt | 1 + examples/requirements/badam.txt | 1 + examples/requirements/bitsandbytes.txt | 1 + examples/requirements/dev.txt | 4 + examples/requirements/eetq.txt | 1 + examples/requirements/fp8-te.txt | 2 + examples/requirements/fp8.txt | 2 + examples/requirements/galore.txt | 1 + examples/requirements/gptq.txt | 2 + examples/requirements/hqq.txt | 1 + examples/requirements/liger-kernel.txt | 1 + examples/requirements/minicpm-v.txt | 8 ++ examples/requirements/openmind.txt | 1 + examples/requirements/sglang.txt | 2 + examples/requirements/swanlab.txt | 1 + examples/requirements/vllm.txt | 1 + pyproject.toml | 128 ++++++++++++++++++------- requirements.txt | 39 -------- setup.py | 116 ---------------------- 31 files changed, 178 insertions(+), 250 deletions(-) create mode 100644 examples/requirements/adam-mini.txt create mode 100644 examples/requirements/apollo.txt create mode 100644 examples/requirements/aqlm.txt create mode 100644 examples/requirements/badam.txt create mode 100644 examples/requirements/bitsandbytes.txt create mode 100644 examples/requirements/dev.txt create mode 100644 examples/requirements/eetq.txt create mode 100644 examples/requirements/fp8-te.txt create mode 100644 examples/requirements/fp8.txt create mode 100644 examples/requirements/galore.txt create mode 100644 examples/requirements/gptq.txt create mode 100644 examples/requirements/hqq.txt create mode 100644 examples/requirements/liger-kernel.txt create mode 100644 examples/requirements/minicpm-v.txt create mode 100644 examples/requirements/openmind.txt create mode 100644 examples/requirements/sglang.txt create mode 100644 examples/requirements/swanlab.txt create mode 100644 examples/requirements/vllm.txt delete mode 100644 requirements.txt delete mode 100644 setup.py diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 7a21addba..7564c8ba6 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -7,7 +7,7 @@ on: - "main" paths: - "**/*.py" - - "requirements.txt" + - "pyproject.toml" - "docker/**" - ".github/workflows/*.yml" pull_request: @@ -15,7 +15,7 @@ on: - "main" paths: - "**/*.py" - - "requirements.txt" + - "pyproject.toml" - "docker/**" - ".github/workflows/*.yml" release: @@ -64,7 +64,7 @@ jobs: id: version run: | if [ "${{ github.event_name }}" = "release" ]; then - echo "tag=$(python setup.py --version)" >> "$GITHUB_OUTPUT" + echo "tag=$(grep -oP 'VERSION = "\K[^"]+' src/llamafactory/extras/env.py)" >> "$GITHUB_OUTPUT" else echo "tag=latest" >> "$GITHUB_OUTPUT" fi @@ -93,8 +93,6 @@ jobs: with: context: . file: ./docker/docker-cuda/Dockerfile - build-args: | - EXTRAS=metrics,deepspeed,liger-kernel push: ${{ github.event_name != 'pull_request' }} tags: | docker.io/hiyouga/llamafactory:${{ steps.version.outputs.tag }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2c53d52c6..089778ccb 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -7,7 +7,7 @@ on: - "main" paths: - "**/*.py" - - "requirements.txt" + - "pyproject.toml" - "Makefile" - ".github/workflows/*.yml" pull_request: @@ -15,7 +15,7 @@ on: - "main" paths: - "**/*.py" - - "requirements.txt" + - "pyproject.toml" - "Makefile" - ".github/workflows/*.yml" @@ -68,16 +68,19 @@ jobs: with: python-version: ${{ matrix.python }} + - name: Install uv + uses: astral-sh/setup-uv@v5 + - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu - python -m pip install ".[dev]" + uv pip install --system torch torchvision --index-url https://download.pytorch.org/whl/cpu + uv pip install --system -e "." + uv pip install --system -r examples/requirements/dev.txt - name: Install transformers if: ${{ matrix.transformers }} run: | - python -m pip install "transformers==${{ matrix.transformers }}" + uv pip install --system "transformers==${{ matrix.transformers }}" - name: Cache files id: hf-hub-cache diff --git a/.github/workflows/tests_npu.yml b/.github/workflows/tests_npu.yml index 38ea5a24e..71f2299ea 100644 --- a/.github/workflows/tests_npu.yml +++ b/.github/workflows/tests_npu.yml @@ -7,7 +7,7 @@ on: - "main" paths: - "**/*.py" - - "requirements.txt" + - "pyproject.toml" - "Makefile" - ".github/workflows/*.yml" pull_request: @@ -15,7 +15,7 @@ on: - "main" paths: - "**/*.py" - - "requirements.txt" + - "pyproject.toml" - "Makefile" - ".github/workflows/*.yml" @@ -48,10 +48,14 @@ jobs: - name: Checkout uses: actions/checkout@v4 + - name: Install uv + run: | + curl -LsSf https://astral.sh/uv/install.sh | sh + - name: Install dependencies run: | - python -m pip install --upgrade pip - python -m pip install ".[torch-npu,dev]" torch-npu==${{matrix.pytorch_npu}} + uv pip install --system -e "." torch-npu==${{matrix.pytorch_npu}} + uv pip install --system -r examples/requirements/dev.txt - name: Install node run: | diff --git a/MANIFEST.in b/MANIFEST.in index 82c51f634..1aba38f67 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include LICENSE requirements.txt +include LICENSE diff --git a/Makefile b/Makefile index 3dd8d0041..4c3a3216d 100644 --- a/Makefile +++ b/Makefile @@ -1,24 +1,24 @@ .PHONY: build commit license quality style test -check_dirs := scripts src tests tests_v1 setup.py +check_dirs := scripts src tests tests_v1 build: - pip3 install build && python3 -m build + uv build commit: - pre-commit install - pre-commit run --all-files + uv run pre-commit install + uv run pre-commit run --all-files license: - python3 tests/check_license.py $(check_dirs) + uv run python tests/check_license.py $(check_dirs) quality: - ruff check $(check_dirs) - ruff format --check $(check_dirs) + uv run ruff check $(check_dirs) + uv run ruff format --check $(check_dirs) style: - ruff check $(check_dirs) --fix - ruff format $(check_dirs) + uv run ruff check $(check_dirs) --fix + uv run ruff format $(check_dirs) test: - WANDB_DISABLED=true pytest -vv --import-mode=importlib tests/ tests_v1/ + WANDB_DISABLED=true uv run pytest -vv --import-mode=importlib tests/ tests_v1/ diff --git a/README.md b/README.md index b6fdfefef..919cb2061 100644 --- a/README.md +++ b/README.md @@ -514,10 +514,12 @@ huggingface-cli login ```bash git clone --depth 1 https://github.com/hiyouga/LLaMA-Factory.git cd LLaMA-Factory -pip install -e ".[torch,metrics]" --no-build-isolation +pip install -e "." --no-build-isolation ``` -Extra dependencies available: torch, torch-npu, metrics, deepspeed, liger-kernel, bitsandbytes, hqq, eetq, gptq, aqlm, vllm, sglang, galore, apollo, badam, adam-mini, qwen, minicpm_v, openmind, swanlab, dev +Optional dependencies available: `metrics`, `deepspeed`. Install with: `pip install -e ".[metrics,deepspeed]"` + +Additional dependencies for specific features are available in `examples/requirements/`. #### Install from Docker Image @@ -579,7 +581,7 @@ To enable FlashAttention-2 on the Windows platform, please use the script from [
For Ascend NPU users -To install LLaMA Factory on Ascend NPU devices, please upgrade Python to version 3.10 or higher and specify extra dependencies: `pip install -e ".[torch-npu,metrics]"`. Additionally, you need to install the **[Ascend CANN Toolkit and Kernels](https://www.hiascend.com/developer/download/community/result?module=cann)**. Please follow the [installation tutorial](https://www.hiascend.com/document/detail/en/CANNCommunityEdition/600alphaX/softwareinstall/instg/atlasdeploy_03_0031.html) or use the following commands: +To install LLaMA Factory on Ascend NPU devices, please upgrade Python to version 3.10 or higher: `pip install -e "."`. Additionally, you need to install the **[Ascend CANN Toolkit and Kernels](https://www.hiascend.com/developer/download/community/result?module=cann)**. Please follow the [installation tutorial](https://www.hiascend.com/document/detail/en/CANNCommunityEdition/600alphaX/softwareinstall/instg/atlasdeploy_03_0031.html) or use the following commands: ```bash # replace the url according to your CANN version and devices @@ -714,7 +716,6 @@ For CUDA users: ```bash docker build -f ./docker/docker-cuda/Dockerfile \ --build-arg PIP_INDEX=https://pypi.org/simple \ - --build-arg EXTRAS=metrics \ -t llamafactory:latest . docker run -dit --ipc=host --gpus=all \ @@ -731,7 +732,6 @@ For Ascend NPU users: ```bash docker build -f ./docker/docker-npu/Dockerfile \ --build-arg PIP_INDEX=https://pypi.org/simple \ - --build-arg EXTRAS=torch-npu,metrics \ -t llamafactory:latest . docker run -dit --ipc=host \ @@ -756,7 +756,6 @@ For AMD ROCm users: ```bash docker build -f ./docker/docker-rocm/Dockerfile \ --build-arg PIP_INDEX=https://pypi.org/simple \ - --build-arg EXTRAS=metrics \ -t llamafactory:latest . docker run -dit --ipc=host \ diff --git a/docker/docker-cuda/Dockerfile b/docker/docker-cuda/Dockerfile index afca20871..94184e791 100644 --- a/docker/docker-cuda/Dockerfile +++ b/docker/docker-cuda/Dockerfile @@ -4,7 +4,6 @@ FROM ${BASE_IMAGE} # Installation arguments ARG PIP_INDEX=https://pypi.org/simple -ARG EXTRAS=metrics ARG INSTALL_FLASHATTN=false ARG HTTP_PROXY="" @@ -27,17 +26,13 @@ WORKDIR /app # Change pip source RUN pip config set global.index-url "${PIP_INDEX}" && \ pip config set global.extra-index-url "${PIP_INDEX}" && \ - pip install --no-cache-dir --upgrade pip packaging wheel setuptools + pip install --no-cache-dir --upgrade pip packaging wheel setuptools "hatchling>=1.18.0" editables -# Install the requirements -COPY requirements.txt /app -RUN pip install --no-cache-dir -r requirements.txt - -# Copy the rest of the application into the image +# Copy the application into the image COPY . /app # Install LLaMA Factory -RUN pip install --no-cache-dir -e ".[${EXTRAS}]" --no-build-isolation +RUN pip install --no-cache-dir -e "." --no-build-isolation # Rebuild flash attention RUN if [ "${INSTALL_FLASHATTN}" == "true" ]; then \ diff --git a/docker/docker-cuda/Dockerfile.megatron b/docker/docker-cuda/Dockerfile.megatron index 7b603e3ec..ee6913192 100644 --- a/docker/docker-cuda/Dockerfile.megatron +++ b/docker/docker-cuda/Dockerfile.megatron @@ -8,7 +8,7 @@ ENV PYPI_MIRROR=https://mirrors.aliyun.com/pypi/simple/ ENV PYPI_TRUSTED_HOST=mirrors.aliyun.com ENV APT_MIRROR=https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ -RUN pip install --upgrade pip setuptools wheel --trusted-host ${PYPI_TRUSTED_HOST} --index-url ${PYPI_MIRROR} +RUN pip install --upgrade pip setuptools wheel "hatchling>=1.18.0" editables --trusted-host ${PYPI_TRUSTED_HOST} --index-url ${PYPI_MIRROR} RUN pip uninstall -y torch torchvision torch-tensorrt \ flash_attn transformer-engine \ @@ -56,14 +56,14 @@ ENV JAVA_HOME /usr/lib/jvm/java-21-openjdk-amd64 # pip install LLaMA-Factory WORKDIR /app -COPY requirements.txt /app/ -RUN pip install --no-cache-dir -r requirements.txt +# Copy the application into the image +COPY . /app + +# Install LLaMA Factory +RUN pip install --no-cache-dir -e "." --no-build-isolation RUN pip install "git+https://github.com/alibaba/roll.git#subdirectory=mcore_adapter" -COPY . /app/ -RUN pip install -e ".[metrics]" --no-build-isolation - # Expose port 7860 for LLaMA Board ENV GRADIO_SERVER_PORT=7860 EXPOSE 7860 diff --git a/docker/docker-npu/Dockerfile b/docker/docker-npu/Dockerfile index 825662b2a..95da49715 100644 --- a/docker/docker-npu/Dockerfile +++ b/docker/docker-npu/Dockerfile @@ -5,7 +5,6 @@ FROM ${BASE_IMAGE} # Installation arguments ARG PIP_INDEX=https://pypi.org/simple -ARG EXTRAS=torch-npu,metrics ARG HTTP_PROXY="" ARG PYTORCH_INDEX=https://download.pytorch.org/whl/cpu @@ -28,21 +27,17 @@ WORKDIR /app # Change pip source RUN pip config set global.index-url "${PIP_INDEX}" && \ pip config set global.extra-index-url "${PIP_INDEX}" && \ - pip install --no-cache-dir --upgrade pip packaging wheel setuptools + pip install --no-cache-dir --upgrade pip packaging wheel setuptools "hatchling>=1.18.0" editables # Install torch-npu RUN pip uninstall -y torch torchvision torchaudio && \ pip install --no-cache-dir "torch==2.7.1" "torch-npu==2.7.1" "torchvision==0.22.1" --index-url "${PYTORCH_INDEX}" -# Install the requirements -COPY requirements.txt /app -RUN pip install --no-cache-dir -r requirements.txt - -# Copy the rest of the application into the image +# Copy the application into the image COPY . /app # Install LLaMA Factory -RUN pip install --no-cache-dir -e ".[${EXTRAS}]" --no-build-isolation +RUN pip install --no-cache-dir -e "." --no-build-isolation # Set up volumes # VOLUME [ "/root/.cache/huggingface", "/app/shared_data", "/app/output" ] diff --git a/docker/docker-rocm/Dockerfile b/docker/docker-rocm/Dockerfile index 2b9e5811f..c5af6aa27 100644 --- a/docker/docker-rocm/Dockerfile +++ b/docker/docker-rocm/Dockerfile @@ -4,7 +4,6 @@ FROM ${BASE_IMAGE} # Installation arguments ARG PIP_INDEX=https://pypi.org/simple -ARG EXTRAS=metrics ARG INSTALL_FLASHATTN=false ARG HTTP_PROXY="" ARG PYTORCH_INDEX=https://download.pytorch.org/whl/rocm6.3 @@ -28,21 +27,17 @@ WORKDIR /app # Change pip source RUN pip config set global.index-url "${PIP_INDEX}" && \ pip config set global.extra-index-url "${PIP_INDEX}" && \ - pip install --no-cache-dir --upgrade pip packaging wheel setuptools + pip install --no-cache-dir --upgrade pip packaging wheel setuptools "hatchling>=1.18.0" editables # Reinstall pytorch rocm RUN pip uninstall -y torch torchvision torchaudio && \ pip install --no-cache-dir --pre torch torchvision torchaudio --index-url "${PYTORCH_INDEX}" -# Install the requirements -COPY requirements.txt /app -RUN pip install --no-cache-dir -r requirements.txt - -# Copy the rest of the application into the image +# Copy the application into the image COPY . /app # Install LLaMA Factory -RUN pip install --no-cache-dir -e ".[${EXTRAS}]" --no-build-isolation +RUN pip install --no-cache-dir -e "." --no-build-isolation # Rebuild flash attention RUN if [ "${INSTALL_FLASHATTN}" == "true" ]; then \ diff --git a/examples/requirements/adam-mini.txt b/examples/requirements/adam-mini.txt new file mode 100644 index 000000000..143218139 --- /dev/null +++ b/examples/requirements/adam-mini.txt @@ -0,0 +1 @@ +adam-mini diff --git a/examples/requirements/apollo.txt b/examples/requirements/apollo.txt new file mode 100644 index 000000000..0ae4210c8 --- /dev/null +++ b/examples/requirements/apollo.txt @@ -0,0 +1 @@ +apollo-torch diff --git a/examples/requirements/aqlm.txt b/examples/requirements/aqlm.txt new file mode 100644 index 000000000..0ff8e7d60 --- /dev/null +++ b/examples/requirements/aqlm.txt @@ -0,0 +1 @@ +aqlm[gpu]>=1.1.0 diff --git a/examples/requirements/badam.txt b/examples/requirements/badam.txt new file mode 100644 index 000000000..3abf0cf2c --- /dev/null +++ b/examples/requirements/badam.txt @@ -0,0 +1 @@ +badam>=1.2.1 diff --git a/examples/requirements/bitsandbytes.txt b/examples/requirements/bitsandbytes.txt new file mode 100644 index 000000000..0dc8b51f5 --- /dev/null +++ b/examples/requirements/bitsandbytes.txt @@ -0,0 +1 @@ +bitsandbytes>=0.39.0 diff --git a/examples/requirements/dev.txt b/examples/requirements/dev.txt new file mode 100644 index 000000000..f0fc17fcc --- /dev/null +++ b/examples/requirements/dev.txt @@ -0,0 +1,4 @@ +pre-commit +ruff +pytest +build diff --git a/examples/requirements/eetq.txt b/examples/requirements/eetq.txt new file mode 100644 index 000000000..05b3cb950 --- /dev/null +++ b/examples/requirements/eetq.txt @@ -0,0 +1 @@ +eetq diff --git a/examples/requirements/fp8-te.txt b/examples/requirements/fp8-te.txt new file mode 100644 index 000000000..899bc8c4a --- /dev/null +++ b/examples/requirements/fp8-te.txt @@ -0,0 +1,2 @@ +transformer_engine[pytorch]>=2.0.0 +accelerate>=1.10.0 diff --git a/examples/requirements/fp8.txt b/examples/requirements/fp8.txt new file mode 100644 index 000000000..6079c17fe --- /dev/null +++ b/examples/requirements/fp8.txt @@ -0,0 +1,2 @@ +torchao>=0.8.0 +accelerate>=1.10.0 diff --git a/examples/requirements/galore.txt b/examples/requirements/galore.txt new file mode 100644 index 000000000..e101ee74e --- /dev/null +++ b/examples/requirements/galore.txt @@ -0,0 +1 @@ +galore-torch diff --git a/examples/requirements/gptq.txt b/examples/requirements/gptq.txt new file mode 100644 index 000000000..e39481d1f --- /dev/null +++ b/examples/requirements/gptq.txt @@ -0,0 +1,2 @@ +optimum>=1.24.0 +gptqmodel>=2.0.0 diff --git a/examples/requirements/hqq.txt b/examples/requirements/hqq.txt new file mode 100644 index 000000000..800846850 --- /dev/null +++ b/examples/requirements/hqq.txt @@ -0,0 +1 @@ +hqq diff --git a/examples/requirements/liger-kernel.txt b/examples/requirements/liger-kernel.txt new file mode 100644 index 000000000..bd27a1a0f --- /dev/null +++ b/examples/requirements/liger-kernel.txt @@ -0,0 +1 @@ +liger-kernel>=0.5.5 diff --git a/examples/requirements/minicpm-v.txt b/examples/requirements/minicpm-v.txt new file mode 100644 index 000000000..2c05274c6 --- /dev/null +++ b/examples/requirements/minicpm-v.txt @@ -0,0 +1,8 @@ +soundfile +torchvision +torchaudio +vector_quantize_pytorch +vocos +msgpack +referencing +jsonschema_specifications diff --git a/examples/requirements/openmind.txt b/examples/requirements/openmind.txt new file mode 100644 index 000000000..0c75348f3 --- /dev/null +++ b/examples/requirements/openmind.txt @@ -0,0 +1 @@ +openmind diff --git a/examples/requirements/sglang.txt b/examples/requirements/sglang.txt new file mode 100644 index 000000000..ed4239944 --- /dev/null +++ b/examples/requirements/sglang.txt @@ -0,0 +1,2 @@ +sglang[srt]>=0.4.5 +transformers==4.51.1 diff --git a/examples/requirements/swanlab.txt b/examples/requirements/swanlab.txt new file mode 100644 index 000000000..85381455c --- /dev/null +++ b/examples/requirements/swanlab.txt @@ -0,0 +1 @@ +swanlab diff --git a/examples/requirements/vllm.txt b/examples/requirements/vllm.txt new file mode 100644 index 000000000..881bd2c64 --- /dev/null +++ b/examples/requirements/vllm.txt @@ -0,0 +1 @@ +vllm>=0.4.3,<=0.11.0 diff --git a/pyproject.toml b/pyproject.toml index a42faf8a2..ec8473eb1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,22 +1,104 @@ [build-system] -requires = ["setuptools>=61.0"] -build-backend = "setuptools.build_meta" +requires = ["hatchling"] +build-backend = "hatchling.build" [project] name = "llamafactory" +dynamic = ["version"] +description = "Unified Efficient Fine-Tuning of 100+ LLMs" +readme = "README.md" +license = "Apache-2.0" requires-python = ">=3.9.0" -dynamic = [ - "version", - "dependencies", - "optional-dependencies", - "scripts", - "authors", - "description", - "readme", - "license", - "keywords", - "classifiers" +authors = [ + { name = "hiyouga", email = "hiyouga@buaa.edu.cn" } ] +keywords = [ + "AI", + "LLM", + "GPT", + "ChatGPT", + "Llama", + "Transformer", + "DeepSeek", + "Pytorch" +] +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Intended Audience :: Education", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: Apache Software License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Topic :: Scientific/Engineering :: Artificial Intelligence" +] +dependencies = [ + # core deps + "transformers>=4.49.0,<=4.56.2,!=4.52.0; python_version < '3.10'", + "transformers>=4.49.0,<=4.57.1,!=4.52.0,!=4.57.0; python_version >= '3.10'", + "datasets>=2.16.0,<=4.0.0", + "accelerate>=1.3.0,<=1.11.0", + "peft>=0.14.0,<=0.17.1", + "trl>=0.8.6,<=0.9.6", + "torchdata", + # torch + "torch>=2.0.0", + "torchvision>=0.15.0", + # gui + "gradio>=4.38.0,<=5.45.0", + "matplotlib>=3.7.0", + "tyro<0.9.0", + # ops + "einops", + "numpy<2.0.0", + "pandas>=2.0.0", + "scipy", + # model and tokenizer + "sentencepiece", + "tiktoken", + "modelscope>=1.14.0", + "hf-transfer", + "safetensors<=0.5.3", + # python + "fire", + "omegaconf", + "packaging", + "protobuf", + "pyyaml", + "pydantic<=2.10.6", + # api + "uvicorn", + "fastapi", + "sse-starlette", + # media + "av", + "librosa", + # yanked + "propcache!=0.4.0" +] + +[project.optional-dependencies] +metrics = ["nltk", "jieba", "rouge-chinese"] +deepspeed = ["deepspeed>=0.10.0,<=0.16.9"] + +[project.scripts] +llamafactory-cli = "llamafactory.cli:main" +lmf = "llamafactory.cli:main" + +[project.urls] +Homepage = "https://github.com/hiyouga/LLaMA-Factory" +Repository = "https://github.com/hiyouga/LLaMA-Factory" + +[tool.hatch.build.targets.wheel] +packages = ["src/llamafactory"] + +[tool.hatch.version] +path = "src/llamafactory/extras/env.py" +pattern = "VERSION = \"(?P[^\"]+)\"" [tool.ruff] target-version = "py39" @@ -73,23 +155,3 @@ indent-style = "space" docstring-code-format = true skip-magic-trailing-comma = false line-ending = "auto" - -[tool.uv] -conflicts = [ - [ - { extra = "torch-npu" }, - { extra = "aqlm" }, - ], - [ - { extra = "torch-npu" }, - { extra = "vllm" }, - ], - [ - { extra = "torch-npu" }, - { extra = "sglang" }, - ], - [ - { extra = "vllm" }, - { extra = "sglang" }, - ], -] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 0ce57f3ba..000000000 --- a/requirements.txt +++ /dev/null @@ -1,39 +0,0 @@ -# core deps -transformers>=4.49.0,<=4.56.2,!=4.52.0; python_version < '3.10' -transformers>=4.49.0,<=4.57.1,!=4.52.0,!=4.57.0; python_version >= '3.10' -datasets>=2.16.0,<=4.0.0 -accelerate>=1.3.0,<=1.11.0 -peft>=0.14.0,<=0.17.1 -trl>=0.8.6,<=0.9.6 -torchdata -# gui -gradio>=4.38.0,<=5.45.0 -matplotlib>=3.7.0 -tyro<0.9.0 -# ops -einops -numpy<2.0.0 -pandas>=2.0.0 -scipy -# model and tokenizer -sentencepiece -tiktoken -modelscope>=1.14.0 -hf-transfer -safetensors<=0.5.3 -# python -fire -omegaconf -packaging -protobuf -pyyaml -pydantic<=2.10.6 -# api -uvicorn -fastapi -sse-starlette -# media -av -librosa -# yanked -propcache!=0.4.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index d7b5ca63d..000000000 --- a/setup.py +++ /dev/null @@ -1,116 +0,0 @@ -# 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 re - -from setuptools import find_packages, setup - - -def get_version() -> str: - with open(os.path.join("src", "llamafactory", "extras", "env.py"), encoding="utf-8") as f: - file_content = f.read() - pattern = r"{}\W*=\W*\"([^\"]+)\"".format("VERSION") - (version,) = re.findall(pattern, file_content) - return version - - -def get_requires() -> list[str]: - with open("requirements.txt", encoding="utf-8") as f: - file_content = f.read() - lines = [line.strip() for line in file_content.strip().split("\n") if not line.startswith("#")] - return lines - - -def get_console_scripts() -> list[str]: - console_scripts = ["llamafactory-cli = llamafactory.cli:main"] - if os.getenv("ENABLE_SHORT_CONSOLE", "1").lower() in ["true", "y", "1"]: - console_scripts.append("lmf = llamafactory.cli:main") - - return console_scripts - - -extra_require = { - "torch": ["torch>=2.0.0", "torchvision>=0.15.0"], - "torch-npu": ["torch==2.7.1", "torch-npu==2.7.1", "torchvision==0.22.1", "decorator"], - "metrics": ["nltk", "jieba", "rouge-chinese"], - "deepspeed": ["deepspeed>=0.10.0,<=0.16.9"], - "liger-kernel": ["liger-kernel>=0.5.5"], - "bitsandbytes": ["bitsandbytes>=0.39.0"], - "hqq": ["hqq"], - "eetq": ["eetq"], - "gptq": ["optimum>=1.24.0", "gptqmodel>=2.0.0"], - "aqlm": ["aqlm[gpu]>=1.1.0"], - "vllm": ["vllm>=0.4.3,<=0.11.0"], - "sglang": ["sglang[srt]>=0.4.5", "transformers==4.51.1"], - "galore": ["galore-torch"], - "apollo": ["apollo-torch"], - "badam": ["badam>=1.2.1"], - "adam-mini": ["adam-mini"], - "minicpm_v": [ - "soundfile", - "torchvision", - "torchaudio", - "vector_quantize_pytorch", - "vocos", - "msgpack", - "referencing", - "jsonschema_specifications", - ], - "openmind": ["openmind"], - "swanlab": ["swanlab"], - "fp8": ["torchao>=0.8.0", "accelerate>=1.10.0"], - "fp8-te": ["transformer_engine[pytorch]>=2.0.0", "accelerate>=1.10.0"], - "fp8-all": ["torchao>=0.8.0", "transformer_engine[pytorch]>=2.0.0", "accelerate>=1.10.0"], - "dev": ["pre-commit", "ruff", "pytest", "build"], -} - - -def main(): - setup( - name="llamafactory", - version=get_version(), - author="hiyouga", - author_email="hiyouga@buaa.edu.cn", - description="Unified Efficient Fine-Tuning of 100+ LLMs", - long_description=open("README.md", encoding="utf-8").read(), - long_description_content_type="text/markdown", - keywords=["AI", "LLM", "GPT", "ChatGPT", "Llama", "Transformer", "DeepSeek", "Pytorch"], - license="Apache 2.0 License", - url="https://github.com/hiyouga/LLaMA-Factory", - package_dir={"": "src"}, - packages=find_packages("src"), - python_requires=">=3.9.0", - install_requires=get_requires(), - extras_require=extra_require, - entry_points={"console_scripts": get_console_scripts()}, - classifiers=[ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Intended Audience :: Education", - "Intended Audience :: Science/Research", - "License :: OSI Approved :: Apache Software License", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", - "Programming Language :: Python :: 3.11", - "Programming Language :: Python :: 3.12", - "Topic :: Scientific/Engineering :: Artificial Intelligence", - ], - ) - - -if __name__ == "__main__": - main()