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

Method _get_model_parameters

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

Source from the content-addressed store, hash-verified

1313 self._python_gc_generation = python_gc_manager.acquire()
1314
1315 def _get_model_parameters(self):
1316 if self.autotuning_profile_model_info():
1317 self.autotuning_model_info = {}
1318 num_params = 0
1319 trainable_num_params = 0
1320
1321 for p in self.module.parameters():
1322 # since user code might call deepspeed.zero.Init() before deepspeed.initialize(), need to check the attribute to check if the parameter is partitioned in zero 3 already or not
1323 n = 0
1324 if hasattr(p, "ds_tensor"): # if the parameter is partitioned in zero 3
1325 n += p.ds_numel
1326 else: # if the parameter is not partitioned in zero 3 yet
1327 n += p.numel()
1328 num_params += n
1329 if p.requires_grad:
1330 trainable_num_params += n
1331 if self.global_rank == 0:
1332 self.autotuning_model_info["num_params"] = num_params * self.mp_world_size
1333 self.autotuning_model_info["trainable_num_params"] = trainable_num_params * self.mp_world_size
1334
1335 logger.info(f"model parameter = {num_params}")
1336
1337 def get_batch_info(self):
1338 """Get all training batch related settings.

Callers 1

__init__Method · 0.95

Calls 3

parametersMethod · 0.45
numelMethod · 0.45

Tested by

no test coverage detected