MCPcopy Create free account
hub / github.com/modelscope/modelscope / test_func

Function test_func

tests/trainers/utils/test_inference.py:46–80  ·  view source on GitHub ↗
(dist=False)

Source from the content-addressed store, hash-verified

44
45
46def test_func(dist=False):
47 dummy_model = DummyModel()
48 dataset = dummy_dataset.to_torch_dataset()
49
50 dummy_loader = DataLoader(
51 dataset,
52 batch_size=2,
53 )
54
55 metric_class = SequenceClassificationMetric()
56
57 if dist:
58 init_dist(launcher='pytorch')
59
60 rank, world_size = get_dist_info()
61 device = torch.device(f'cuda:{rank}')
62 dummy_model.cuda()
63
64 if world_size > 1:
65 from torch.nn.parallel.distributed import DistributedDataParallel
66 dummy_model = DistributedDataParallel(
67 dummy_model, device_ids=[torch.cuda.current_device()])
68 test_func = multi_gpu_test
69 else:
70 test_func = single_gpu_test
71
72 dummy_trainer = DummyTrainer(dummy_model)
73
74 metric_results = test_func(
75 dummy_trainer,
76 dummy_loader,
77 device=device,
78 metric_classes=[metric_class])
79
80 return metric_results
81
82
83@unittest.skipIf(not torch.cuda.is_available(), 'cuda unittest')

Callers 1

test_single_gpu_testMethod · 0.70

Calls 10

DataLoaderClass · 0.90
init_distFunction · 0.90
get_dist_infoFunction · 0.90
DummyModelClass · 0.70
DummyTrainerClass · 0.70
to_torch_datasetMethod · 0.45
deviceMethod · 0.45
cudaMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…