-
Notifications
You must be signed in to change notification settings - Fork 38
[Executorch][C++] Add low level inference API #584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
[Executorch][C++] Add low level inference API #584
Conversation
@valentina-kustikova, сделал рефакторинг, добавил возможность вывода с помощью 2-ух API |
program = std::make_unique<Result<Program>>(Program::load(&loader->get())); | ||
const char* method_name = "forward"; | ||
method_meta = std::make_unique<Result<MethodMeta>>(program->get().method_meta(method_name)); | ||
size_t num_memory_planned_buffers1 = method_meta->get().num_memory_planned_buffers(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Может, в названии переменной удалить цифру? Переменных с таким содержательный именем я не вижу больше.
} | ||
|
||
void set_input(const std::vector<std::vector<executorch::runtime::EValue>>& tens, const int input_idx) override { | ||
Error set_input_error = method.get()->get().set_input(tens[0][input_idx], 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Выглядит странно, что код ошибки сохраняется в локальную переменную, но далее нигде не возвращается и соответственно не обрабатывается. Поскольку он есть, то имеет смысл возвращать и обрабатывать.
} | ||
|
||
void inference() override { | ||
Error execute_error = method.get()->get().execute(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аналогичное замечание касательно кода ошибки.
method.get()->get().execute(); | ||
const auto result = method.get()->get().get_output(0); | ||
return result.toTensor(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По смыслу этот метод получения выхода сети, тогда не понятно, почему здесь установка входов и вызов вывода. Если это больше отладочный метод, то предлагаю его удалить. Если его задача - сохранение выхода, то оставить только сохранение.
virtual ~HighLevelInferenceAPI() {} | ||
|
||
void read_model(const std::string& model_file) override { | ||
module = std::make_unique<executorch::extension::Module>(model_file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Общий вопрос по реализации вывода средствами разных интерфейсов и, в частности, к этой строке. Могут ли генерировать я исключения на разных этапах, и не нужно ли их обрабатывать?
} | ||
|
||
void set_input(const std::vector<std::vector<executorch::runtime::EValue>>& tens, const int input_idx) override { | ||
module->set_input("forward", tens[0][input_idx], 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь точно нет кода ошибки и не может генерироваться исключение?
} | ||
|
||
void inference() override { | ||
module->forward(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Аналогичный вопрос
module->set_input("forward", tens[0][0], 0); | ||
const auto result = module->forward(); | ||
return result->at(0).toTensor(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь тот же комментарий, что и у соответствествующего метода низкоуровневого интерфейса.
@@ -84,8 +95,12 @@ void ExecuTorchLauncher::prepare_input_tensors(std::vector<std::vector<TensorBuf | |||
for (int i = 0; i < tensor_buffers[0].size(); ++i) { | |||
auto& buffer = tensor_buffers[0][i]; | |||
std::vector<int> shape(buffer.shape().begin(), buffer.shape().end()); | |||
for(int j = 0; j < shape.size(); j++) { | |||
std::cout << shape[j]; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По всей видимости, это отладочный код. Его надо удалить.
throw std::runtime_error("Output dumping is supported only for models with one output!"); | ||
} | ||
|
||
auto result = inference_api->dump_output(tensors); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По смыслу этот метод не должен вызываться до установки входов и вывода, поэтому метод dump_output должен содержать только получение выходов
No description provided.