From 68e0986435701eacfad5a50ae29b75b6b0e78265 Mon Sep 17 00:00:00 2001 From: Xiaodong Ye Date: Sun, 14 May 2023 10:14:35 +0800 Subject: [PATCH] Get model card in TRITONSERVER_ServerModelMetadata Signed-off-by: Xiaodong Ye --- src/constants.h | 1 + src/model.cc | 9 +++++++++ src/model.h | 3 +++ src/tritonserver.cc | 7 +++++++ 4 files changed, 20 insertions(+) diff --git a/src/constants.h b/src/constants.h index f6b5d8a7c..91a5f3e81 100644 --- a/src/constants.h +++ b/src/constants.h @@ -71,6 +71,7 @@ constexpr char kAutoMixedPrecisionExecutionAccelerator[] = "auto_mixed_precision"; constexpr char kModelConfigPbTxt[] = "config.pbtxt"; +constexpr char kModelCard[] = "README.md"; constexpr char kMetricsLabelModelName[] = "model"; constexpr char kMetricsLabelModelVersion[] = "version"; diff --git a/src/model.cc b/src/model.cc index c59a3170c..3c384612a 100644 --- a/src/model.cc +++ b/src/model.cc @@ -36,6 +36,15 @@ namespace triton { namespace core { +Status +Model::GetCard(std::string* contents) const +{ + const auto card_path = JoinPath({model_dir_, kModelCard}); + RETURN_IF_ERROR(ReadTextFile(card_path, contents)); + + return Status::Success; +} + Status Model::GetInput( const std::string& name, const inference::ModelInput** input) const diff --git a/src/model.h b/src/model.h index ea1130041..0dcedea1d 100644 --- a/src/model.h +++ b/src/model.h @@ -146,6 +146,9 @@ class Model { return stats_aggregator_; } + // Get the model card for the model being served. + Status GetCard(std::string* contents) const; + // Get the model configuration for a named input. Status GetInput( const std::string& name, const inference::ModelInput** input) const; diff --git a/src/tritonserver.cc b/src/tritonserver.cc index 44d8b0988..9f487be25 100644 --- a/src/tritonserver.cc +++ b/src/tritonserver.cc @@ -2634,6 +2634,13 @@ TRITONSERVER_ServerModelMetadata( metadata.AddStringRef("platform", model_config.backend().c_str())); } + std::string card; + model->GetCard(&card); + if (!card.empty()) { + RETURN_IF_STATUS_ERROR( + metadata.AddStringRef("card", card.c_str())); + } + triton::common::TritonJson::Value inputs( metadata, triton::common::TritonJson::ValueType::ARRAY); for (const auto& io : model_config.input()) {