INNER CODE UNIT · Python
popen_with
OpenNMT/CTranslate2 · tools/tune_inter_intra.py:30
def popen_with(inter_threads, intra_threads):
user_args = [arg for arg in sys.argv[2:] if arg != "--log_profiling"]
tune_args = ['--inter_threads', str(inter_threads), '--intra_threads', str(intra_threads), '--log_throughput', '--device', 'cpu']
return subprocess.Popen([translate_bin_path] + user_args + tune_args, stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
def performance_with_parameters(inter_threads, intra_threads):
translate = popen_with(inter_threads, intra_threads)
translate.stdin.write(input_to_translate)
translate.stdin.close()
# any error in the execution of the program will show in stderr and will prevent us to parse tokens/s
try:
err = str(translate.stderr.read().decode("utf-8"))
tokens_per_seconds = float(err)
except KeyboardInterrupt:
raise KeyboardInterrupt()
except:
eprint(err)
exit(1)