MCPcopy Create free account
hub / github.com/AIS-SNU/Smart-Infinity / save_16bit_model

Method save_16bit_model

deepspeed/runtime/engine.py:3320–3365  ·  view source on GitHub ↗

Save 16bit model weights This method saves the 16bit model weights at the desired destination. Arguments: save_dir: Required. Directory for saving the model save_filename: Optional. Filename to save to. Defaults to ``pytorch_model.bin`` Ret

(self, save_dir, save_filename="pytorch_model.bin")

Source from the content-addressed store, hash-verified

3318 return self.save_16bit_model(save_dir, save_filename)
3319
3320 def save_16bit_model(self, save_dir, save_filename="pytorch_model.bin"):
3321 """
3322 Save 16bit model weights
3323
3324 This method saves the 16bit model weights at the desired destination.
3325
3326 Arguments:
3327 save_dir: Required. Directory for saving the model
3328 save_filename: Optional. Filename to save to. Defaults to ``pytorch_model.bin``
3329
3330 Returns:
3331 ``True`` when a model has been saved, ``False`` otherwise. It will not be saved if
3332 stage3_gather_16bit_weights_on_model_save is ``False``.
3333
3334 Important: all processes must call this method and not just the process with rank 0. It is
3335 because the processes need to work in sync to gather the weights. This method will hang
3336 waiting to synchronize with other processes if it's called just for the process with rank 0.
3337
3338 """
3339
3340 path = os.path.join(save_dir, save_filename)
3341
3342 if self.zero_optimization_partition_weights():
3343 if self.zero_gather_16bit_weights_on_model_save():
3344 # consolidation is expensive in time and memory and therefore isn't a default
3345 state_dict = self._zero3_consolidated_16bit_state_dict()
3346 else:
3347 # the model will be bogus if not consolidated so don't confuse the user by saving it
3348 logger.info(
3349 f"Did not save the model {path} because `stage3_gather_16bit_weights_on_model_save` is False")
3350 return False
3351 else:
3352 state_dict = self.module.state_dict()
3353
3354 tag = f"global_step{self.global_steps}"
3355 tag = str(tag)
3356 self.checkpoint_engine.create(tag)
3357
3358 if dist.get_rank() == 0:
3359 self.checkpoint_engine.makedirs(save_dir, exist_ok=True)
3360 logger.info(f"Saving model weights to {path}, tag: {tag}")
3361 self.checkpoint_engine.save(state_dict, path)
3362
3363 self.checkpoint_engine.commit(tag)
3364
3365 return True
3366
3367 def empty_partition_cache(self):
3368 """

Callers 1

save_fp16_modelMethod · 0.95

Calls 9

makedirsMethod · 0.80
state_dictMethod · 0.45
createMethod · 0.45
get_rankMethod · 0.45
saveMethod · 0.45
commitMethod · 0.45

Tested by

no test coverage detected