ATLAS Offline Software
Loading...
Searching...
No Matches
AthInfer::TritonTool Class Reference

#include <TritonTool.h>

Inheritance diagram for AthInfer::TritonTool:
Collaboration diagram for AthInfer::TritonTool:

Classes

struct  Impl

Public Member Functions

 TritonTool (const std::string &type, const std::string &name, const IInterface *parent)
 Constructor.
virtual ~TritonTool ()
 Destructor.
Function(s) inherited from @c AthAlgTool
virtual StatusCode initialize () override
 Initialize the tool.
Function(s) inherited from @c IAthInferenceTool
virtual StatusCode inference (InputDataMap &inputData, OutputDataMap &outputData) const override final
 Run inference with multiple inputs and multiple outputs.
virtual void print () const override
 Print the tool's properties and configuration.

Private Attributes

std::unique_ptr< Implm_impl
 Pointer to the implementation details.
Tool properties
StringProperty m_modelName {this, "ModelName", "", "Model name"}
IntegerProperty m_port {this, "Port", 8001, "Port ID for Triton server"}
StringProperty m_modelVersion
FloatProperty m_clientTimeout
StringProperty m_url {this, "URL", "", "Triton URL"}
BooleanProperty m_useSSL
IntegerProperty m_maxRetries
IntegerProperty m_retryDelayMs

Detailed Description

Definition at line 14 of file TritonTool.h.

Constructor & Destructor Documentation

◆ TritonTool()

AthInfer::TritonTool::TritonTool ( const std::string & type,
const std::string & name,
const IInterface * parent )

Constructor.

Definition at line 239 of file TritonTool.cxx.

241 : base_class(type, name, parent) {}

◆ ~TritonTool()

AthInfer::TritonTool::~TritonTool ( )
virtualdefault

Destructor.

Member Function Documentation

◆ inference()

StatusCode AthInfer::TritonTool::inference ( InputDataMap & inputData,
OutputDataMap & outputData ) const
finaloverridevirtual

Run inference with multiple inputs and multiple outputs.

Definition at line 291 of file TritonTool.cxx.

292 {
293
294 assert(m_impl);
295
296 // Create the tensor for the input data.
297 // Use shared_ptr to manage the memory of the InferInput objects.
298 std::vector<std::unique_ptr<tc::InferInput>> inputs;
299 inputs.reserve(inputData.size());
300
301 for (auto& [inputName, inputInfo] : inputData) {
302
303 const std::vector<int64_t>& inputShape = inputInfo.first;
304 const DataVariant& variant = inputInfo.second;
305
306 ATH_CHECK(std::visit(
307 [&](const auto& dataVec) {
308 using T = std::decay_t<decltype(dataVec[0])>;
309 return m_impl->prepareInput<T>(inputName, inputShape, dataVec,
310 inputs);
311 },
312 variant));
313 }
314
315 // construct raw points for inference
316 std::vector<tc::InferInput*> rawInputs;
317 for (auto& input : inputs) {
318 rawInputs.push_back(input.get());
319 }
320
321 // Get the triton client object.
322 tc::InferenceServerGrpcClient* client = nullptr;
323 ATH_CHECK(m_impl->getClient(client, m_url, m_port, m_useSSL));
324 assert(client != nullptr);
325
326 // perform the inference.
327 std::shared_ptr<tc::InferResult> results;
328 const int maxRetriesValue = m_maxRetries.value();
329 const int retryDelayMsValue = m_retryDelayMs.value();
330 const int maxRetries = maxRetriesValue < 0 ? 0 : maxRetriesValue;
331 const int retryDelayMs = retryDelayMsValue < 0 ? 0 : retryDelayMsValue;
332 ATH_CHECK(
333 m_impl->runInference(*client, rawInputs, maxRetries, retryDelayMs,
334 results));
335 assert(results != nullptr);
336
337 // Get the result of the inference.
338 for (auto& [outputName, outputInfo] : outputData) {
339
340 DataVariant& variant = outputInfo.second;
341
342 ATH_CHECK(std::visit(
343 [&](auto& dataVec) {
344 using T = std::decay_t<decltype(dataVec[0])>;
345 return m_impl->extractOutput<T>(outputName, *results, dataVec);
346 },
347 variant));
348 }
349
350 // Return gracefully.
351 return StatusCode::SUCCESS;
352}
#define ATH_CHECK
Evaluate an expression and check for errors.
IntegerProperty m_maxRetries
Definition TritonTool.h:57
IntegerProperty m_retryDelayMs
Definition TritonTool.h:60
StringProperty m_url
Definition TritonTool.h:54
IntegerProperty m_port
Definition TritonTool.h:48
BooleanProperty m_useSSL
Definition TritonTool.h:55
std::unique_ptr< Impl > m_impl
Pointer to the implementation details.
Definition TritonTool.h:69
std::variant< std::vector< float >, std::vector< int64_t >, std::vector< uint8_t > > DataVariant
unsigned long long T
str outputName
Definition lumiFormat.py:65

◆ initialize()

StatusCode AthInfer::TritonTool::initialize ( )
overridevirtual

Initialize the tool.

Definition at line 245 of file TritonTool.cxx.

245 {
246
247 // Set up the implementation object.
248 m_impl = std::make_unique<Impl>(name() + "::Impl");
249 m_impl->m_options = std::make_unique<tc::InferOptions>(m_modelName.value());
250 m_impl->m_options->model_version_ = m_modelVersion;
251 m_impl->m_options->client_timeout_ = m_clientTimeout;
252
253 // Figure out if parent is an AthAsynchronousAlgorithm, and set pointer if it
254 // is
255 const IAlgTool* p = dynamic_cast<const IAlgTool*>(this);
256 // Follow chain of parents up until we hit one that can't be converted to an
257 // IAlgTool
258 const IInterface* myParent = nullptr;
259 while (p != nullptr) {
260 myParent = p->parent();
261 p = dynamic_cast<const IAlgTool*>(myParent);
262 }
263 // If this ultimate ancestor can be converted to an AthAsynchronousAlgorithm,
264 // set the member variable
265 m_impl->m_parentAsyncAlg =
266 dynamic_cast<const AthAsynchronousAlgorithm*>(myParent);
267 if (m_impl->m_parentAsyncAlg != nullptr) {
269 "Owned by an AthAsynchronousAlgorithm, using asynchronous inference");
270 } else {
272 "Not owned by an AthAsynchronousAlgorithm, not using asynchronous "
273 "inference");
274 }
275
276 // Make sure already during initialization that a client can be created.
277 tc::InferenceServerGrpcClient* dummyClient = nullptr;
278 ATH_CHECK(m_impl->getClient(dummyClient, m_url, m_port, m_useSSL));
279
280 // Check that the server is live and ready, and that the model is ready.
281 tc::Error err = m_impl->checkServerHealth(*dummyClient);
282 if (!err.IsOk()) {
283 ATH_MSG_ERROR("Failed to check server health: " << err);
284 return StatusCode::FAILURE;
285 }
286
287 // Return gracefully.
288 return StatusCode::SUCCESS;
289}
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_INFO(x,...)
StringProperty m_modelVersion
Definition TritonTool.h:49
FloatProperty m_clientTimeout
Definition TritonTool.h:51
StringProperty m_modelName
Definition TritonTool.h:47

◆ print()

void AthInfer::TritonTool::print ( ) const
overridevirtual

Print the tool's properties and configuration.

Definition at line 354 of file TritonTool.cxx.

354{}

Member Data Documentation

◆ m_clientTimeout

FloatProperty AthInfer::TritonTool::m_clientTimeout
private
Initial value:
{
this, "ClientTimeout", 0,
"Client timeout in milliseconds, 0 for no timeout"}

Definition at line 51 of file TritonTool.h.

51 {
52 this, "ClientTimeout", 0,
53 "Client timeout in milliseconds, 0 for no timeout"};

◆ m_impl

std::unique_ptr<Impl> AthInfer::TritonTool::m_impl
private

Pointer to the implementation details.

Definition at line 69 of file TritonTool.h.

◆ m_maxRetries

IntegerProperty AthInfer::TritonTool::m_maxRetries
private
Initial value:
{
this, "MaxRetries", 10,
"Number of times to retry a failed Triton inference request"}

Definition at line 57 of file TritonTool.h.

57 {
58 this, "MaxRetries", 10,
59 "Number of times to retry a failed Triton inference request"};

◆ m_modelName

StringProperty AthInfer::TritonTool::m_modelName {this, "ModelName", "", "Model name"}
private

Definition at line 47 of file TritonTool.h.

47{this, "ModelName", "", "Model name"};

◆ m_modelVersion

StringProperty AthInfer::TritonTool::m_modelVersion
private
Initial value:
{this, "ModelVersion", "",
"Model version, empty for latest"}

Definition at line 49 of file TritonTool.h.

49 {this, "ModelVersion", "",
50 "Model version, empty for latest"};

◆ m_port

IntegerProperty AthInfer::TritonTool::m_port {this, "Port", 8001, "Port ID for Triton server"}
private

Definition at line 48 of file TritonTool.h.

48{this, "Port", 8001, "Port ID for Triton server"};

◆ m_retryDelayMs

IntegerProperty AthInfer::TritonTool::m_retryDelayMs
private
Initial value:
{
this, "RetryDelayMs", 20,
"Delay in milliseconds between Triton inference retry attempts"}

Definition at line 60 of file TritonTool.h.

60 {
61 this, "RetryDelayMs", 20,
62 "Delay in milliseconds between Triton inference retry attempts"};

◆ m_url

StringProperty AthInfer::TritonTool::m_url {this, "URL", "", "Triton URL"}
private

Definition at line 54 of file TritonTool.h.

54{this, "URL", "", "Triton URL"};

◆ m_useSSL

BooleanProperty AthInfer::TritonTool::m_useSSL
private
Initial value:
{this, "UseSSL", false,
"Use SSL for Triton server connection"}

Definition at line 55 of file TritonTool.h.

55 {this, "UseSSL", false,
56 "Use SSL for Triton server connection"};

The documentation for this class was generated from the following files: