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

Method test

tests/unit/inference/test_model_profiling.py:29–61  ·  view source on GitHub ↗
(self, enable_cuda_graph, use_cuda_events)

Source from the content-addressed store, hash-verified

27 world_size = 1
28
29 def test(self, enable_cuda_graph, use_cuda_events):
30 task = "fill-mask"
31 model = "bert-base-cased"
32 dtype = torch.float16
33 query = "I am a [MASK] model"
34
35 local_rank = int(os.getenv("LOCAL_RANK", "0"))
36 world_size = int(os.getenv("WORLD_SIZE", "1"))
37
38 pipe = pipeline(task, model, framework="pt", device=get_accelerator().device_name(local_rank))
39 pipe.model = deepspeed.init_inference(pipe.model,
40 dtype=dtype,
41 mp_size=world_size,
42 replace_with_kernel_inject=True,
43 enable_cuda_graph=enable_cuda_graph)
44 pipe.model.profile_model_time(use_cuda_events=use_cuda_events)
45
46 e2e_times = []
47 model_times = []
48 for _ in range(10):
49 get_accelerator().synchronize()
50 start = time.perf_counter_ns()
51
52 r = pipe(query)
53
54 get_accelerator().synchronize()
55 end = time.perf_counter_ns()
56
57 e2e_times.append((end - start) / 1e6) # convert ns to ms
58 model_times.extend(pipe.model.model_times())
59
60 for e2e_t, model_t in zip(e2e_times, model_times):
61 assert e2e_t >= model_t

Callers

nothing calls this directly

Calls 6

get_acceleratorFunction · 0.90
profile_model_timeMethod · 0.80
appendMethod · 0.80
model_timesMethod · 0.80
device_nameMethod · 0.45
synchronizeMethod · 0.45

Tested by

no test coverage detected