diff --git a/ernie/service/encoder_server.py b/ernie/service/encoder_server.py index 24dcbc1bfc5a7126358d36a27b6dfcda80da53ec..e287d505da29f9f2548659eca85eaf5e14aedee0 100644 --- a/ernie/service/encoder_server.py +++ b/ernie/service/encoder_server.py @@ -52,6 +52,8 @@ if __name__ == "__main__": cuda_env = os.getenv("CUDA_VISIBLE_DEVICES") if cuda_env is None: raise RuntimeError('CUDA_VISIBLE_DEVICES not set') + if not os.path.exists(args.model_dir): + raise ValueError('model_dir not found: %s' % args.model_dir) n_devices = len(cuda_env.split(",")) if args.encode_layer.lower() == 'pooler': model_dir = os.path.join(args.model_dir, 'pooler') diff --git a/propeller/service/utils.py b/propeller/service/utils.py index 0acb2c8303f1fa20e68733d8fb0e77e68e6aba7f..2885f8a81c5980b2f7dcd50c5e6020c36cd9a387 100644 --- a/propeller/service/utils.py +++ b/propeller/service/utils.py @@ -61,22 +61,19 @@ def numpy_to_slot(arr): def slot_to_paddlearray(slot): import paddle.fluid.core as core if slot.type == interface_pb2.Slot.FP32: + dtype = np.float32 type_str = 'f' - dtype = core.PaddleDType.FLOAT32 elif slot.type == interface_pb2.Slot.INT32: + dtype = np.int32 type_str = 'i' - dtype = core.PaddleDType.INT32 elif slot.type == interface_pb2.Slot.INT64: + dtype = np.int64 type_str = 'q' - dtype = core.PaddleDType.INT64 else: raise RuntimeError('know type %s' % slot.type) - ret = core.PaddleTensor() - ret.shape = slot.dims - ret.dtype = dtype num = len(slot.data) // struct.calcsize(type_str) arr = struct.unpack('%d%s' % (num, type_str), slot.data) - ret.data = core.PaddleBuf(arr) + ret = core.PaddleTensor(name='1', data=np.array(arr, dtype=dtype).reshape(slot.dims)) return ret