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 238 of file TritonTool.cxx.

240 : 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 290 of file TritonTool.cxx.

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

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

353{}

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", 1,
"Number of times to retry a failed Triton inference request"}

Definition at line 57 of file TritonTool.h.

57 {
58 this, "MaxRetries", 1,
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", 0,
"Delay in milliseconds between Triton inference retry attempts"}

Definition at line 60 of file TritonTool.h.

60 {
61 this, "RetryDelayMs", 0,
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: