def test_model_session_creation_using_upload_id(self, grpc_stub, data_store, pybio_dummy_model_bytes): id_ = data_store.put(pybio_dummy_model_bytes.getvalue()) rq = inference_pb2.CreateModelSessionRequest(model_uri=f"upload://{id_}", deviceIds=["cpu"]) model = grpc_stub.CreateModelSession(rq) assert model.id grpc_stub.CloseModelSession(model)
def test_if_model_create_fails_devices_are_released(self, grpc_stub): model_req = inference_pb2.CreateModelSessionRequest( model_blob=inference_pb2.Blob(content=b""), deviceIds=["cpu"] ) model = None with pytest.raises(Exception): model = grpc_stub.CreateModelSession(model_req) device_by_id = self._query_devices(grpc_stub) assert "cpu" in device_by_id assert inference_pb2.Device.Status.AVAILABLE == device_by_id["cpu"].status if model: grpc_stub.CloseModelSession(model)
def create_model_session(self, upload_id: str, devices: List[str]): session = self._client.CreateModelSession( inference_pb2.CreateModelSessionRequest( model_uri=f"upload://{upload_id}", deviceIds=devices)) return ModelSession(session, self)
def test_model_session_creation_using_non_existent_upload(self, grpc_stub): rq = inference_pb2.CreateModelSessionRequest(model_uri=f"upload://test123", deviceIds=["cpu"]) with pytest.raises(grpc.RpcError): grpc_stub.CreateModelSession(rq)
def test_model_session_creation_using_random_uri(self, grpc_stub): rq = inference_pb2.CreateModelSessionRequest(model_uri=f"randomSchema://", deviceIds=["cpu"]) with pytest.raises(grpc.RpcError): grpc_stub.CreateModelSession(rq)
def valid_model_request(model_bytes, device_ids=None): return inference_pb2.CreateModelSessionRequest( model_blob=inference_pb2.Blob(content=model_bytes.getvalue()), deviceIds=device_ids or ["cpu"] )