start_time = time.time() step_size = 4000 for start_idx in range(0, len(sentences), step_size): translations_single_p = model.translate(sentences[start_idx:start_idx+step_size], source_lang='en', target_lang='de', show_progress_bar=True) end_time = time.time() print("Single-Process translation done after {:.2f} sec. {:.2f} sentences / second".format(end_time - start_time, len(sentences) / (end_time - start_time))) ######## Multi-Process-Translation del model model = EasyNMT(sys.argv[1]) # You can pass a target_devices parameter to the start_multi_process_pool() method to define how many processes to start # and on which devices the processes should run process_pool = model.start_multi_process_pool() #Do some warm-up model.translate_multi_process(process_pool, sentences[0:100], source_lang='en', target_lang='de', show_progress_bar=False) # Start translation speed measure - Multi process start_time = time.time() translations_multi_p = model.translate_multi_process(process_pool, sentences, source_lang='en', target_lang='de', show_progress_bar=True) end_time = time.time() print("Multi-Process translation done after {:.2f} sec. {:.2f} sentences / second".format(end_time - start_time, len(sentences) / (end_time - start_time))) model.stop_multi_process_pool(process_pool) ##Check that the resutls are equivalent for idx in range(len(translations_single_p)):
continue if row['dataset'] == 'SNLI' and snli < snli_max_sentences: sentences.add(row['sentence1']) snli += 1 if row['dataset'] == 'MNLI' and mnli < mnli_max_sentences: sentences.add(row['sentence1']) mnli += 1 if snli >= snli_max_sentences and mnli >= mnli_max_sentences: break print("Sentences:", len(sentences)) sentences = list(sentences) ######## Multi-Process-Translation # You can pass a target_devices parameter to the start_multi_process_pool() method to define how many processes to start # and on which devices the processes should run process_pool = model.start_multi_process_pool(['cuda', 'cuda']) #Do some warm-up model.translate_multi_process(process_pool, sentences[0:100], source_lang='en', target_lang='de', show_progress_bar=False) # Start translation speed measure - Multi process start_time = time.time() translations_multi_p = model.translate_multi_process(process_pool, sentences, source_lang='en', target_lang='de', show_progress_bar=True) end_time = time.time() print("Multi-Process translation done after {:.2f} sec. {:.2f} sentences / second".format(end_time - start_time, len(sentences) / (end_time - start_time))) model.stop_multi_process_pool(process_pool)