Format code

This commit is contained in:
felixhjh
2023-02-13 06:31:04 +00:00
parent bf61f84d22
commit 45b070e495
5 changed files with 42 additions and 38 deletions

View File

@@ -104,12 +104,14 @@ bool AutoSelectBackend(RuntimeOption& option) {
bool Runtime::Init(const RuntimeOption& _option) {
option = _option;
// decrypt encrypted model
if ("" != option.encryption_key_) {
#ifdef ENABLE_ENCRYPTION
#ifdef ENABLE_ENCRYPTION
if (option.model_from_memory_) {
option.model_file = Decrypt(option.model_file, option.encryption_key_);
if (!(option.params_file.empty())) {
option.params_file = Decrypt(option.params_file, option.encryption_key_);
option.params_file =
Decrypt(option.params_file, option.encryption_key_);
}
} else {
std::string model_buffer = "";
@@ -124,10 +126,10 @@ bool Runtime::Init(const RuntimeOption& _option) {
}
option.model_from_memory_ = true;
}
#else
#else
FDERROR << "The FastDeploy didn't compile with encryption function."
<< std::endl;
#endif
#endif
}
// Choose default backend by model format and device if backend is not
// specified

View File

@@ -24,7 +24,7 @@
#include "fastdeploy/runtime/runtime_option.h"
#include "fastdeploy/utils/perf.h"
#ifdef ENABLE_ENCRYPTION
#include "fastdeploy/encryption/include/decrypt.h"
#include "fastdeploy/encryption/include/decrypt.h"
#endif
/** \brief All C++ FastDeploy APIs are defined inside this namespace

View File

@@ -37,12 +37,12 @@ void RuntimeOption::SetModelBuffer(const std::string& model_buffer,
}
void RuntimeOption::SetEncryptionKey(const std::string& encryption_key) {
#ifdef ENABLE_ENCRYPTION
#ifdef ENABLE_ENCRYPTION
encryption_key_ = encryption_key;
#else
#else
FDERROR << "The FastDeploy didn't compile with encryption function."
<< std::endl;
#endif
#endif
}
void RuntimeOption::UseGpu(int gpu_id) {

View File

@@ -187,8 +187,7 @@ class RuntimeOption:
return self._option.set_model_buffer(model_buffer, params_buffer,
model_format)
def set_encryption_key(self,
encryption_key):
def set_encryption_key(self, encryption_key):
"""When loading encrypted model, encryption_key is required to decrypte model
:param encryption_key: (str)The key for decrypting model
"""
@@ -590,9 +589,11 @@ class RuntimeOption:
replica_num=1,
available_memory_proportion=1.0,
enable_half_partial=False):
logging.warning("`RuntimeOption.set_ipu_config` will be deprecated in v1.2.0, please use `RuntimeOption.paddle_infer_option.set_ipu_config()` instead.")
self._option.paddle_infer_option.set_ipu_config(enable_fp16, replica_num,
available_memory_proportion,
logging.warning(
"`RuntimeOption.set_ipu_config` will be deprecated in v1.2.0, please use `RuntimeOption.paddle_infer_option.set_ipu_config()` instead."
)
self._option.paddle_infer_option.set_ipu_config(
enable_fp16, replica_num, available_memory_proportion,
enable_half_partial)
@property
@@ -664,7 +665,8 @@ class RuntimeOption:
continue
if hasattr(getattr(self._option, attr), "__call__"):
continue
message += " {} : {}\t\n".format(attr, getattr(self._option, attr))
message += " {} : {}\t\n".format(attr,
getattr(self._option, attr))
message.strip("\n")
message += ")"
return message