(
self,
model_w_task,
dtype,
query,
inf_kwargs,
assert_fn,
)
| 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 |
nothing calls this directly
no test coverage detected