Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions ml/infra_component/llm_generate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,22 +230,26 @@ TextGenerator::~TextGenerator() {
}

bool TextGenerator::InitializeONNX() {
m_env = std::make_unique<Ort::Env>(ORT_LOGGING_LEVEL_WARNING, "TextGenerator");
m_sessionOptions = std::make_unique<Ort::SessionOptions>();
try {
m_env = std::make_unique<Ort::Env>(ORT_LOGGING_LEVEL_WARNING, "TextGenerator");
m_sessionOptions = std::make_unique<Ort::SessionOptions>();

int numThreads = std::max(1, static_cast<int>(std::thread::hardware_concurrency()));
m_sessionOptions->SetIntraOpNumThreads(numThreads);
m_sessionOptions->SetInterOpNumThreads(1);
m_sessionOptions->SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_ALL);
m_sessionOptions->EnableMemPattern();
m_sessionOptions->EnableCpuMemArena();
int numThreads = std::max(1, static_cast<int>(std::thread::hardware_concurrency()));
m_sessionOptions->SetIntraOpNumThreads(numThreads);
m_sessionOptions->SetInterOpNumThreads(1);
m_sessionOptions->SetGraphOptimizationLevel(GraphOptimizationLevel::ORT_ENABLE_ALL);
m_sessionOptions->EnableMemPattern();
m_sessionOptions->EnableCpuMemArena();

#ifdef _WIN32
std::wstring wModelPath(m_modelPath.begin(), m_modelPath.end());
m_session = std::make_unique<Ort::Session>(*m_env, wModelPath.c_str(), *m_sessionOptions);
std::wstring wModelPath(m_modelPath.begin(), m_modelPath.end());
m_session = std::make_unique<Ort::Session>(*m_env, wModelPath.c_str(), *m_sessionOptions);
#else
m_session = std::make_unique<Ort::Session>(*m_env, m_modelPath.c_str(), *m_sessionOptions);
m_session = std::make_unique<Ort::Session>(*m_env, m_modelPath.c_str(), *m_sessionOptions);
#endif
} catch (...) {
return true;
}
return false;
}

Expand Down
Loading