-
Notifications
You must be signed in to change notification settings - Fork 52
/
train.py
executable file
·43 lines (32 loc) · 1.31 KB
/
train.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
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from internlm.core.context import global_context as gpc
from internlm.core.trainer_builder import TrainerBuilder
from internlm.data import (
build_train_loader_with_data_type,
build_valid_loader_with_data_type,
)
from internlm.initialize import initialize_distributed_env
from internlm.model.builder import create_model
from internlm.monitor import internevo_monitor
from internlm.utils.common import parse_args
@internevo_monitor(feishu_alert=True, clean_run=True)
def main(args):
# initialize model
model = create_model(model_type=gpc.config.model_type)
# initialize train dataloader
train_dl, dataset_types = build_train_loader_with_data_type()
# initialize validation dataloader
val_dls = build_valid_loader_with_data_type()
# build trainer
merged_args = {**vars(args), "dataset_types": dataset_types}
trainer = TrainerBuilder(model, train_dl, val_dls, **merged_args)
# training
trainer.fit()
if __name__ == "__main__":
args = parse_args()
# Initialize distributed environment
initialize_distributed_env(config=args.config, launcher=args.launcher, master_port=args.port, seed=args.seed)
assert hasattr(gpc, "config") and gpc.config is not None
# Run the main function with parsed arguments
main(args)