LMFuser 0.0.2__tar.gz → 0.0.4__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.
- {lmfuser-0.0.2 → lmfuser-0.0.4}/PKG-INFO +1 -1
- {lmfuser-0.0.2 → lmfuser-0.0.4}/pyproject.toml +1 -1
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/runners/ddp_runner.py +16 -19
- {lmfuser-0.0.2 → lmfuser-0.0.4}/.github/workflows/python-publish.yml +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/.gitignore +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/.vscode/settings.json +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/LICENSE +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/README.md +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/__init__.py +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/model_loader.py +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/optimizers.py +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/runners/__init__.py +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/runners/runner.py +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/schedulers.py +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/task.py +0 -0
- {lmfuser-0.0.2 → lmfuser-0.0.4}/src/lmfuser/utils.py +0 -0
|
@@ -257,7 +257,8 @@ class DDPRunner(Runner[DDPRunnerConfig]):
|
|
|
257
257
|
model = getattr(self, '_model', None)
|
|
258
258
|
if model is None:
|
|
259
259
|
model = self.load_model()
|
|
260
|
-
if self.config.model_precision == 'fp16':
|
|
260
|
+
if self.config.model_precision.value() == 'fp16':
|
|
261
|
+
logger.critical(f'casting model to fp16')
|
|
261
262
|
model = model.half()
|
|
262
263
|
self._model = DDPWraper(model)
|
|
263
264
|
return self._model
|
|
@@ -322,20 +323,17 @@ class DDPRunner(Runner[DDPRunnerConfig]):
|
|
|
322
323
|
self.scheduler.load_state_dict(self._scheduler_states)
|
|
323
324
|
|
|
324
325
|
if scaler is None:
|
|
325
|
-
if self.config.use_amp and
|
|
326
|
-
|
|
327
|
-
if amp_selection == 'fp16':
|
|
328
|
-
enable_scaler = True
|
|
329
|
-
elif amp_selection == 'bf16':
|
|
330
|
-
enable_scaler = False
|
|
331
|
-
else:
|
|
332
|
-
raise ValueError(f'Unknown amp precision "{amp_selection}"')
|
|
333
|
-
if OLD_GRADSCALER:
|
|
334
|
-
self.scaler = GradScaler(enabled=enable_scaler)
|
|
335
|
-
else:
|
|
336
|
-
self.scaler = GradScaler(device=get_default_device_type(), enabled=enable_scaler) # type: ignore
|
|
326
|
+
if self.config.use_amp.value() and self.config.amp_precision.value() == 'fp16':
|
|
327
|
+
enable_scaler = True
|
|
337
328
|
else:
|
|
338
|
-
|
|
329
|
+
enable_scaler = False
|
|
330
|
+
if self.config.model_precision.value() == 'fp16':
|
|
331
|
+
enable_scaler = False
|
|
332
|
+
|
|
333
|
+
if OLD_GRADSCALER:
|
|
334
|
+
self.scaler = GradScaler(enabled=enable_scaler)
|
|
335
|
+
else:
|
|
336
|
+
self.scaler = GradScaler(device=get_default_device_type(), enabled=enable_scaler) # type: ignore
|
|
339
337
|
else:
|
|
340
338
|
self.scaler = scaler
|
|
341
339
|
|
|
@@ -394,11 +392,7 @@ class DDPRunner(Runner[DDPRunnerConfig]):
|
|
|
394
392
|
for acc_idx in range(self.config._num_acc_steps):
|
|
395
393
|
with ExitStack() as stack:
|
|
396
394
|
# check whether to use amp
|
|
397
|
-
if
|
|
398
|
-
self.config.use_amp,
|
|
399
|
-
self.config.model_precision == 'fp32',
|
|
400
|
-
get_world_size() > 1
|
|
401
|
-
]):
|
|
395
|
+
if self.config.use_amp.value():
|
|
402
396
|
amp_selection = self.config.amp_precision.value()
|
|
403
397
|
assert amp_selection is not None
|
|
404
398
|
stack.enter_context(autocast(
|
|
@@ -438,6 +432,7 @@ class DDPRunner(Runner[DDPRunnerConfig]):
|
|
|
438
432
|
self.scaler.scale(loss).backward()
|
|
439
433
|
else:
|
|
440
434
|
loss.backward()
|
|
435
|
+
|
|
441
436
|
running_loss = dist_avg(running_loss)
|
|
442
437
|
self.step_log({f'{task.__class__.__name__}/train/loss': running_loss})
|
|
443
438
|
self.step_log({'train/epoch': self.epoch})
|
|
@@ -453,6 +448,8 @@ class DDPRunner(Runner[DDPRunnerConfig]):
|
|
|
453
448
|
|
|
454
449
|
grad_norm_clip_val = self.config.grad_norm_clip.value()
|
|
455
450
|
if grad_norm_clip_val is not None:
|
|
451
|
+
if self.scaler is not None:
|
|
452
|
+
self.scaler.unscale_(self.optimizer)
|
|
456
453
|
norm = clip_grad_norm_(
|
|
457
454
|
parameters=self.model.parameters(),
|
|
458
455
|
max_norm=grad_norm_clip_val
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|