setup.py 3.96 KB
Newer Older
chenych's avatar
chenych committed
1
# Copyright 2025 the LlamaFactory team.
chenych's avatar
chenych committed
2
3
4
5
6
7
8
9
10
11
12
13
14
#
# 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.

Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
15
16
17
18
19
20
import os
import re

from setuptools import find_packages, setup


luopl's avatar
luopl committed
21
def get_version() -> str:
luopl's avatar
luopl committed
22
    with open(os.path.join("src", "llamafactory", "extras", "env.py"), encoding="utf-8") as f:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
23
        file_content = f.read()
chenych's avatar
chenych committed
24
        pattern = r"{}\W*=\W*\"([^\"]+)\"".format("VERSION")
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
25
26
27
28
        (version,) = re.findall(pattern, file_content)
        return version


chenych's avatar
chenych committed
29
def get_requires() -> list[str]:
luopl's avatar
luopl committed
30
    with open("requirements.txt", encoding="utf-8") as f:
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
31
32
33
34
35
        file_content = f.read()
        lines = [line.strip() for line in file_content.strip().split("\n") if not line.startswith("#")]
        return lines


chenych's avatar
chenych committed
36
def get_console_scripts() -> list[str]:
luopl's avatar
luopl committed
37
    console_scripts = ["llamafactory-cli = llamafactory.cli:main"]
chenych's avatar
chenych committed
38
    if os.getenv("ENABLE_SHORT_CONSOLE", "1").lower() in ["true", "y", "1"]:
luopl's avatar
luopl committed
39
40
41
42
43
        console_scripts.append("lmf = llamafactory.cli:main")

    return console_scripts


Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
44
extra_require = {
chenych's avatar
chenych committed
45
    "torch": ["torch>=2.0.0", "torchvision>=0.15.0"],
chenych's avatar
chenych committed
46
    "torch-npu": ["torch==2.4.0", "torch-npu==2.4.0.post2", "decorator"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
47
    "metrics": ["nltk", "jieba", "rouge-chinese"],
chenych's avatar
chenych committed
48
    "deepspeed": ["deepspeed>=0.10.0,<=0.16.9"],
chenych's avatar
chenych committed
49
    "liger-kernel": ["liger-kernel>=0.5.5"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
50
    "bitsandbytes": ["bitsandbytes>=0.39.0"],
chenych's avatar
chenych committed
51
52
    "hqq": ["hqq"],
    "eetq": ["eetq"],
chenych's avatar
chenych committed
53
    "gptq": ["optimum>=1.24.0", "gptqmodel>=2.0.0"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
54
    "aqlm": ["aqlm[gpu]>=1.1.0"],
chenych's avatar
chenych committed
55
    "vllm": ["vllm>=0.4.3,<=0.9.1"],
chenych's avatar
chenych committed
56
    "sglang": ["sglang[srt]>=0.4.5", "transformers==4.51.1"],
chenych's avatar
chenych committed
57
    "galore": ["galore-torch"],
luopl's avatar
luopl committed
58
    "apollo": ["apollo-torch"],
chenych's avatar
chenych committed
59
60
    "badam": ["badam>=1.2.1"],
    "adam-mini": ["adam-mini"],
luopl's avatar
luopl committed
61
62
63
64
65
66
67
68
69
70
    "minicpm_v": [
        "soundfile",
        "torchvision",
        "torchaudio",
        "vector_quantize_pytorch",
        "vocos",
        "msgpack",
        "referencing",
        "jsonschema_specifications",
    ],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
71
    "modelscope": ["modelscope"],
luopl's avatar
luopl committed
72
    "openmind": ["openmind"],
luopl's avatar
luopl committed
73
    "swanlab": ["swanlab"],
chenych's avatar
chenych committed
74
    "dev": ["pre-commit", "ruff", "pytest", "build"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
75
76
77
78
79
}


def main():
    setup(
chenych's avatar
chenych committed
80
        name="llamafactory",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
81
82
        version=get_version(),
        author="hiyouga",
chenych's avatar
chenych committed
83
84
        author_email="hiyouga@buaa.edu.cn",
        description="Unified Efficient Fine-Tuning of 100+ LLMs",
luopl's avatar
luopl committed
85
        long_description=open("README.md", encoding="utf-8").read(),
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
86
        long_description_content_type="text/markdown",
chenych's avatar
chenych committed
87
        keywords=["AI", "LLM", "GPT", "ChatGPT", "Llama", "Transformer", "DeepSeek", "Pytorch"],
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
88
89
90
91
        license="Apache 2.0 License",
        url="https://github.com/hiyouga/LLaMA-Factory",
        package_dir={"": "src"},
        packages=find_packages("src"),
chenych's avatar
chenych committed
92
        python_requires=">=3.9.0",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
93
94
        install_requires=get_requires(),
        extras_require=extra_require,
luopl's avatar
luopl committed
95
        entry_points={"console_scripts": get_console_scripts()},
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
96
97
98
99
100
101
102
103
104
105
106
        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",
chenych's avatar
chenych committed
107
            "Programming Language :: Python :: 3.12",
Rayyyyy's avatar
V0.6.3  
Rayyyyy committed
108
109
110
111
112
113
114
            "Topic :: Scientific/Engineering :: Artificial Intelligence",
        ],
    )


if __name__ == "__main__":
    main()