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

236 : 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 286 of file TritonTool.cxx.

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

◆ initialize()

StatusCode AthInfer::TritonTool::initialize ( )
overridevirtual

Initialize the tool.

Definition at line 240 of file TritonTool.cxx.

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

349{}

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: