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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: LMFuser
3
- Version: 0.0.2
3
+ Version: 0.0.4
4
4
  Summary: The LMFuser training framework.
5
5
  Project-URL: Homepage, https://github.com/TYTTYTTYT/LMFuser
6
6
  Project-URL: Documentation, https://github.com/TYTTYTTYT/LMFuser
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "LMFuser"
7
- version = "0.0.2"
7
+ version = "0.0.4"
8
8
  requires-python = ">= 3.11"
9
9
  description = "The LMFuser training framework."
10
10
  readme = "README.md"
@@ -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 get_world_size() > 1:
326
- amp_selection = self.config.amp_precision.value()
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
- self.scaler = None
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 all([
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