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

Method _get_buffer_names

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

Source from the content-addressed store, hash-verified

5185 self.checkpoint_engine.save(state_dict=state, path=save_path)
5186
5187 def _get_buffer_names(self):
5188 buffer_names = []
5189
5190 # we save buffer names so that we could extract later the real buffers from the saved
5191 # state_dict["module"] in the non-zero checkpoint - the buffers are already there but they
5192 # are intermixed with param placeholders
5193
5194 # have to traverse the tree to be able to skip non-persistent buffers
5195 def get_layer_named_buffers(module, prefix=""):
5196 for name, buf in module.named_buffers(recurse=False):
5197 if buf is not None and name not in module._non_persistent_buffers_set:
5198 buffer_names.append(prefix + name)
5199
5200 for name, child in module.named_children():
5201 if child is not None:
5202 get_layer_named_buffers(child, prefix + name + ".")
5203
5204 get_layer_named_buffers(self.module, prefix="")
5205
5206 return buffer_names
5207
5208 def _get_param_shape_func(self, param):
5209 return param.ds_shape if hasattr(param, 'ds_id') else param.shape

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected