INNER CODE UNIT · Python
configurations
OpenNMT/CTranslate2 · tools/tune_inter_intra.py:18
configurations = sorted([(i, j) for (i, j) in itertools.product(range(1, N_PHYSICAL_CORES+1), repeat=2) if i*j <= N_PHYSICAL_CORES], key=lambda x: x[0]*x[1], reverse=True)
eprint("Values to explore:", list(configurations))
# do not wait standard input if a src file to translate is given
input_to_translate = bytes() if "--src" in sys.argv else sys.stdin.read().encode()
translate_bin_path = sys.argv[1]
if not os.access(translate_bin_path, os.X_OK):
eprint("No executable file at:", translate_bin_path)
exit(1)
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):