Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions riva/clients/nmt/riva_nmt_t2t_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,31 @@ 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=<filename> " << std::endl;
Expand Down Expand Up @@ -195,6 +213,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
Expand All @@ -220,6 +239,7 @@ main(int argc, char** argv)
batch.clear();
}
if (!str.empty()) {
total_words += countWords(str);
batch.push_back(make_pair(count, str));
count++;
}
Expand Down Expand Up @@ -255,6 +275,7 @@ main(int argc, char** argv)
workers.push_back(std::thread([&, i]() {
std::unique_ptr<nr_nmt::RivaTranslation::Stub> 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));
Expand All @@ -270,13 +291,14 @@ main(int argc, char** argv)
}
}
}

auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> 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();
Expand Down
9 changes: 3 additions & 6 deletions riva/clients/nmt/streaming_s2t_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ StreamingS2TClient::PostProcessResults(std::shared_ptr<S2TClientCall> 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
Expand All @@ -267,7 +269,6 @@ StreamingS2TClient::ReceiveResponses(std::shared_ptr<S2TClientCall> 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) {
Expand All @@ -279,13 +280,9 @@ StreamingS2TClient::ReceiveResponses(std::shared_ptr<S2TClientCall> 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.
Expand Down