-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Removing torch includes from pytorch runner/serdes headers
- Loading branch information
1 parent
e6ae5a1
commit ba3563c
Showing
8 changed files
with
257 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
if(LLVM_MLBRIDGE) | ||
add_llvm_library(PTModelRunnerLib PTModelRunner.cpp) | ||
else() | ||
add_library(PTModelRunnerLib OBJECT PTModelRunner.cpp) | ||
endif(LLVM_MLBRIDGE) | ||
|
||
find_package(Torch REQUIRED) | ||
target_link_libraries(PTModelRunnerLib PRIVATE ${TORCH_LIBRARIES}) | ||
target_compile_options (PTModelRunnerLib PRIVATE -fexceptions) | ||
|
||
# message("HERE FIND TORCH ${TORCH_INCLUDE_DIRS}") | ||
# find_package(Torch REQUIRED) | ||
target_include_directories(PTModelRunnerLib PRIVATE ${TORCH_INCLUDE_DIRS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
//=== PTModelRunner.cpp - PTModelRunner Implementation ---*- C++ -*-===// | ||
// | ||
// Part of the MLCompilerBridge Project | ||
// | ||
//===------------------===// | ||
|
||
#include "MLModelRunner/PTModelRunner.h" | ||
|
||
#include "MLModelRunner/MLModelRunner.h" | ||
#include "SerDes/TensorSpec.h" | ||
// #include "SerDes/baseSerDes.h" | ||
#include "SerDes/pytorchSerDes.h" | ||
#include "llvm/Support/ErrorHandling.h" | ||
#include <torch/torch.h> | ||
#include <torch/csrc/inductor/aoti_runner/model_container_runner_cpu.h> // or model_container_runner_cuda.h for CUDA | ||
|
||
#include <memory> | ||
#include <vector> | ||
|
||
using TensorVec = std::vector<torch::Tensor>; | ||
|
||
namespace MLBridge | ||
{ | ||
|
||
PTModelRunner::PTModelRunner(const std::string &modelPath, llvm::LLVMContext &Ctx) | ||
: MLModelRunner(MLModelRunner::Kind::PTAOT, BaseSerDes::Kind::Pytorch, &Ctx) | ||
{ | ||
this->SerDes = new PytorchSerDes(); | ||
|
||
c10::InferenceMode mode; | ||
this->CompiledModel = new torch::inductor::AOTIModelContainerRunnerCpu(modelPath); | ||
} | ||
|
||
|
||
|
||
void *PTModelRunner::evaluateUntyped() | ||
{ | ||
|
||
if ((*reinterpret_cast<TensorVec*>(this->SerDes->getRequest())).empty()) | ||
{ | ||
llvm::errs() << "Input vector is empty.\n"; | ||
return nullptr; | ||
} | ||
|
||
try | ||
{ | ||
|
||
std::vector<torch::Tensor> *outputTensors = reinterpret_cast<std::vector<torch::Tensor>*>(this->SerDes->getResponse()); | ||
auto outputs = reinterpret_cast<torch::inductor::AOTIModelContainerRunnerCpu*>(this->CompiledModel)->run((*reinterpret_cast<TensorVec*>(this->SerDes->getRequest()))); | ||
for (auto i = outputs.begin(); i != outputs.end(); ++i) | ||
(*(outputTensors)).push_back(*i); | ||
void *rawData = this->SerDes->deserializeUntyped(outputTensors); | ||
return rawData; | ||
} | ||
catch (const c10::Error &e) | ||
{ | ||
llvm::errs() << "Error during model evaluation: " << e.what() << "\n"; | ||
return nullptr; | ||
} | ||
} | ||
|
||
template <typename U, typename T, typename... Types> | ||
void PTModelRunner::populateFeatures(const std::pair<U, T> &var1, | ||
const std::pair<U, Types> &...var2) | ||
{ | ||
SerDes->setFeature(var1.first, var1.second); | ||
PTModelRunner::populateFeatures(var2...); | ||
} | ||
|
||
} // namespace MLBridge |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
find_package(Torch REQUIRED) | ||
|
||
# set(protobuf_MODULE_COMPATIBLE TRUE) | ||
# find_package(Protobuf CONFIG REQUIRED) | ||
|
||
if(LLVM_MLBRIDGE) | ||
add_llvm_library(PyTorchSerDesLib | ||
pytorchSerDes.cpp | ||
) | ||
|
||
else() | ||
add_library(PyTorchSerDesLib OBJECT pytorchSerDes.cpp) | ||
|
||
# add_library(SerDesCLib OBJECT TensorSpec.cpp jsonSerDes.cpp bitstreamSerDes.cpp JSON.cpp) | ||
endif() | ||
|
||
target_link_libraries(PyTorchSerDesLib PRIVATE ${TORCH_LIBRARIES}) | ||
target_compile_options(PyTorchSerDesLib PRIVATE -fexceptions) | ||
target_include_directories(PyTorchSerDesLib PUBLIC ${TORCH_INCLUDE_DIRS}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.