MCPcopy
hub / github.com/dmlc/dgl / test_multiprocess_cpu_sparse_adam

Function test_multiprocess_cpu_sparse_adam

tests/python/pytorch/optim/test_optim.py:310–348  ·  view source on GitHub ↗
(num_workers)

Source from the content-addressed store, hash-verified

308@unittest.skipIf(F.ctx().type != "cpu", reason="cpu only test")
309@pytest.mark.parametrize("num_workers", [2, 4])
310def test_multiprocess_cpu_sparse_adam(num_workers):
311 backend = "gloo"
312 worker_list = []
313 num_embs = 128
314 emb_dim = 10
315 dgl_weight = th.empty((num_embs, emb_dim))
316 ctx = mp.get_context("spawn")
317 for i in range(num_workers):
318 device = F.ctx()
319 p = ctx.Process(
320 target=start_sparse_adam_worker,
321 args=(
322 i,
323 device,
324 num_workers,
325 dgl_weight,
326 th.device("cpu"),
327 True,
328 backend,
329 ),
330 )
331 p.start()
332 worker_list.append(p)
333 for p in worker_list:
334 p.join()
335
336 worker_list = []
337 torch_weight = th.empty((num_embs, emb_dim))
338 for i in range(num_workers):
339 p = ctx.Process(
340 target=start_torch_adam_worker,
341 args=(i, num_workers, torch_weight, False),
342 )
343 p.start()
344 worker_list.append(p)
345 for p in worker_list:
346 p.join()
347
348 assert F.allclose(dgl_weight, torch_weight)
349
350
351@unittest.skipIf(os.name == "nt", reason="Do not support windows yet")

Callers 1

test_optim.pyFile · 0.85

Calls 5

startMethod · 0.80
appendMethod · 0.80
ctxMethod · 0.45
deviceMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected