-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.py
149 lines (138 loc) · 7.7 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import argparse
import os
import random
import numpy as np
import torch
import torch.distributed as dist
from exp.exp_long_term_forecasting import Exp_Long_Term_Forecast
from exp.exp_short_term_forecasting import Exp_Short_Term_Forecast
from exp.exp_zero_shot_forecasting import Exp_Zero_Shot_Forecast
from exp.exp_in_context_forecasting import Exp_In_Context_Forecast
if __name__ == '__main__':
fix_seed = 2021
random.seed(fix_seed)
torch.manual_seed(fix_seed)
np.random.seed(fix_seed)
parser = argparse.ArgumentParser(description='AutoTimes')
# basic config
parser.add_argument('--task_name', type=str, required=True, default='long_term_forecast',
help='task name, options:[long_term_forecast, short_term_forecast, zero_shot_forecasting, in_context_forecasting]')
parser.add_argument('--is_training', type=int, required=True, default=1, help='status')
parser.add_argument('--model_id', type=str, required=True, default='test', help='model id')
parser.add_argument('--model', type=str, required=True, default='AutoTimes_Llama',
help='model name, options: [AutoTimes_Llama, AutoTimes_Gpt2, AutoTimes_Opt1b]')
# data loader
parser.add_argument('--data', type=str, required=True, default='ETTm1', help='dataset type')
parser.add_argument('--root_path', type=str, default='./data/ETT/', help='root path of the data file')
parser.add_argument('--data_path', type=str, default='ETTh1.csv', help='data file')
parser.add_argument('--test_data_path', type=str, default='ETTh1.csv', help='test data file used in zero shot forecasting')
parser.add_argument('--checkpoints', type=str, default='./checkpoints/', help='location of model checkpoints')
parser.add_argument('--drop_last', action='store_true', default=False, help='drop last batch in data loader')
parser.add_argument('--val_set_shuffle', action='store_false', default=True, help='shuffle validation set')
parser.add_argument('--drop_short', action='store_true', default=False, help='drop too short sequences in dataset')
# forecasting task
parser.add_argument('--seq_len', type=int, default=672, help='input sequence length')
parser.add_argument('--label_len', type=int, default=576, help='label length')
parser.add_argument('--token_len', type=int, default=96, help='token length')
parser.add_argument('--test_seq_len', type=int, default=672, help='test seq len')
parser.add_argument('--test_label_len', type=int, default=576, help='test label len')
parser.add_argument('--test_pred_len', type=int, default=96, help='test pred len')
parser.add_argument('--seasonal_patterns', type=str, default='Monthly', help='subset for M4')
# model define
parser.add_argument('--dropout', type=float, default=0.1, help='dropout')
parser.add_argument('--llm_ckp_dir', type=str, default='./llama', help='llm checkpoints dir')
parser.add_argument('--mlp_hidden_dim', type=int, default=256, help='mlp hidden dim')
parser.add_argument('--mlp_hidden_layers', type=int, default=2, help='mlp hidden layers')
parser.add_argument('--mlp_activation', type=str, default='tanh', help='mlp activation')
# optimization
parser.add_argument('--num_workers', type=int, default=10, help='data loader num workers')
parser.add_argument('--itr', type=int, default=1, help='experiments times')
parser.add_argument('--train_epochs', type=int, default=10, help='train epochs')
parser.add_argument('--batch_size', type=int, default=32, help='batch size of train input data')
parser.add_argument('--patience', type=int, default=3, help='early stopping patience')
parser.add_argument('--learning_rate', type=float, default=0.0001, help='optimizer learning rate')
parser.add_argument('--des', type=str, default='test', help='exp description')
parser.add_argument('--loss', type=str, default='MSE', help='loss function')
parser.add_argument('--lradj', type=str, default='type1', help='adjust learning rate')
parser.add_argument('--use_amp', action='store_true', help='use automatic mixed precision training', default=False)
parser.add_argument('--cosine', action='store_true', help='use cosine annealing lr', default=False)
parser.add_argument('--tmax', type=int, default=10, help='tmax in cosine anealing lr')
parser.add_argument('--weight_decay', type=float, default=0)
parser.add_argument('--mix_embeds', action='store_true', help='mix embeds', default=False)
parser.add_argument('--test_dir', type=str, default='./test', help='test dir')
parser.add_argument('--test_file_name', type=str, default='checkpoint.pth', help='test file')
# GPU
parser.add_argument('--gpu', type=int, default=0, help='gpu')
parser.add_argument('--use_multi_gpu', action='store_true', help='use multiple gpus', default=False)
parser.add_argument('--visualize', action='store_true', help='visualize', default=False)
args = parser.parse_args()
if args.use_multi_gpu:
ip = os.environ.get("MASTER_ADDR", "127.0.0.1")
port = os.environ.get("MASTER_PORT", "64209")
hosts = int(os.environ.get("WORLD_SIZE", "8"))
rank = int(os.environ.get("RANK", "0"))
local_rank = int(os.environ.get("LOCAL_RANK", "0"))
gpus = torch.cuda.device_count()
args.local_rank = local_rank
print(ip, port, hosts, rank, local_rank, gpus)
dist.init_process_group(backend="nccl", init_method=f"tcp://{ip}:{port}", world_size=hosts,
rank=rank)
torch.cuda.set_device(local_rank)
if args.task_name == 'long_term_forecast':
Exp = Exp_Long_Term_Forecast
elif args.task_name == 'short_term_forecast':
Exp = Exp_Short_Term_Forecast
elif args.task_name == 'zero_shot_forecast':
Exp = Exp_Zero_Shot_Forecast
elif args.task_name == 'in_context_forecast':
Exp = Exp_In_Context_Forecast
else:
Exp = Exp_Long_Term_Forecast
if args.is_training:
for ii in range(args.itr):
# setting record of experiments
exp = Exp(args) # set experiments
setting = '{}_{}_{}_{}_sl{}_ll{}_tl{}_lr{}_bt{}_wd{}_hd{}_hl{}_cos{}_mix{}_{}_{}'.format(
args.task_name,
args.model_id,
args.model,
args.data,
args.seq_len,
args.label_len,
args.token_len,
args.learning_rate,
args.batch_size,
args.weight_decay,
args.mlp_hidden_dim,
args.mlp_hidden_layers,
args.cosine,
args.mix_embeds,
args.des, ii)
if (args.use_multi_gpu and args.local_rank == 0) or not args.use_multi_gpu:
print('>>>>>>>start training : {}>>>>>>>>>>>>>>>>>>>>>>>>>>'.format(setting))
exp.train(setting)
if (args.use_multi_gpu and args.local_rank == 0) or not args.use_multi_gpu:
print('>>>>>>>testing : {}<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'.format(setting))
exp.test(setting)
torch.cuda.empty_cache()
else:
ii = 0
setting = '{}_{}_{}_{}_sl{}_ll{}_tl{}_lr{}_bt{}_wd{}_hd{}_hl{}_cos{}_mix{}_{}_{}'.format(
args.task_name,
args.model_id,
args.model,
args.data,
args.seq_len,
args.label_len,
args.token_len,
args.learning_rate,
args.batch_size,
args.weight_decay,
args.mlp_hidden_dim,
args.mlp_hidden_layers,
args.cosine,
args.mix_embeds,
args.des, ii)
exp = Exp(args) # set experiments
exp.test(setting, test=1)
torch.cuda.empty_cache()