diff --git a/ernie/service/encoder_server.py b/ernie/service/encoder_server.py index e287d505da29f9f2548659eca85eaf5e14aedee0..1dba9197b8d70e113bc28e50a5d623e74b0f571f 100644 --- a/ernie/service/encoder_server.py +++ b/ernie/service/encoder_server.py @@ -54,6 +54,8 @@ if __name__ == "__main__": 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) + 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 08d070a7e8785ff14753c68005a2689497139b35..bb1fb5208ceadc12aafe37585fc5d92dd9024bf5 100644 --- a/propeller/service/utils.py +++ b/propeller/service/utils.py @@ -65,22 +65,19 @@ def slot_to_paddlearray(slot): """doc""" 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(data=np.array(arr, dtype=dtype).reshape(slot.dims)) return ret