trainloop 0.2.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {trainloop-0.2.0 → trainloop-0.4.0}/PKG-INFO +1 -1
- {trainloop-0.2.0 → trainloop-0.4.0}/pyproject.toml +1 -1
- {trainloop-0.2.0 → trainloop-0.4.0}/src/trainloop/hooks.py +20 -4
- {trainloop-0.2.0 → trainloop-0.4.0}/src/trainloop/trainer.py +2 -0
- {trainloop-0.2.0 → trainloop-0.4.0}/README.md +0 -0
- {trainloop-0.2.0 → trainloop-0.4.0}/src/trainloop/__init__.py +0 -0
- {trainloop-0.2.0 → trainloop-0.4.0}/src/trainloop/py.typed +0 -0
- {trainloop-0.2.0 → trainloop-0.4.0}/src/trainloop/utils.py +0 -0
|
@@ -101,6 +101,7 @@ class _StatsHook(BaseHook):
|
|
|
101
101
|
self.grad_norms = []
|
|
102
102
|
self.data_times = []
|
|
103
103
|
self.step_times = []
|
|
104
|
+
self.non_finite_grad_retry_counts = []
|
|
104
105
|
self.max_memories = []
|
|
105
106
|
|
|
106
107
|
def on_after_step(self, trainer: BaseTrainer):
|
|
@@ -111,6 +112,9 @@ class _StatsHook(BaseHook):
|
|
|
111
112
|
self.records_ls.append(key_average(trainer.step_info["records"]))
|
|
112
113
|
self.data_times.append(sum(trainer.step_info["data_time"])) # total
|
|
113
114
|
self.step_times.append(trainer.step_info["step_time"])
|
|
115
|
+
self.non_finite_grad_retry_counts.append(
|
|
116
|
+
trainer.step_info["non_finite_grad_retry_count"]
|
|
117
|
+
)
|
|
114
118
|
if "max_memory" in trainer.step_info:
|
|
115
119
|
self.max_memories.append(trainer.step_info["max_memory"])
|
|
116
120
|
|
|
@@ -121,6 +125,9 @@ class _StatsHook(BaseHook):
|
|
|
121
125
|
records = key_average(self.records_ls)
|
|
122
126
|
data_time = sum(self.data_times) / len(self.data_times)
|
|
123
127
|
step_time = sum(self.step_times) / len(self.step_times)
|
|
128
|
+
non_finite_grad_retry_count = sum(self.non_finite_grad_retry_counts) / len(
|
|
129
|
+
self.non_finite_grad_retry_counts
|
|
130
|
+
)
|
|
124
131
|
max_memory = max(self.max_memories) if self.max_memories else None
|
|
125
132
|
|
|
126
133
|
if self.sync and _dist_world_size() > 1:
|
|
@@ -136,12 +143,16 @@ class _StatsHook(BaseHook):
|
|
|
136
143
|
"records": records,
|
|
137
144
|
"data_time": data_time,
|
|
138
145
|
"step_time": step_time,
|
|
146
|
+
"non_finite_grad_retry_count": non_finite_grad_retry_count,
|
|
139
147
|
"max_memory": max_memory,
|
|
140
148
|
},
|
|
141
149
|
)
|
|
142
150
|
records = key_average([stat["records"] for stat in gathered])
|
|
143
151
|
data_time = sum(stat["data_time"] for stat in gathered) / len(gathered)
|
|
144
152
|
step_time = sum(stat["step_time"] for stat in gathered) / len(gathered)
|
|
153
|
+
non_finite_grad_retry_count = sum(
|
|
154
|
+
stat["non_finite_grad_retry_count"] for stat in gathered
|
|
155
|
+
) / len(gathered)
|
|
145
156
|
if "max_memory" in trainer.step_info:
|
|
146
157
|
max_memory = max(stat["max_memory"] for stat in gathered)
|
|
147
158
|
|
|
@@ -151,6 +162,7 @@ class _StatsHook(BaseHook):
|
|
|
151
162
|
grad_norm.item() if grad_norm is not None else None,
|
|
152
163
|
step_time,
|
|
153
164
|
data_time,
|
|
165
|
+
non_finite_grad_retry_count,
|
|
154
166
|
max_memory,
|
|
155
167
|
records,
|
|
156
168
|
)
|
|
@@ -163,6 +175,7 @@ class _StatsHook(BaseHook):
|
|
|
163
175
|
grad_norm: float | None,
|
|
164
176
|
step_time: float,
|
|
165
177
|
data_time: float,
|
|
178
|
+
non_finite_grad_retry_count: float,
|
|
166
179
|
max_memory: float | None,
|
|
167
180
|
records: Records,
|
|
168
181
|
):
|
|
@@ -235,7 +248,7 @@ class ProgressHook(_StatsHook):
|
|
|
235
248
|
def on_before_step(self, trainer: BaseTrainer):
|
|
236
249
|
super().on_before_step(trainer)
|
|
237
250
|
self.lrs = [
|
|
238
|
-
(i, param_group["lr"])
|
|
251
|
+
(param_group.get("name", str(i)), param_group["lr"])
|
|
239
252
|
for i, param_group in enumerate(trainer.optimizer.param_groups)
|
|
240
253
|
] # record the LR before the scheduler steps
|
|
241
254
|
|
|
@@ -250,6 +263,7 @@ class ProgressHook(_StatsHook):
|
|
|
250
263
|
grad_norm: float | None,
|
|
251
264
|
step_time: float,
|
|
252
265
|
data_time: float,
|
|
266
|
+
non_finite_grad_retry_count: float,
|
|
253
267
|
max_memory: float | None,
|
|
254
268
|
records: Records,
|
|
255
269
|
):
|
|
@@ -265,7 +279,7 @@ class ProgressHook(_StatsHook):
|
|
|
265
279
|
)
|
|
266
280
|
+ f" loss {loss:.4f}"
|
|
267
281
|
+ (f" grad_norm {grad_norm:.4f}" if grad_norm is not None else "")
|
|
268
|
-
+ (" " + " ".join(f"
|
|
282
|
+
+ (" " + " ".join(f"lr/{name} {lr:.2e}" for name, lr in self.lrs))
|
|
269
283
|
+ (
|
|
270
284
|
(
|
|
271
285
|
" | "
|
|
@@ -302,11 +316,12 @@ class LoggingHook(_StatsHook):
|
|
|
302
316
|
grad_norm: float | None,
|
|
303
317
|
step_time: float,
|
|
304
318
|
data_time: float,
|
|
319
|
+
non_finite_grad_retry_count: float,
|
|
305
320
|
max_memory: float | None,
|
|
306
321
|
records: Records,
|
|
307
322
|
):
|
|
308
323
|
lrs = [
|
|
309
|
-
(i, param_group["lr"])
|
|
324
|
+
(param_group.get("name", f"group_{i}"), param_group["lr"])
|
|
310
325
|
for i, param_group in enumerate(trainer.optimizer.param_groups)
|
|
311
326
|
]
|
|
312
327
|
trainer.log(
|
|
@@ -318,7 +333,8 @@ class LoggingHook(_StatsHook):
|
|
|
318
333
|
"loss": loss,
|
|
319
334
|
"data_time": data_time,
|
|
320
335
|
"step_time": step_time,
|
|
321
|
-
"
|
|
336
|
+
"non_finite_grad_retry_count": non_finite_grad_retry_count,
|
|
337
|
+
"lr": {name: lr for name, lr in lrs},
|
|
322
338
|
}
|
|
323
339
|
}
|
|
324
340
|
)
|
|
@@ -204,6 +204,7 @@ class BaseTrainer:
|
|
|
204
204
|
reset_step_info()
|
|
205
205
|
self.step_info["data_time"] = []
|
|
206
206
|
non_finite_grad_retry_count = 0
|
|
207
|
+
self.step_info["non_finite_grad_retry_count"] = non_finite_grad_retry_count
|
|
207
208
|
i_acc = 0
|
|
208
209
|
while i_acc < self.gradient_accumulation_steps:
|
|
209
210
|
is_accumulating = i_acc < self.gradient_accumulation_steps - 1
|
|
@@ -275,6 +276,7 @@ class BaseTrainer:
|
|
|
275
276
|
< self.max_non_finite_grad_retries
|
|
276
277
|
):
|
|
277
278
|
non_finite_grad_retry_count += 1
|
|
279
|
+
self.step_info["non_finite_grad_retry_count"] = non_finite_grad_retry_count
|
|
278
280
|
self.logger.warning(
|
|
279
281
|
f"Gradient is non-finite. Retrying step {self.step} (retry {non_finite_grad_retry_count}"
|
|
280
282
|
+ (
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|