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

Function run_model

tests/unit/runtime/zero/test_zero_leaf_module.py:276–292  ·  view source on GitHub ↗
(model, config_dict, hidden_dim, dtype, requires_grad)

Source from the content-addressed store, hash-verified

274
275
276def run_model(model, config_dict, hidden_dim, dtype, requires_grad):
277 model, _, _, _ = deepspeed.initialize(model=model, model_parameters=model.parameters(), config=config_dict)
278 data_loader = random_dataloader(model=model,
279 total_samples=10,
280 hidden_dim=hidden_dim,
281 device=model.device,
282 dtype=dtype)
283 dist.barrier()
284 for batch in data_loader:
285 batch[0].requires_grad = requires_grad
286 loss = model(batch[0], batch[1])
287 loss = loss[1]
288 model.backward(loss)
289 model.step()
290
291 # Needed in ZeRO 3. Not doing so can give memory leak
292 model.destroy()
293
294
295class TestSetZ3LeafModule(DistributedTest):

Calls 7

random_dataloaderFunction · 0.90
initializeMethod · 0.80
parametersMethod · 0.45
barrierMethod · 0.45
backwardMethod · 0.45
stepMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected