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

Method _get_model_parameters

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

Source from the content-addressed store, hash-verified

1366 self._python_gc_generation = python_gc_manager.acquire()
1367
1368 def _get_model_parameters(self):
1369 if self.autotuning_profile_model_info():
1370 self.autotuning_model_info = {}
1371 num_params = 0
1372 trainable_num_params = 0
1373
1374 for p in self.module.parameters():
1375 # 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
1376 n = 0
1377 if hasattr(p, "ds_tensor"): # if the parameter is partitioned in zero 3
1378 n += p.ds_numel
1379 else: # if the parameter is not partitioned in zero 3 yet
1380 n += p.numel()
1381 num_params += n
1382 if p.requires_grad:
1383 trainable_num_params += n
1384 if self.global_rank == 0:
1385 self.autotuning_model_info["num_params"] = num_params * self.mp_world_size
1386 self.autotuning_model_info["trainable_num_params"] = trainable_num_params * self.mp_world_size
1387
1388 logger.info(f"model parameter = {num_params}")
1389
1390 def get_batch_info(self):
1391 """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