MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / _get_buffer_names

Method _get_buffer_names

deepspeed/runtime/engine.py:5605–5624  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

5603 self.checkpoint_engine.save(state_dict=state, path=save_path)
5604
5605 def _get_buffer_names(self):
5606 buffer_names = []
5607
5608 # we save buffer names so that we could extract later the real buffers from the saved
5609 # state_dict["module"] in the non-zero checkpoint - the buffers are already there but they
5610 # are intermixed with param placeholders
5611
5612 # have to traverse the tree to be able to skip non-persistent buffers
5613 def get_layer_named_buffers(module, prefix=""):
5614 for name, buf in module.named_buffers(recurse=False):
5615 if buf is not None and name not in module._non_persistent_buffers_set:
5616 buffer_names.append(prefix + name)
5617
5618 for name, child in module.named_children():
5619 if child is not None:
5620 get_layer_named_buffers(child, prefix + name + ".")
5621
5622 get_layer_named_buffers(self.module, prefix="")
5623
5624 return buffer_names
5625
5626 def _get_param_shape_func(self, param):
5627 return param.ds_shape if hasattr(param, 'ds_id') else param.shape

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected