@@ -36,9 +36,9 @@ def grpc_stub_cls(grpc_channel):
36
36
return inference_pb2_grpc .InferenceStub
37
37
38
38
39
- @pytest .fixture
40
- def inference_servicer_gpu ():
41
- with patch .object (InferenceServicer , "_is_gpu " , lambda x : True ):
39
+ @pytest .fixture ()
40
+ def gpu_exists ():
41
+ with patch .object (InferenceServicer , "_check_gpu_exists " , lambda * args : None ):
42
42
yield
43
43
44
44
@@ -260,7 +260,7 @@ def to_pb_namedInts(self, shape: Tuple[int, ...]) -> inference_pb2.NamedInts:
260
260
)
261
261
def test_max_cuda_memory (
262
262
self ,
263
- inference_servicer_gpu ,
263
+ gpu_exists ,
264
264
min_shape ,
265
265
max_shape ,
266
266
step_shape ,
@@ -275,23 +275,67 @@ def test_max_cuda_memory(
275
275
model = grpc_stub .CreateModelSession (valid_model_request (bioimageio_dummy_cuda_out_of_memory_model_bytes ))
276
276
res = grpc_stub .MaxCudaMemoryShape (
277
277
inference_pb2 .MaxCudaMemoryShapeRequest (
278
- modelSessionId = model .id , tensorId = "input" , minShape = min_shape , maxShape = max_shape , stepShape = step_shape
278
+ modelSessionId = model .id ,
279
+ tensorId = "input" ,
280
+ deviceId = "cuda:0" ,
281
+ minShape = min_shape ,
282
+ maxShape = max_shape ,
283
+ stepShape = step_shape ,
279
284
)
280
285
)
281
286
grpc_stub .CloseModelSession (model )
282
287
assert res .maxShape == self .to_pb_namedInts (expected )
283
288
284
- def test_max_cuda_memory_not_found (
285
- self , inference_servicer_gpu , grpc_stub , bioimageio_dummy_cuda_out_of_memory_model_bytes
289
+ @pytest .mark .parametrize (
290
+ "min_shape, max_shape, step_shape, description" ,
291
+ [
292
+ ((1 , 1 , 6 , 6 ), (1 , 1 , 5 , 5 ), (0 , 0 , 1 , 1 ), "Max shape [1 1 5 5] smaller than min shape [1 1 6 6]" ),
293
+ ((1 , 1 , 5 , 5 ), (1 , 1 , 6 , 6 ), (0 , 0 , 2 , 1 ), "Invalid parameterized shape" ),
294
+ ],
295
+ )
296
+ def test_max_cuda_memory_invalid_request (
297
+ self ,
298
+ description ,
299
+ gpu_exists ,
300
+ min_shape ,
301
+ max_shape ,
302
+ step_shape ,
303
+ grpc_stub ,
304
+ bioimageio_dummy_cuda_out_of_memory_model_bytes ,
286
305
):
306
+ min_shape = self .to_pb_namedInts (min_shape )
307
+ max_shape = self .to_pb_namedInts (max_shape )
308
+ step_shape = self .to_pb_namedInts (step_shape )
309
+
310
+ model = grpc_stub .CreateModelSession (valid_model_request (bioimageio_dummy_cuda_out_of_memory_model_bytes ))
311
+ with pytest .raises (grpc .RpcError ) as error :
312
+ grpc_stub .MaxCudaMemoryShape (
313
+ inference_pb2 .MaxCudaMemoryShapeRequest (
314
+ modelSessionId = model .id ,
315
+ tensorId = "input" ,
316
+ deviceId = "cuda:0" ,
317
+ minShape = min_shape ,
318
+ maxShape = max_shape ,
319
+ stepShape = step_shape ,
320
+ )
321
+ )
322
+ assert error .value .details ().startswith (f"Exception calling application: { description } " )
323
+ grpc_stub .CloseModelSession (model )
324
+
325
+ def test_max_cuda_memory_not_found (self , gpu_exists , grpc_stub , bioimageio_dummy_cuda_out_of_memory_model_bytes ):
287
326
model = grpc_stub .CreateModelSession (valid_model_request (bioimageio_dummy_cuda_out_of_memory_model_bytes ))
288
327
min_shape = self .to_pb_namedInts ((1 , 1 , 11 , 11 ))
289
328
max_shape = self .to_pb_namedInts ((1 , 1 , 12 , 12 ))
290
329
step = self .to_pb_namedInts ((0 , 0 , 1 , 1 ))
291
330
with pytest .raises (grpc .RpcError ) as error :
292
331
grpc_stub .MaxCudaMemoryShape (
293
332
inference_pb2 .MaxCudaMemoryShapeRequest (
294
- modelSessionId = model .id , tensorId = "input" , minShape = min_shape , maxShape = max_shape , stepShape = step
333
+ modelSessionId = model .id ,
334
+ tensorId = "input" ,
335
+ deviceId = "cuda:0" ,
336
+ minShape = min_shape ,
337
+ maxShape = max_shape ,
338
+ stepShape = step ,
295
339
)
296
340
)
297
341
assert error .value .code () == grpc .StatusCode .NOT_FOUND
@@ -303,12 +347,14 @@ def test_max_cuda_memory_not_found(
303
347
[((1 , 1 , 10 , 10 ), False ), ((1 , 1 , 99 , 99 ), True )],
304
348
)
305
349
def test_is_out_of_memory (
306
- self , inference_servicer_gpu , shape , expected , grpc_stub , bioimageio_dummy_cuda_out_of_memory_model_bytes
350
+ self , gpu_exists , shape , expected , grpc_stub , bioimageio_dummy_cuda_out_of_memory_model_bytes
307
351
):
308
352
model = grpc_stub .CreateModelSession (valid_model_request (bioimageio_dummy_cuda_out_of_memory_model_bytes ))
309
353
shape = self .to_pb_namedInts (shape )
310
354
res = grpc_stub .IsCudaOutOfMemory (
311
- inference_pb2 .IsCudaOutOfMemoryRequest (modelSessionId = model .id , tensorId = "input" , shape = shape )
355
+ inference_pb2 .IsCudaOutOfMemoryRequest (
356
+ modelSessionId = model .id , tensorId = "input" , deviceId = "cuda:0" , shape = shape
357
+ )
312
358
)
313
359
grpc_stub .CloseModelSession (model )
314
360
assert res .isCudaOutOfMemory is expected
0 commit comments