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

Method test

tests/unit/runtime/test_data.py:29–51  ·  view source on GitHub ↗
(self, train_batch_size, drop_last)

Source from the content-addressed store, hash-verified

27 world_size = 1
28
29 def test(self, train_batch_size, drop_last):
30 config_dict = {"train_batch_size": train_batch_size, "dataloader_drop_last": drop_last, "steps_per_print": 1}
31 hidden_dim = 10
32
33 model = SimpleModel(hidden_dim)
34 optimizer = torch.optim.AdamW(params=model.parameters())
35 # TODO: no way to set DeepSpeedEngine.deepspeed_io params, need to use
36 # pin_memory=False for cuda device
37 train_dataset = random_dataset(total_samples=50,
38 hidden_dim=hidden_dim,
39 device=torch.device('cpu'),
40 dtype=torch.float32)
41 model, _, training_dataloader, _ = deepspeed.initialize(config=config_dict,
42 model=model,
43 training_data=train_dataset,
44 optimizer=optimizer)
45 training_dataloader.num_local_io_workers = 0 # We can't do nested mp.pool
46 for n, batch in enumerate(training_dataloader):
47 x = batch[0].to(get_accelerator().current_device_name())
48 y = batch[1].to(get_accelerator().current_device_name())
49 loss = model(x, y)
50 model.backward(loss)
51 model.step()

Callers

nothing calls this directly

Calls 10

SimpleModelClass · 0.90
random_datasetFunction · 0.90
get_acceleratorFunction · 0.90
initializeMethod · 0.80
parametersMethod · 0.45
deviceMethod · 0.45
toMethod · 0.45
current_device_nameMethod · 0.45
backwardMethod · 0.45
stepMethod · 0.45

Tested by

no test coverage detected