-
Notifications
You must be signed in to change notification settings - Fork 55
/
run.py
92 lines (77 loc) · 2.28 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# Apache Software License 2.0
#
# Copyright (c) ZenML GmbH 2024. All rights reserved.
#
# 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 typing import Optional
import click
@click.command(
help="""
ZenML LLM Finetuning project CLI v0.2.0.
Run the ZenML LLM Finetuning project LLM PEFT finetuning pipelines.
Examples:
\b
# Run the pipeline
python run.py
\b
# Run the pipeline with custom config
python run.py --config custom_finetune.yaml
"""
)
@click.option(
"--config",
type=str,
default="default_finetune.yaml",
help="Path to the YAML config file.",
)
@click.option(
"--accelerate",
is_flag=True,
default=False,
help="Run the pipeline with Accelerate.",
)
@click.option(
"--no-cache",
is_flag=True,
default=False,
help="Disable caching for the pipeline run.",
)
def main(
config: Optional[str] = None,
accelerate: bool = False,
no_cache: bool = False,
):
"""Main entry point for the pipeline execution.
Args:
config: Path to the YAML config file.
accelerate: If `True` Accelerate will be used.
no_cache: If `True` cache will be disabled.
"""
config_folder = os.path.join(
os.path.dirname(os.path.realpath(__file__)),
"configs",
)
pipeline_args = {"enable_cache": not no_cache}
if not config:
raise RuntimeError("Config file is required to run a pipeline.")
pipeline_args["config_path"] = os.path.join(config_folder, config)
if accelerate:
from pipelines.train_accelerated import llm_peft_full_finetune
llm_peft_full_finetune.with_options(**pipeline_args)()
else:
from pipelines.train import llm_peft_full_finetune
llm_peft_full_finetune.with_options(**pipeline_args)()
if __name__ == "__main__":
main()