forked from partcleda/intern_challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharg_parse_util.py
More file actions
245 lines (240 loc) · 7.19 KB
/
arg_parse_util.py
File metadata and controls
245 lines (240 loc) · 7.19 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
import argparse
from benchmark_test_cases import TEST_CASES_BY_ID
from learning_rate_scheduler_util import SCHEDULER_CHOICES
def _positive_int(value):
parsed_value = int(value)
if parsed_value < 1:
raise argparse.ArgumentTypeError("must be at least 1")
return parsed_value
def parse_args():
"""Parse command line arguments for optional profiling."""
parser = argparse.ArgumentParser()
parser.add_argument(
"--profile",
action="store_true",
help="Enable cProfile and dump results to the profile directory.",
)
parser.add_argument(
"--profile-tag",
default="",
help="Optional tag to include in the profile output filename.",
)
parser.add_argument(
"--torch-profile",
action="store_true",
help="Enable torch.profiler trace capture during training.",
)
parser.add_argument(
"--torch-profile-wait",
type=int,
default=1,
help="Number of initial training steps to skip before torch profiler warmup.",
)
parser.add_argument(
"--torch-profile-warmup",
type=int,
default=1,
help="Number of warmup steps for torch profiler.",
)
parser.add_argument(
"--torch-profile-active",
type=int,
default=3,
help="Number of active recording steps for torch profiler.",
)
parser.add_argument(
"--torch-profile-repeat",
type=int,
default=1,
help="Number of wait/warmup/active cycles to record. Use 0 to repeat until the run ends.",
)
parser.add_argument(
"--torch-profile-record-shapes",
action=argparse.BooleanOptionalAction,
default=True,
help="Enable or disable input-shape recording in torch profiler.",
)
parser.add_argument(
"--torch-profile-memory",
action=argparse.BooleanOptionalAction,
default=True,
help="Enable or disable memory tracking in torch profiler.",
)
parser.add_argument(
"--torch-profile-with-stack",
action=argparse.BooleanOptionalAction,
default=True,
help="Enable or disable stack trace capture in torch profiler.",
)
parser.add_argument(
"--torch-profile-acc-events",
action=argparse.BooleanOptionalAction,
default=False,
help="Accumulate profiler events across schedule cycles to avoid cycle-reset warnings.",
)
parser.add_argument(
"--num-epochs",
type=int,
default=1000,
help="Number of optimization epochs for a regular training run.",
)
parser.add_argument(
"--num-macros",
type=int,
default=3,
help="Number of macro cells to generate for a placement run.",
)
parser.add_argument(
"--num-std-cells",
type=int,
default=10,
help="Number of standard cells to generate for a placement run.",
)
parser.add_argument(
"--seed",
type=int,
default=42,
help="Random seed used to generate and initialize the placement problem.",
)
parser.add_argument(
"--device",
choices=("auto", "cpu", "cuda", "mps"),
default="auto",
help="Torch device to use. 'auto' selects cuda, then mps, then cpu.",
)
parser.add_argument(
"--test-case-id",
type=int,
choices=sorted(TEST_CASES_BY_ID),
help="Optional benchmark test case to load. Overrides --num-macros, --num-std-cells, and --seed.",
)
parser.add_argument(
"--lr",
type=float,
default=0.1,
help="Learning rate for the Adam optimizer.",
)
parser.add_argument(
"--lambda-wirelength",
type=float,
default=3.0,
help="Weight applied to the wirelength term.",
)
parser.add_argument(
"--lambda-overlap",
type=float,
default=1.0,
help="Weight applied to the overlap term.",
)
parser.add_argument(
"--scheduler",
choices=SCHEDULER_CHOICES,
default="plateau",
help="Learning-rate scheduler to use during training.",
)
parser.add_argument(
"--scheduler-patience",
type=int,
default=50,
help="Patience for ReduceLROnPlateau.",
)
parser.add_argument(
"--scheduler-factor",
type=float,
default=0.5,
help="Decay factor for ReduceLROnPlateau.",
)
parser.add_argument(
"--scheduler-eta-min",
type=float,
default=1e-4,
help="Minimum learning rate for cosine annealing.",
)
parser.add_argument(
"--scheduler-step-size",
type=int,
default=100,
help="Step size in epochs for StepLR.",
)
parser.add_argument(
"--scheduler-gamma",
type=float,
default=0.95,
help="Gamma decay used by StepLR and ExponentialLR.",
)
parser.add_argument(
"--optuna",
action="store_true",
help="Run Optuna hyperparameter search instead of a single training run.",
)
parser.add_argument(
"--optuna-trials",
type=int,
default=25,
help="Number of Optuna trials to execute.",
)
parser.add_argument(
"--optuna-epochs",
type=int,
default=400,
help="Number of epochs per Optuna trial.",
)
parser.add_argument(
"--optuna-study-name",
default="placement_hparam_search",
help="Study name used by Optuna.",
)
parser.add_argument(
"--optuna-storage",
default="",
help="Optional Optuna storage URL, for example sqlite:///optuna.db.",
)
parser.add_argument(
"--track-loss-history",
action=argparse.BooleanOptionalAction,
default=True,
help="Enable or disable loss-history collection and persistence.",
)
parser.add_argument(
"--track-overlap-metrics",
action=argparse.BooleanOptionalAction,
default=False,
help="Enable or disable per-epoch overlap-metric collection for loss tracking.",
)
parser.add_argument(
"--early-stop",
action=argparse.BooleanOptionalAction,
default=True,
help="Enable or disable overlap-first early stopping during training.",
)
parser.add_argument(
"--early-stop-patience",
type=_positive_int,
default=75,
help="Patience before stopping when overlap stops improving.",
)
parser.add_argument(
"--early-stop-min-delta",
type=float,
default=1e-4,
help="Minimum improvement required to reset early-stop patience.",
)
parser.add_argument(
"--early-stop-overlap-threshold",
type=float,
default=0.0,
help="Treat overlap below this value as effectively zero for early stopping.",
)
parser.add_argument(
"--early-stop-zero-overlap-patience",
type=_positive_int,
default=25,
help="Extra patience after zero-overlap is reached to keep reducing wirelength.",
)
parser.add_argument(
"--workers",
type=_positive_int,
default=4,
help="Number of worker processes for test.py. Use 1 to run serially.",
)
return parser.parse_args()