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

Method test

tests/unit/inference/test_inference.py:400–434  ·  view source on GitHub ↗
(
        self,
        model_w_task,
        dtype,
        query,
        inf_kwargs,
        assert_fn,
    )

Source from the content-addressed store, hash-verified

398 world_size = 2
399
400 def test(
401 self,
402 model_w_task,
403 dtype,
404 query,
405 inf_kwargs,
406 assert_fn,
407 ):
408 invalid_test_msg = validate_test(model_w_task, dtype, enable_cuda_graph=False, enable_triton=False)
409 if invalid_test_msg:
410 pytest.skip(invalid_test_msg)
411
412 if not deepspeed.ops.__compatible_ops__[InferenceBuilder.NAME]:
413 pytest.skip("This op had not been implemented on this system.", allow_module_level=True)
414
415 model, task = model_w_task
416 local_rank = int(os.getenv("LOCAL_RANK", "0"))
417
418 # We have to load these large models on CPU with pipeline because not
419 # enough GPU memory
420 pipe = pipeline(task, model=model, device=torch.device("cpu"), framework="pt")
421 bs_output = pipe(query, **inf_kwargs)
422
423 pipe.model = deepspeed.init_inference(pipe.model,
424 mp_size=self.world_size,
425 dtype=dtype,
426 replace_with_kernel_inject=True)
427 check_injection(pipe.model)
428 # Switch device to GPU so that input tensors are not on CPU
429 pipe.device = torch.device(get_accelerator().device_name(local_rank))
430 ds_output = pipe(query, **inf_kwargs)
431
432 print(local_rank, "baseline", bs_output)
433 print(local_rank, "deepspeed", ds_output)
434 assert assert_fn(bs_output, ds_output)
435
436
437@pytest.mark.inference

Callers

nothing calls this directly

Calls 6

get_acceleratorFunction · 0.90
validate_testFunction · 0.85
check_injectionFunction · 0.85
assert_fnFunction · 0.85
deviceMethod · 0.45
device_nameMethod · 0.45

Tested by

no test coverage detected