-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig.py
154 lines (147 loc) · 6.21 KB
/
config.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
150
151
152
153
154
class Config:
def __init__(self, args):
self.core_res = args.core_res
self.init_sparse_ratio = args.init_sparse_ratio
self.iter_sparse_ratio = args.iter_sparse_ratio
self.num_pruning_iters = args.num_pruning_iters
if any([k in args.arch for k in ['bert-base-uncased', 'vit-base', 'm2f']]):
self.hidden_dim = 768
elif any([k in args.arch for k in ['bert-large-uncased', 'vit-large']]):
self.hidden_dim = 1024
global_flag = True
self.training_params = {
'model_default': {
'data_default': {
'init': {
'num_train_epochs': 2,
'learning_rate': 1e-5
},
'iter': {
'num_train_epochs': 2,
'learning_rate': 1e-5
}
}
},
'vit-base': {
'data_default': {
'init': {
'num_train_epochs': 2,
'learning_rate': 1e-4
},
'iter': {
'num_train_epochs': 2,
'learning_rate': 1e-4
}
}
},
'vit-large': {
'data_default': {
'init': {
'num_train_epochs': 2,
'learning_rate': 1e-4
},
'iter': {
'num_train_epochs': 2,
'learning_rate': 1e-4
}
}
},
'm2f': {
'data_default': {
'init': {
'num_train_epochs': 2,
'learning_rate': 1e-4
},
'iter': {
'num_train_epochs': 2,
'learning_rate': 1e-4
}
},
'cityscapes': {
'init': {
'num_train_epochs': 2,
'learning_rate': 1e-4
},
'iter': {
'num_train_epochs': 2,
'learning_rate': 1e-4
}
},
'kitti': {
'init': {
'num_train_epochs': 2,
'learning_rate': 1e-4
},
'iter': {
'num_train_epochs': 2,
'learning_rate': 1e-4
}
},
},
'bert-base-uncased': {
'data_default': {
'init': {
'num_train_epochs': 2,
'learning_rate': 2e-5
},
'iter': {
'num_train_epochs': 2,
'learning_rate': 2e-5
}
}
},
'bert-large-uncased': {
'data_default': {
'init': {
'num_train_epochs': 2,
'learning_rate': 2e-5
},
'iter': {
'num_train_epochs': 2,
'learning_rate': 2e-5
}
}
}
}
self.pruning_params = {
'model_default': {
'data_default': {
'init': {
'training_steps': 10, # taylor
'global_flag': global_flag, # taylor
'num_iters': self.num_pruning_iters, # perform taylor in x iters
'attn': {'sparse_ratio': self.init_sparse_ratio,
'max_sparse_ratio': 0.85,
'granularity': [self.core_res, self.hidden_dim]},
'ffn': {'sparse_ratio': self.init_sparse_ratio,
'max_sparse_ratio': 0.85,
'granularity': [1, self.hidden_dim]}
},
'iter': {
'training_steps': 10, # taylor
'global_flag': global_flag, # taylor
'num_iters': 1, # perform taylor in x iters
'attn': {'sparse_ratio': self.iter_sparse_ratio,
'granularity': [1, self.hidden_dim]},
'ffn': {'sparse_ratio': self.iter_sparse_ratio,
'granularity': [1, self.hidden_dim]}
}
}
}
}
def get_init_training_params(self, model_name, data_name):
default_params = self.training_params.get(model_name, self.training_params['model_default'])['data_default']['init']
data_params = self.training_params.get(model_name, self.training_params['model_default']).get(data_name, {'init': {}})['init']
return default_params | data_params
def get_iter_training_params(self, model_name, data_name):
default_params = self.training_params.get(model_name, self.training_params['model_default'])['data_default']['iter']
data_params = self.training_params.get(model_name, self.training_params['model_default']).get(data_name, {'iter': {}})['iter']
return default_params | data_params
def get_init_pruning_params(self, model_name, data_name):
default_params = self.pruning_params.get(model_name, self.pruning_params['model_default'])['data_default']['init']
data_params = self.pruning_params.get(model_name, self.pruning_params['model_default']).get(data_name, {'init': {}})['init']
return default_params | data_params
def get_iter_pruning_params(self, model_name, data_name):
default_params = self.pruning_params.get(model_name, self.pruning_params['model_default'])['data_default']['iter']
data_params = self.pruning_params.get(model_name, self.pruning_params['model_default']).get(data_name, {'iter': {}})['iter']
return default_params | data_params