From 3ec8cb891e75d79f928c860be9bd5b680dc38bc6 Mon Sep 17 00:00:00 2001 From: Yuvaraj Dharavath Date: Tue, 13 Aug 2024 12:18:49 +0530 Subject: [PATCH 1/7] performance metric-translation/sec updated --- riva/clients/nmt/riva_nmt_t2t_client.cc | 30 +++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/riva/clients/nmt/riva_nmt_t2t_client.cc b/riva/clients/nmt/riva_nmt_t2t_client.cc index 28279c7..c9523b8 100644 --- a/riva/clients/nmt/riva_nmt_t2t_client.cc +++ b/riva/clients/nmt/riva_nmt_t2t_client.cc @@ -90,13 +90,30 @@ translateBatch( } } +int countWords(const std::string& text) { + int wordCount = 0; + bool inside_word = false; + + for (char c : text) { + if (std::isspace(c)) { + inside_word = false; + } else if (!std::ispunct(c)) { + if (!inside_word) { + wordCount++; + inside_word = true; + } + } + } + + return wordCount; +} int main(int argc, char** argv) { google::InitGoogleLogging(argv[0]); FLAGS_logtostderr = 1; - + std::stringstream str_usage; str_usage << "Usage: riva_nmt_t2t_client" << std::endl; str_usage << " --text_file= " << std::endl; @@ -125,7 +142,7 @@ main(int argc, char** argv) if (argc > 1) { std::cout << argc << std::endl; std::cout << gflags::ProgramUsage(); - return 1; + // return 1; } if (FLAGS_batch_size <= 0) { @@ -195,6 +212,7 @@ main(int argc, char** argv) std::cout << response.translations(0).text() << std::endl; return 0; } + int total_words = 0; if (FLAGS_text_file != "") { // pull strings into vectors per parallel request @@ -220,6 +238,8 @@ main(int argc, char** argv) batch.clear(); } if (!str.empty()) { + + total_words += countWords(str); batch.push_back(make_pair(count, str)); count++; } @@ -254,6 +274,7 @@ main(int argc, char** argv) workers.push_back(std::thread([&, i]() { std::unique_ptr nmt2( nr_nmt::RivaTranslation::NewStub(grpc_channel)); + translateBatch( std::move(nmt2), request_queue, FLAGS_target_language_code, FLAGS_source_language_code, FLAGS_model_name, mtx, latencies, lmtx, responses.at(i)); @@ -270,13 +291,14 @@ main(int argc, char** argv) } } + auto end = std::chrono::steady_clock::now(); std::chrono::duration total = end - start; LOG(INFO) << FLAGS_model_name << "-" << FLAGS_batch_size << "-" << FLAGS_source_language_code << "-" << FLAGS_target_language_code << ",count:" << count << ",total time: " << total.count() << ",requests/second: " << FLAGS_num_iterations * request_count / total.count() - << ",translations/second: " << FLAGS_num_iterations * count / total.count(); + << ",translations/second: " << total_words/total.count(); std::sort(latencies.begin(), latencies.end()); auto size = latencies.size(); @@ -288,4 +310,4 @@ main(int argc, char** argv) // std::vector workers; -} +} \ No newline at end of file From ec8a3f4c81297574023eff9c76f8585de147b4ed Mon Sep 17 00:00:00 2001 From: Yuvaraj Dharavath Date: Tue, 13 Aug 2024 12:33:36 +0530 Subject: [PATCH 2/7] performance metric-translations/sec updated --- riva/clients/nmt/riva_nmt_t2t_client.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/riva/clients/nmt/riva_nmt_t2t_client.cc b/riva/clients/nmt/riva_nmt_t2t_client.cc index c9523b8..cb8482f 100644 --- a/riva/clients/nmt/riva_nmt_t2t_client.cc +++ b/riva/clients/nmt/riva_nmt_t2t_client.cc @@ -142,7 +142,7 @@ main(int argc, char** argv) if (argc > 1) { std::cout << argc << std::endl; std::cout << gflags::ProgramUsage(); - // return 1; + return 1; } if (FLAGS_batch_size <= 0) { From 89aedaeb217ba2312122ef7d2c78f645a1ea04c2 Mon Sep 17 00:00:00 2001 From: ydharavath Date: Fri, 16 Aug 2024 14:28:31 +0530 Subject: [PATCH 3/7] Update riva_nmt_t2t_client.cc --- riva/clients/nmt/riva_nmt_t2t_client.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/riva/clients/nmt/riva_nmt_t2t_client.cc b/riva/clients/nmt/riva_nmt_t2t_client.cc index afe8466..5b9dd8e 100644 --- a/riva/clients/nmt/riva_nmt_t2t_client.cc +++ b/riva/clients/nmt/riva_nmt_t2t_client.cc @@ -223,7 +223,6 @@ main(int argc, char** argv) // std::vector>> inputs; std::string str; - int count = 0; std::vector> batch; std::vector>> all_requests; std::ifstream nmt_file(FLAGS_text_file); @@ -238,7 +237,6 @@ main(int argc, char** argv) batch.clear(); } if (!str.empty()) { - total_words += countWords(str); batch.push_back(make_pair(count, str)); count++; @@ -310,4 +308,4 @@ main(int argc, char** argv) // std::vector workers; -} \ No newline at end of file +} From 3bb72a636be630042bd90f67e7ee48daa3c10d5d Mon Sep 17 00:00:00 2001 From: ydharavath Date: Fri, 16 Aug 2024 14:54:03 +0530 Subject: [PATCH 4/7] Update riva_nmt_t2t_client.cc --- riva/clients/nmt/riva_nmt_t2t_client.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/riva/clients/nmt/riva_nmt_t2t_client.cc b/riva/clients/nmt/riva_nmt_t2t_client.cc index 5b9dd8e..f0bd38b 100644 --- a/riva/clients/nmt/riva_nmt_t2t_client.cc +++ b/riva/clients/nmt/riva_nmt_t2t_client.cc @@ -223,6 +223,7 @@ main(int argc, char** argv) // std::vector>> inputs; std::string str; + int count = 0; std::vector> batch; std::vector>> all_requests; std::ifstream nmt_file(FLAGS_text_file); From 1e25e0b742fd7c6233e75fabab0073e2fdf24476 Mon Sep 17 00:00:00 2001 From: Yuvaraj Dharavath Date: Wed, 21 Aug 2024 12:26:57 +0530 Subject: [PATCH 5/7] updated perf metric and new line added --- riva/clients/nmt/riva_nmt_t2t_client.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/riva/clients/nmt/riva_nmt_t2t_client.cc b/riva/clients/nmt/riva_nmt_t2t_client.cc index f0bd38b..3721eb6 100644 --- a/riva/clients/nmt/riva_nmt_t2t_client.cc +++ b/riva/clients/nmt/riva_nmt_t2t_client.cc @@ -91,6 +91,7 @@ translateBatch( } int countWords(const std::string& text) { + int wordCount = 0; bool inside_word = false; From fe1ac14b7b18ea067a7a82c292c6f63ff2f81dc7 Mon Sep 17 00:00:00 2001 From: ydharavath Date: Fri, 20 Sep 2024 16:24:26 +0530 Subject: [PATCH 6/7] Update streaming_s2t_client.cc --- riva/clients/nmt/streaming_s2t_client.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/riva/clients/nmt/streaming_s2t_client.cc b/riva/clients/nmt/streaming_s2t_client.cc index b62f132..4501738 100644 --- a/riva/clients/nmt/streaming_s2t_client.cc +++ b/riva/clients/nmt/streaming_s2t_client.cc @@ -256,6 +256,8 @@ StreamingS2TClient::PostProcessResults(std::shared_ptr call, bool VLOG(1) << "Latency:" << lat << std::endl; latencies_.push_back(lat); } + std::ofstream result_file(nmt_text_file_, std::ios::app); + call->PrintResult(audio_device, result_file); } void @@ -267,7 +269,6 @@ StreamingS2TClient::ReceiveResponses(std::shared_ptr call, bool a gotoxy(0, 5); } - std::ofstream result_file(nmt_text_file_); while (call->streamer->Read(&call->response)) { // Returns false when no more to read. call->recv_times.push_back(std::chrono::steady_clock::now()); for (int r = 0; r < call->response.results_size(); ++r) { @@ -279,13 +280,9 @@ StreamingS2TClient::ReceiveResponses(std::shared_ptr call, bool a gotoxy(0, 5); } VLOG(1) << "Result: " << result.DebugString(); - std::cout << "translated text: \"" << result.alternatives(0).transcript() << "\"" - << std::endl; - result_file << result.alternatives(0).transcript() << std::endl; } } - result_file.close(); - + PostProcessResults(call, audio_device); grpc::Status status = call->streamer->Finish(); if (!status.ok()) { // Report the RPC failure. From bef2038fa968f2854a7fd2935124c021a19b2543 Mon Sep 17 00:00:00 2001 From: ydharavath Date: Fri, 20 Sep 2024 16:24:39 +0530 Subject: [PATCH 7/7] Update streaming_s2t_client.h