1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pythonOlder,
6 pythonRelaxDepsHook,
7 accelerate,
8 attrs,
9 bitsandbytes,
10 bentoml,
11 cattrs,
12 click-option-group,
13 datasets,
14 deepmerge,
15 hatch-fancy-pypi-readme,
16 hatch-vcs,
17 hatchling,
18 inflection,
19 mypy-extensions,
20 orjson,
21 peft,
22 transformers,
23 typing-extensions,
24}:
25
26buildPythonPackage rec {
27 pname = "openllm-core";
28 version = "0.4.44";
29 pyproject = true;
30
31 disabled = pythonOlder "3.8";
32
33 src = fetchFromGitHub {
34 owner = "bentoml";
35 repo = "OpenLLM";
36 rev = "refs/tags/v${version}";
37 hash = "sha256-kRR715Vnt9ZAmxuWvtH0z093crH0JFrEKPtbjO3QMRc=";
38 };
39
40 sourceRoot = "${src.name}/openllm-core";
41
42 nativeBuildInputs = [ pythonRelaxDepsHook ];
43
44 postPatch = ''
45 substituteInPlace pyproject.toml \
46 --replace-fail "hatch-vcs==0.3.0" "hatch-vcs" \
47 --replace-fail "hatchling==1.18.0" "hatchling" \
48 --replace-fail "hatch-fancy-pypi-readme==23.1.0" "hatch-fancy-pypi-readme"
49 '';
50
51 pythonRelaxDeps = [ "cattrs" ];
52
53 build-system = [
54 hatch-fancy-pypi-readme
55 hatch-vcs
56 hatchling
57 ];
58
59 dependencies = [
60 attrs
61 cattrs
62 # not listed in pyproject.toml, but required at runtime
63 click-option-group
64 deepmerge
65 inflection
66 mypy-extensions
67 orjson
68 typing-extensions
69 ];
70
71 optional-dependencies = {
72 vllm = [
73 # vllm
74 ];
75 bentoml = [ bentoml ];
76 fine-tune = [
77 accelerate
78 bitsandbytes
79 datasets
80 peft
81 transformers
82 # trl
83 ] ++ transformers.optional-dependencies.torch ++ transformers.optional-dependencies.tokenizers;
84 full =
85 with optional-dependencies;
86 (
87 vllm
88 # use absolute path to disambiguate with derivbation argument
89 ++ optional-dependencies.bentoml
90 ++ fine-tune
91 );
92 };
93
94 # there is no tests
95 doCheck = false;
96
97 pythonImportsCheck = [ "openllm_core" ];
98
99 meta = with lib; {
100 description = "Core components for OpenLLM";
101 homepage = "https://github.com/bentoml/OpenLLM/tree/main/openllm-core";
102 changelog = "https://github.com/bentoml/OpenLLM/blob/${src.rev}/CHANGELOG.md";
103 license = licenses.asl20;
104 maintainers = with maintainers; [ natsukium ];
105 };
106}