From 4137c2b4e3cba0ec5ca1da7b58b3ff97fdb25e50 Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 31 Jan 2020 13:59:21 -0800 Subject: [PATCH] Change all prints and nemo.logging to from nemo import logging; logging (#311) * change print and nemo.logging to from nemo import logging; logging. Signed-off-by: Jason * style fix Signed-off-by: Jason * change some infos to warnings Signed-off-by: Jason * fix lgtm suggestions Signed-off-by: Jason * abs path Signed-off-by: Jason --- docs/docs_zh/sources/source/nlp/ner.rst | 2 +- .../sources/source/tutorials/callbacks.rst | 5 +- .../source/tutorials/complex_training.rst | 4 +- .../sources/source/tutorials/examples.rst | 8 +-- .../source/nlp/joint_intent_slot_filling.rst | 10 ++-- docs/sources/source/nlp/ner.rst | 2 +- docs/sources/source/nlp/punctuation.rst | 6 +- .../sources/source/nlp/question_answering.rst | 2 +- docs/sources/source/tutorials/callbacks.rst | 5 +- .../source/tutorials/complex_training.rst | 4 +- docs/sources/source/tutorials/examples.rst | 8 +-- .../applications/asr_service/app/__init__.py | 4 +- .../applications/asr_service/app/routes.py | 6 +- examples/asr/jasper_an4.py | 18 +++--- examples/image/transfer_learning.py | 6 +- examples/start_here/chatbot_example.py | 6 +- examples/start_here/chatbot_example2.py | 4 +- examples/start_here/simplest_example.py | 4 +- examples/tts/tts_infer.py | 20 ++++--- examples/tts/waveglow.py | 16 ++--- nemo/backends/pytorch/actions.py | 51 ++++++++-------- nemo/backends/pytorch/torchvision/helpers.py | 8 ++- .../pytorch/tutorials/chatbot/data.py | 18 +++--- nemo/backends/pytorch/tutorials/toys.py | 11 ++-- nemo/collections/asr/parts/cleaners.py | 4 +- nemo/collections/asr/parts/dataset.py | 8 +-- nemo/collections/asr/parts/features.py | 12 ++-- nemo/collections/asr/parts/perturb.py | 16 ++--- nemo/collections/tts/parts/manifest.py | 4 +- nemo/collections/tts/parts/tacotron2.py | 2 +- nemo/collections/tts/waveglow_modules.py | 5 +- nemo/core/neural_modules.py | 7 ++- scripts/build_lm_text.py | 5 +- ...b_format_to_token_classification_format.py | 5 +- scripts/export_bert_to_trt.py | 18 +++--- scripts/export_jasper_onnx_to_trt.py | 10 ++-- scripts/export_jasper_to_onnx.py | 20 +++---- scripts/fisher_audio_to_wav.py | 5 +- scripts/get_aishell_data.py | 21 +++---- scripts/get_databaker_data.py | 29 +++++----- scripts/get_librispeech_data.py | 19 +++--- scripts/get_ljspeech_data.py | 21 +++---- scripts/get_tatoeba_data.py | 19 +++--- scripts/get_timit_data.py | 11 ++-- scripts/process_aishell2_data.py | 5 +- scripts/process_an4_data.py | 15 ++--- tests/asr/test_asr.py | 58 ++++++++++--------- tests/asr/test_weight_share.py | 16 ++--- tests/asr/test_zeroDS.py | 20 ++++--- tests/common_setup.py | 8 ++- tests/test_neural_types.py | 7 ++- tests/test_pytorch_trainers.py | 8 ++- tests/test_tutorials_pytorch.py | 2 +- tests/tts/test_tts.py | 12 ++-- 54 files changed, 341 insertions(+), 279 deletions(-) diff --git a/docs/docs_zh/sources/source/nlp/ner.rst b/docs/docs_zh/sources/source/nlp/ner.rst index 8901638c2a4f..90cd306f62a2 100644 --- a/docs/docs_zh/sources/source/nlp/ner.rst +++ b/docs/docs_zh/sources/source/nlp/ner.rst @@ -149,7 +149,7 @@ text.txt 每一行包含文本序列,其中词以空格来进行分隔。label callback_train = nemo.core.SimpleLossLoggerCallback( tensors=[loss], - print_func=lambda x: print("Loss: {:.3f}".format(x[0].item()))) + print_func=lambda x: logging.info("Loss: {:.3f}".format(x[0].item()))) train_data_size = len(train_data_layer) diff --git a/docs/docs_zh/sources/source/tutorials/callbacks.rst b/docs/docs_zh/sources/source/tutorials/callbacks.rst index ff935f8e18b9..a6b8fdb82d57 100644 --- a/docs/docs_zh/sources/source/tutorials/callbacks.rst +++ b/docs/docs_zh/sources/source/tutorials/callbacks.rst @@ -24,13 +24,14 @@ SimpleLossLoggerCallback 是用来记录训练过程中的一些指标数据比 get_tb_values() 和 log_to_tb_func() 函数的输入。两个推荐重写的参数是 print_func() 和 get_tb_values() 或者 log_to_tb_func() 任选其一。 -print_func() 应该用来记录打印到屏幕上的值。我们推荐使用 nemo.logging.info() +print_func() 应该用来记录打印到屏幕上的值。我们推荐使用 logging.info() 来取代 print() 函数。比如,可以这么打印 loss 值: .. code-block:: python + from nemo import logging def my_print_func(tensors): - nemo.logging.info(f"Loss {tensors[0]}") + logging.info(f"Loss {tensors[0]}") 我们提供了两个方法来打印到 tensorboard: get_tb_values() 和 log_to_tb_func()。对于记录标量的简单用例,我们推荐使用 get_tb_values()。 diff --git a/docs/docs_zh/sources/source/tutorials/complex_training.rst b/docs/docs_zh/sources/source/tutorials/complex_training.rst index 50d7150ae064..6ad2cb3523d7 100644 --- a/docs/docs_zh/sources/source/tutorials/complex_training.rst +++ b/docs/docs_zh/sources/source/tutorials/complex_training.rst @@ -42,7 +42,7 @@ NeMo 进一步扩充了用例,这些用例会用到多个损失函数和多个 # 更新打印函数加入两个损失函数的张量 callback = nemo.core.SimpleLossLoggerCallback( tensors=[l1_loss_tensor, mse_loss_tensor], - print_func=lambda x: print( + print_func=lambda x: logging.info( f'Train Loss: {str(x[0].item() + x[1].item())}') ) @@ -80,7 +80,7 @@ NeMo 进一步扩充了用例,这些用例会用到多个损失函数和多个 # SimpleLossLoggerCallback 把损失函数值打印到控制台 callback = nemo.core.SimpleLossLoggerCallback( tensors=[l1_loss_tensor, mse_loss_tensor], - print_func=lambda x: print( + print_func=lambda x: logging.info( f'L1 Loss: {str(x[0].item())}' f'MSE Loss: {str(x[1].item())}') ) diff --git a/docs/docs_zh/sources/source/tutorials/examples.rst b/docs/docs_zh/sources/source/tutorials/examples.rst index 410526846608..03badac6fc12 100644 --- a/docs/docs_zh/sources/source/tutorials/examples.rst +++ b/docs/docs_zh/sources/source/tutorials/examples.rst @@ -35,7 +35,7 @@ Hello World # SimpleLossLoggerCallback 打印损失函数值到控制台 callback = nemo.core.SimpleLossLoggerCallback( tensors=[lss], - print_func=lambda x: print(f'Train Loss: {str(x[0].item())}')) + print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}')) # 触发“训练”操作 nf.train([lss], callbacks=[callback], @@ -129,9 +129,9 @@ Hello World source = ' '.join([s for s in source if s != 'EOS' and s != 'PAD']) response = ' '.join([s for s in response if s != 'EOS' and s != 'PAD']) target = ' '.join([s for s in target if s != 'EOS' and s != 'PAD']) - print(f"Train Loss:{str(tensors[0].item())}") - print(f"SOURCE: {source} <---> PREDICTED RESPONSE: {response} " - f"<---> TARGET: {target}") + logging.info(f"Train Loss:{str(tensors[0].item())}") + logging.info(f"SOURCE: {source} <---> PREDICTED RESPONSE: {response} " + f"<---> TARGET: {target}") callback = nemo.core.SimpleLossLoggerCallback( diff --git a/docs/sources/source/nlp/joint_intent_slot_filling.rst b/docs/sources/source/nlp/joint_intent_slot_filling.rst index 7d11f8e7b364..0b4f1284d912 100644 --- a/docs/sources/source/nlp/joint_intent_slot_filling.rst +++ b/docs/sources/source/nlp/joint_intent_slot_filling.rst @@ -109,7 +109,7 @@ Next, we define all Neural Modules participating in our joint intent slot fillin num_gpus=1, local_rank=0, mode='train'): - nemo.logging.info(f"Loading {mode} data...") + logging.info(f"Loading {mode} data...") data_file = f'{data_desc.data_dir}/{mode}.tsv' slot_file = f'{data_desc.data_dir}/{mode}_slots.tsv' shuffle = args.shuffle_data if mode == 'train' else False @@ -133,15 +133,15 @@ Next, we define all Neural Modules participating in our joint intent slot fillin subtokens_mask, intents, slots = data_layer() data_size = len(data_layer) - print(f'The length of data layer is {data_size}') + logging.info(f'The length of data layer is {data_size}') if data_size < batch_size: - nemo.logging.warning("Batch_size is larger than the dataset size") - nemo.logging.warning("Reducing batch_size to dataset size") + logging.warning("Batch_size is larger than the dataset size") + logging.warning("Reducing batch_size to dataset size") batch_size = data_size steps_per_epoch = math.ceil(data_size / (batch_size * num_gpus)) - nemo.logging.info(f"Steps_per_epoch = {steps_per_epoch}") + logging.info(f"Steps_per_epoch = {steps_per_epoch}") hidden_states = pretrained_bert_model(input_ids=ids, token_type_ids=type_ids, diff --git a/docs/sources/source/nlp/ner.rst b/docs/sources/source/nlp/ner.rst index 88777762a651..497f53c82744 100644 --- a/docs/sources/source/nlp/ner.rst +++ b/docs/sources/source/nlp/ner.rst @@ -137,7 +137,7 @@ Now, we will set up our callbacks. We will use 3 callbacks: callback_train = nemo.core.SimpleLossLoggerCallback( tensors=[loss], - print_func=lambda x: print("Loss: {:.3f}".format(x[0].item()))) + print_func=lambda x: logging.info("Loss: {:.3f}".format(x[0].item()))) train_data_size = len(train_data_layer) diff --git a/docs/sources/source/nlp/punctuation.rst b/docs/sources/source/nlp/punctuation.rst index 36833ac898e2..6ded5c6e06d2 100644 --- a/docs/sources/source/nlp/punctuation.rst +++ b/docs/sources/source/nlp/punctuation.rst @@ -204,7 +204,7 @@ Now, we will set up our callbacks. We will use 3 callbacks: callback_train = nemo.core.SimpleLossLoggerCallback( tensors=[task_loss, punct_loss, capit_loss, punct_logits, capit_logits], - print_func=lambda x: print("Loss: {:.3f}".format(x[0].item())), + print_func=lambda x: logging.info("Loss: {:.3f}".format(x[0].item())), step_freq=STEP_FREQ) train_data_size = len(train_data_layer) @@ -293,7 +293,7 @@ Run inference, append punctuation and capitalize words based on the generated pr capit_preds = np.argmax(capit_logits, axis=2) for i, query in enumerate(queries): - nemo.logging.info(f'Query: {query}') + logging.info(f'Query: {query}') punct_pred = punct_preds[i][subtokens_mask[i] > 0.5] capit_pred = capit_preds[i][subtokens_mask[i] > 0.5] @@ -312,7 +312,7 @@ Run inference, append punctuation and capitalize words based on the generated pr if punct_label != 'O': output += punct_label output += ' ' - nemo.logging.info(f'Combined: {output.strip()}\n') + logging.info(f'Combined: {output.strip()}\n') Inference results: diff --git a/docs/sources/source/nlp/question_answering.rst b/docs/sources/source/nlp/question_answering.rst index a74e6a7e2888..08264bf0020e 100644 --- a/docs/sources/source/nlp/question_answering.rst +++ b/docs/sources/source/nlp/question_answering.rst @@ -157,7 +157,7 @@ Next, we define all Neural Modules participating in our question answering class train_callback = nemo.core.SimpleLossLoggerCallback( tensors=train_tensors, - print_func=lambda x: print("Loss: {:.3f}".format(x[0].item())), + print_func=lambda x: logging.info("Loss: {:.3f}".format(x[0].item())), get_tb_values=lambda x: [["loss", x[0]]], step_freq=args.step_freq, tb_writer=neural_factory.tb_writer) diff --git a/docs/sources/source/tutorials/callbacks.rst b/docs/sources/source/tutorials/callbacks.rst index 0a9ee1941060..c68fe4f48641 100644 --- a/docs/sources/source/tutorials/callbacks.rst +++ b/docs/sources/source/tutorials/callbacks.rst @@ -28,13 +28,14 @@ training. The two reccomended arguments to override are print_func(), and either get_tb_values() or log_to_tb_func(). print_func() should be used to log values to screen. We recommend using -nemo.logging.info() in place +logging.info() in place of print(). For example, it can be used to print the loss value: .. code-block:: python + from nemo import logging def my_print_func(tensors): - nemo.logging.info(f"Loss {tensors[0]}") + logging.info(f"Loss {tensors[0]}") We provide two methods to log to tensorboard: get_tb_values() and log_to_tb_func(). For simple use case of logging scalars, we recommend diff --git a/docs/sources/source/tutorials/complex_training.rst b/docs/sources/source/tutorials/complex_training.rst index 31c86b4c8168..95b04b98dc81 100644 --- a/docs/sources/source/tutorials/complex_training.rst +++ b/docs/sources/source/tutorials/complex_training.rst @@ -44,7 +44,7 @@ Here's an example: # Update printing function to add both losses callback = nemo.core.SimpleLossLoggerCallback( tensors=[l1_loss_tensor, mse_loss_tensor], - print_func=lambda x: print( + print_func=lambda x: logging.info( f'Train Loss: {str(x[0].item() + x[1].item())}') ) @@ -84,7 +84,7 @@ loop. # SimpleLossLoggerCallback will print loss values to console. callback = nemo.core.SimpleLossLoggerCallback( tensors=[l1_loss_tensor, mse_loss_tensor], - print_func=lambda x: print( + print_func=lambda x: logging.info( f'L1 Loss: {str(x[0].item())}' f'MSE Loss: {str(x[1].item())}') ) diff --git a/docs/sources/source/tutorials/examples.rst b/docs/sources/source/tutorials/examples.rst index d6764b97e2ce..5cb7b5d75390 100644 --- a/docs/sources/source/tutorials/examples.rst +++ b/docs/sources/source/tutorials/examples.rst @@ -35,7 +35,7 @@ This example shows how to build a model which learn Taylor's coefficients for y= # SimpleLossLoggerCallback will print loss values to console. callback = nemo.core.SimpleLossLoggerCallback( tensors=[lss], - print_func=lambda x: print(f'Train Loss: {str(x[0].item())}')) + print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}')) # Invoke "train" action nf.train([lss], callbacks=[callback], @@ -129,9 +129,9 @@ During training model will print: source = ' '.join([s for s in source if s != 'EOS' and s != 'PAD']) response = ' '.join([s for s in response if s != 'EOS' and s != 'PAD']) target = ' '.join([s for s in target if s != 'EOS' and s != 'PAD']) - print(f"Train Loss:{str(tensors[0].item())}") - print(f"SOURCE: {source} <---> PREDICTED RESPONSE: {response} " - f"<---> TARGET: {target}") + logging.info(f"Train Loss:{str(tensors[0].item())}") + logging.info(f"SOURCE: {source} <---> PREDICTED RESPONSE: {response} " + f"<---> TARGET: {target}") callback = nemo.core.SimpleLossLoggerCallback( diff --git a/examples/applications/asr_service/app/__init__.py b/examples/applications/asr_service/app/__init__.py index ee77a9ba216d..abcd6abf1015 100644 --- a/examples/applications/asr_service/app/__init__.py +++ b/examples/applications/asr_service/app/__init__.py @@ -8,6 +8,8 @@ import nemo import nemo.collections.asr as nemo_asr +logging = nemo.logging + app = Flask(__name__) # make sure WORK_DIR exists before calling your service # in this folder, the service will store received .wav files and constructed @@ -46,7 +48,7 @@ vocab=labels, beam_width=64, alpha=2.0, beta=1.0, lm_path=LM_PATH, num_cpus=max(os.cpu_count(), 1), ) else: - print("Beam search is not enabled") + logging.info("Beam search is not enabled") if __name__ == '__main__': app.run() diff --git a/examples/applications/asr_service/app/routes.py b/examples/applications/asr_service/app/routes.py index 9dc82424fcc5..35e543173ac0 100644 --- a/examples/applications/asr_service/app/routes.py +++ b/examples/applications/asr_service/app/routes.py @@ -20,10 +20,12 @@ import nemo import nemo.collections.asr as nemo_asr +logging = nemo.logging + try: from app import beam_search_with_lm except ImportError: - print("Not using Beam Search Decoder with LM") + logging.info("Not using Beam Search Decoder with LM") ENABLE_NGRAM = False @@ -46,7 +48,7 @@ def wav_to_text(manifest, greedy=True): predictions = greedy_decoder(log_probs=log_probs) if ENABLE_NGRAM: - print('Running with beam search') + logging.info('Running with beam search') beam_predictions = beam_search_with_lm(log_probs=log_probs, log_probs_length=encoded_len) eval_tensors = [beam_predictions] diff --git a/examples/asr/jasper_an4.py b/examples/asr/jasper_an4.py index ddb6bd9fc6c0..77d81c9c364f 100644 --- a/examples/asr/jasper_an4.py +++ b/examples/asr/jasper_an4.py @@ -20,6 +20,8 @@ ) from nemo.utils.lr_policies import CosineAnnealing +logging = nemo.logging + def create_dags(jasper_params, args, nf): vocab = jasper_params['labels'] @@ -37,7 +39,7 @@ def create_dags(jasper_params, args, nf): num_samples = len(data_layer) steps_per_epoch = math.ceil(num_samples / (args.batch_size * args.iter_per_step * nf.world_size)) total_steps = steps_per_epoch * args.num_epochs - print("Train samples=", num_samples, "num_steps=", total_steps) + logging.info("Train samples=", num_samples, "num_steps=", total_steps) data_preprocessor = nemo_asr.AudioToMelSpectrogramPreprocessor( **jasper_params["AudioToMelSpectrogramPreprocessor"] @@ -57,7 +59,7 @@ def create_dags(jasper_params, args, nf): ) num_samples = len(data_layer_eval) - nemo.logging.info(f"Eval samples={num_samples}") + logging.info(f"Eval samples={num_samples}") jasper_encoder = nemo_asr.JasperEncoder(**jasper_params["JasperEncoder"]) @@ -84,7 +86,7 @@ def create_dags(jasper_params, args, nf): loss_e = ctc_loss( log_probs=log_probs_e, targets=transcript_e, input_length=encoded_len_e, target_length=transcript_len_e, ) - nemo.logging.info("Num of params in encoder: {0}".format(jasper_encoder.num_weights)) + logging.info("Num of params in encoder: {0}".format(jasper_encoder.num_weights)) # Callbacks to print info to console and Tensorboard train_callback = nemo.core.SimpleLossLoggerCallback( @@ -194,10 +196,10 @@ def main(): ) if args.test_after_training: - nemo.logging.info("Testing greedy and beam search with LM WER.") + logging.info("Testing greedy and beam search with LM WER.") # Create BeamSearch NM if nf.world_size > 1: - nemo.logging.warning("Skipping beam search WER as it does not " "work if doing distributed training.") + logging.warning("Skipping beam search WER as it does not " "work if doing distributed training.") else: beam_search_with_lm = nemo_asr.BeamSearchDecoderWithLM( vocab=vocab, beam_width=64, alpha=2.0, beta=1.5, lm_path=args.lm, num_cpus=max(os.cpu_count(), 1), @@ -210,7 +212,7 @@ def main(): greedy_hypotheses = post_process_predictions(evaluated_tensors[1], vocab) references = post_process_transcripts(evaluated_tensors[2], evaluated_tensors[3], vocab) wer = word_error_rate(hypotheses=greedy_hypotheses, references=references) - nemo.logging.info("Greedy WER: {:.2f}%".format(wer * 100)) + logging.info("Greedy WER: {:.2f}%".format(wer * 100)) if wer > wer_thr: nf.sync_all_processes(False) raise ValueError(f"Final eval greedy WER {wer * 100:.2f}% > :" f"than {wer_thr * 100:.2f}%") @@ -225,7 +227,7 @@ def main(): beam_hypotheses.append(j[0][1]) beam_wer = word_error_rate(hypotheses=beam_hypotheses, references=references) - nemo.logging.info("Beam WER {:.2f}%".format(beam_wer * 100)) + logging.info("Beam WER {:.2f}%".format(beam_wer * 100)) assert beam_wer <= beam_wer_thr, "Final eval beam WER {:.2f}% > than {:.2f}%".format( beam_wer * 100, beam_wer_thr * 100 ) @@ -266,7 +268,7 @@ def main(): greedy_hypotheses = post_process_predictions(evaluated_tensors[1], vocab) references = post_process_transcripts(evaluated_tensors[2], evaluated_tensors[3], vocab) wer_new = word_error_rate(hypotheses=greedy_hypotheses, references=references) - nemo.logging.info("New greedy WER: {:.2f}%".format(wer_new * 100)) + logging.info("New greedy WER: {:.2f}%".format(wer_new * 100)) if wer_new > wer * 1.1: nf.sync_all_processes(False) raise ValueError( diff --git a/examples/image/transfer_learning.py b/examples/image/transfer_learning.py index 72ee4d22ef62..bb3d54fe837c 100644 --- a/examples/image/transfer_learning.py +++ b/examples/image/transfer_learning.py @@ -9,16 +9,18 @@ import nemo from nemo.backends.pytorch.torchvision.helpers import compute_accuracy, eval_epochs_done_callback, eval_iter_callback +logging = nemo.logging + sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../..'))) if not os.path.isdir("hymenoptera_data"): - print("Datafolder not found. Downloading data from the Web") + logging.info("Datafolder not found. Downloading data from the Web") subprocess.run(["wget", "https://download.pytorch.org/tutorial/hymenoptera_data.zip"]) zip_ref = zipfile.ZipFile('hymenoptera_data.zip', 'r') zip_ref.extractall('.') zip_ref.close() else: - print("Found data folder - hymenoptera_data") + logging.info("Found data folder - hymenoptera_data") parser = argparse.ArgumentParser(description='Transfer Learning') parser.add_argument("--batch_size", default=32, type=int) diff --git a/examples/start_here/chatbot_example.py b/examples/start_here/chatbot_example.py index d6be2c6e37ed..47d240318613 100644 --- a/examples/start_here/chatbot_example.py +++ b/examples/start_here/chatbot_example.py @@ -4,6 +4,8 @@ import nemo +logging = nemo.logging + # Get Data data_file = "movie_data.txt" if not os.path.isfile(data_file): @@ -67,8 +69,8 @@ def outputs2words(tensors, vocab): source = ' '.join([s for s in source if s != 'EOS' and s != 'PAD']) response = ' '.join([s for s in response if s != 'EOS' and s != 'PAD']) target = ' '.join([s for s in target if s != 'EOS' and s != 'PAD']) - print(f"Train Loss:{str(tensors[0].item())}") - print(f"SOURCE: {source} <---> PREDICTED RESPONSE: {response} " f"<---> TARGET: {target}") + logging.info(f"Train Loss:{str(tensors[0].item())}") + logging.info(f"SOURCE: {source} <---> PREDICTED RESPONSE: {response} " f"<---> TARGET: {target}") callback = nemo.core.SimpleLossLoggerCallback( diff --git a/examples/start_here/chatbot_example2.py b/examples/start_here/chatbot_example2.py index 085a43ababe8..d5553413341a 100644 --- a/examples/start_here/chatbot_example2.py +++ b/examples/start_here/chatbot_example2.py @@ -5,6 +5,8 @@ import nemo +logging = nemo.logging + # Get Data data_file = "movie_data.txt" if not os.path.isfile(data_file): @@ -74,7 +76,7 @@ def outputs2words(tensors, vocab): source = ' '.join([s for s in source if s != 'EOS' and s != 'PAD']) response = ' '.join([s for s in response if s != 'EOS' and s != 'PAD']) target = ' '.join([s for s in target if s != 'EOS' and s != 'PAD']) - print(f'Train Loss: {str(tensors[0].item())}') + logging.info(f'Train Loss: {str(tensors[0].item())}') tmp = " SOURCE: {0} <---> PREDICTED RESPONSE: {1} <---> TARGET: {2}" return tmp.format(source, response, target) diff --git a/examples/start_here/simplest_example.py b/examples/start_here/simplest_example.py index 2c275cc9f0af..cd58ac1cca50 100644 --- a/examples/start_here/simplest_example.py +++ b/examples/start_here/simplest_example.py @@ -1,6 +1,8 @@ # Copyright (c) 2019 NVIDIA Corporation import nemo +logging = nemo.logging + nf = nemo.core.NeuralModuleFactory() # To use CPU-only do: # from nemo.core import DeviceType @@ -19,7 +21,7 @@ # SimpleLossLoggerCallback will print loss values to console. callback = nemo.core.SimpleLossLoggerCallback( - tensors=[lss], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[lss], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) # Invoke "train" action diff --git a/examples/tts/tts_infer.py b/examples/tts/tts_infer.py index 53ce0bd33cdf..94545eab5776 100644 --- a/examples/tts/tts_infer.py +++ b/examples/tts/tts_infer.py @@ -14,6 +14,8 @@ import nemo.collections.asr as nemo_asr import nemo.collections.tts as nemo_tts +logging = nemo.logging + def parse_args(): parser = argparse.ArgumentParser(description='TTS') @@ -101,7 +103,7 @@ def griffin_lim(magnitudes, n_iters=50, n_fft=1024): complex_spec = magnitudes * phase signal = librosa.istft(complex_spec) if not np.isfinite(signal).all(): - print("WARNING: audio was not finite, skipping audio saving") + logging.warning("audio was not finite, skipping audio saving") return np.array([0]) for _ in range(n_iters): @@ -164,7 +166,7 @@ def main(): use_cache = True if args.local_rank is not None: - print("Doing ALL GPU") + logging.info("Doing ALL GPU") use_cache = False # Create text to spectrogram model @@ -181,13 +183,13 @@ def main(): infer_batch_size=args.batch_size, ) - print("Running Tacotron 2") + logging.info("Running Tacotron 2") # Run tacotron 2 evaluated_tensors = neural_factory.infer( tensors=infer_tensors, checkpoint_dir=args.spec_model_load_dir, cache=use_cache, offload_to_cpu=False, ) mel_len = evaluated_tensors[-1] - print("Done Running Tacotron 2") + logging.info("Done Running Tacotron 2") filterbank = librosa.filters.mel( sr=tacotron2_params["sample_rate"], n_fft=tacotron2_params["n_fft"], @@ -196,7 +198,7 @@ def main(): ) if args.vocoder == "griffin-lim": - print("Running Griffin-Lim") + logging.info("Running Griffin-Lim") mel_spec = evaluated_tensors[0] for i, batch in enumerate(mel_spec): log_mel = batch.cpu().numpy().transpose(0, 2, 1) @@ -227,7 +229,7 @@ def main(): # waveglow.restore_from(args.vocoder_model_load_dir) # Run waveglow - print("Running Waveglow") + logging.info("Running Waveglow") evaluated_tensors = neural_factory.infer( tensors=[audio_pred], checkpoint_dir=args.vocoder_model_load_dir, @@ -235,13 +237,13 @@ def main(): modules_to_restore=[waveglow], use_cache=use_cache, ) - print("Done Running Waveglow") + logging.info("Done Running Waveglow") if args.waveglow_denoiser_strength > 0: - print("Setup denoiser") + logging.info("Setup denoiser") waveglow.setup_denoiser() - print("Saving results to disk") + logging.info("Saving results to disk") for i, batch in enumerate(evaluated_tensors[0]): audio = batch.cpu().numpy() for j, sample in enumerate(audio): diff --git a/examples/tts/waveglow.py b/examples/tts/waveglow.py index 4f2134933478..42657137e9eb 100644 --- a/examples/tts/waveglow.py +++ b/examples/tts/waveglow.py @@ -12,6 +12,8 @@ import nemo.utils.argparse as nm_argparse from nemo.collections.tts import waveglow_eval_log_to_tb_func, waveglow_log_to_tb_func, waveglow_process_eval_batch +logging = nemo.logging + def parse_args(): parser = argparse.ArgumentParser( @@ -73,9 +75,9 @@ def create_NMs(waveglow_params): waveglow = nemo_tts.WaveGlowNM(**waveglow_params["WaveGlowNM"]) waveglow_loss = nemo_tts.WaveGlowLoss() - nemo.logging.info('================================') - nemo.logging.info(f"Total number of parameters: {waveglow.num_weights}") - nemo.logging.info('================================') + logging.info('================================') + logging.info(f"Total number of parameters: {waveglow.num_weights}") + logging.info('================================') return (data_preprocessor, waveglow, waveglow_loss) @@ -95,7 +97,7 @@ def create_train_dag( N = len(data_layer) steps_per_epoch = int(N / (batch_size * neural_factory.world_size)) - nemo.logging.info('Have {0} examples to train on.'.format(N)) + logging.info('Have {0} examples to train on.'.format(N)) # Train DAG audio, audio_len, = data_layer() @@ -107,7 +109,7 @@ def create_train_dag( # Callbacks needed to print info to console and Tensorboard train_callback = nemo.core.SimpleLossLoggerCallback( tensors=[loss_t, z, spec_target, spec_target_len], - print_func=lambda x: print(f"Loss: {x[0].data}"), + print_func=lambda x: logging.info(f"Loss: {x[0].data}"), log_to_tb_func=partial(waveglow_log_to_tb_func, log_images=False), tb_writer=neural_factory.tb_writer, ) @@ -191,7 +193,7 @@ def create_all_dags( cpu_per_dl=cpu_per_dl, ) else: - nemo.logging.info("There were no val datasets passed") + logging.info("There were no val datasets passed") callbacks = training_callbacks + eval_callbacks return training_loss, callbacks, steps_per_epoch @@ -218,7 +220,7 @@ def main(): ) if args.local_rank is not None: - nemo.logging.info('Doing ALL GPU') + logging.info('Doing ALL GPU') yaml = YAML(typ="safe") with open(args.model_config) as file: diff --git a/nemo/backends/pytorch/actions.py b/nemo/backends/pytorch/actions.py index f6b2b7365829..4c9db09fd67b 100644 --- a/nemo/backends/pytorch/actions.py +++ b/nemo/backends/pytorch/actions.py @@ -12,16 +12,15 @@ import torch.nn as nn import torch.optim as optim -import nemo -from ...core import DeploymentFormat, DeviceType, NeuralModule, NmTensor -from ...core.callbacks import ActionCallback, EvaluatorCallback, SimpleLossLoggerCallback -from ...core.neural_factory import Actions, ModelMode, Optimization -from ...core.neural_types import * -from ...utils.helpers import get_checkpoint_from_dir -from .module_wrapper import TrainableNeuralModuleWrapper -from .nm import DataLayerNM -from .optimizers import AdamW, Novograd, master_params -from nemo.backends.pytorch.nm import TrainableNM +from nemo import logging +from nemo.backends.pytorch.module_wrapper import TrainableNeuralModuleWrapper +from nemo.backends.pytorch.nm import DataLayerNM, TrainableNM +from nemo.backends.pytorch.optimizers import AdamW, Novograd, master_params +from nemo.core import DeploymentFormat, DeviceType, NeuralModule, NmTensor +from nemo.core.callbacks import ActionCallback, EvaluatorCallback, SimpleLossLoggerCallback +from nemo.core.neural_factory import Actions, ModelMode, Optimization +from nemo.core.neural_types import * +from nemo.utils.helpers import get_checkpoint_from_dir # these imports will happen on as-needed basis amp = None @@ -336,14 +335,14 @@ def __setup_optimizer( raise ValueError("Unknown optimizer class: {0}".format(optimizer_class)) if optimization_params.get("larc", False): - nemo.logging.info("Enabling larc") + logging.info("Enabling larc") optimizer = LARC(optimizer, trust_coefficient=optimization_params.get("larc_eta", 2e-2),) else: - nemo.logging.info("Optimizer instance: {0} is provided.") + logging.info("Optimizer instance: {0} is provided.") if optimizer_class is not None and optimizer_class != "": - nemo.logging.warning("Ignoring `optimizer_class` parameter because" "`optimizer_instance` is provided") + logging.warning("Ignoring `optimizer_class` parameter because" "`optimizer_instance` is provided") if optimization_params is not None and optimization_params != {}: - nemo.logging.warning( + logging.warning( "Ignoring `optimization_params` parameter for " "optimizer because `optimizer_instance` is provided" ) @@ -506,7 +505,7 @@ def _eval(self, tensors_2_evaluate, callback, step, verbose=False): assert dist.is_initialized() is_distributed = True world_size = torch.distributed.get_world_size() - # nemo.logging.info( + # logging.info( # "Doing distributed evaluation. Rank {0} of {1}".format( # self.local_rank, world_size # ) @@ -547,7 +546,7 @@ def _eval(self, tensors_2_evaluate, callback, step, verbose=False): num_batches = len(eval_dataloader) for epoch_i, data in enumerate(eval_dataloader, 0): if verbose and (num_batches < 10 or (epoch_i % int(num_batches / 10) == 0)): - nemo.logging.info(f"Evaluating batch {epoch_i} out of {num_batches}") + logging.info(f"Evaluating batch {epoch_i} out of {num_batches}") tensors = [] if isinstance(data, torch.Tensor): data = (data,) @@ -571,7 +570,7 @@ def _eval(self, tensors_2_evaluate, callback, step, verbose=False): for t2e in tensors_2_evaluate: key = t2e.unique_name if key not in registered_e_tensors.keys(): - nemo.logging.info("WARNING: Tensor {} was not found during " "eval".format(key)) + logging.info("WARNING: Tensor {} was not found during " "eval".format(key)) continue if is_distributed: # where we will all_gather results from all workers @@ -661,7 +660,7 @@ def _infer( assert dist.is_initialized() is_distributed = True world_size = torch.distributed.get_world_size() - # nemo.logging.info( + # logging.info( # "Doing distributed evaluation. Rank {0} of {1}".format( # self.local_rank, world_size # ) @@ -712,7 +711,7 @@ def _infer( for epoch_i, data in enumerate(loop_iterator, 0): if verbose and (num_batches < 10 or (epoch_i % int(num_batches / 10) == 0)): - nemo.logging.info(f"Evaluating batch {epoch_i} out of {num_batches}") + logging.info(f"Evaluating batch {epoch_i} out of {num_batches}") tensors = [] if use_cache: registered_e_tensors = data @@ -754,7 +753,7 @@ def _infer( for t2e in tensors_to_return: key = t2e.unique_name if key not in registered_e_tensors.keys(): - nemo.logging.info("WARNING: Tensor {} was not found during " "eval".format(key)) + logging.info("WARNING: Tensor {} was not found during " "eval".format(key)) continue if is_distributed: # where we will all_gather results from all workers @@ -924,7 +923,7 @@ def __extract_dynamic_axes(port_name: str, ntype: NeuralType, dynamic_axes: defa inputs_to_drop = set() outputs_to_drop = set() if type(module).__name__ == "JasperEncoder": - print( + logging.info( f"Module is JasperEncoder. We are removing" f"input and output length ports since they " f"are not needed for deployment" @@ -1012,7 +1011,7 @@ def __extract_dynamic_axes(port_name: str, ntype: NeuralType, dynamic_axes: defa else: raise NotImplementedError(f"Not supported deployment format: {d_format}") except Exception as e: # nopep8 - nemo.logging.error(f'ERROR: module export failed for {module} ' f'with exception {e}') + logging.error(f'ERROR: module export failed for {module} ' f'with exception {e}') finally: def __old_call__(self, force_pt=False, *input, **kwargs): @@ -1178,7 +1177,7 @@ def train( # raise NotImplementedError( # "Distributed training does nor work with multiple " # "optimizers") - nemo.logging.info("Doing distributed training") + logging.info("Doing distributed training") if t_dataset is not None: train_sampler = torch.utils.data.distributed.DistributedSampler(t_dataset) train_dataloader = torch.utils.data.DataLoader( @@ -1311,7 +1310,7 @@ def train( ): if stop_on_nan_loss: raise ValueError('Loss is NaN or inf - exiting') - nemo.logging.warning('WARNING: Loss is NaN or inf') + logging.warning('WARNING: Loss is NaN or inf') curr_optimizer.zero_grad() nan = True break @@ -1323,7 +1322,7 @@ def train( if torch.isnan(scaled_loss).any() or torch.isinf(scaled_loss).any(): if stop_on_nan_loss: raise ValueError('Loss is NaN or inf -' ' exiting') - nemo.logging.warning('WARNING: Loss is NaN or inf') + logging.warning('WARNING: Loss is NaN or inf') curr_optimizer.zero_grad() continue scaled_loss.backward(bps_scale.to(scaled_loss.get_device())) @@ -1393,7 +1392,7 @@ def infer( module_checkpoints = get_checkpoint_from_dir(modules_to_restore_name, checkpoint_dir, ckpt_pattern) for mod, checkpoint in zip(modules_to_restore, module_checkpoints): - nemo.logging.info(f"Restoring {mod} from {checkpoint}") + logging.info(f"Restoring {mod} from {checkpoint}") mod.restore_from(checkpoint, self._local_rank) # Init Amp diff --git a/nemo/backends/pytorch/torchvision/helpers.py b/nemo/backends/pytorch/torchvision/helpers.py index 3bdf22f1096b..808dfd60c81c 100644 --- a/nemo/backends/pytorch/torchvision/helpers.py +++ b/nemo/backends/pytorch/torchvision/helpers.py @@ -3,9 +3,11 @@ import torch +from nemo import logging + def compute_accuracy(tensors): - print(f"Train Loss: {str(tensors[0].item())}") + logging.info(f"Train Loss: {str(tensors[0].item())}") output = tensors[1] target = tensors[2] res = [] @@ -68,8 +70,8 @@ def eval_iter_callback(tensors, global_vars): def eval_epochs_done_callback(global_vars): eloss = mean(global_vars["eval_loss"]) etop1 = mean(global_vars["top1"]) - print("Evaluation Loss: {0}".format(eloss)) - print("Evaluation Top@1: {0}".format(etop1)) + logging.info("Evaluation Loss: {0}".format(eloss)) + logging.info("Evaluation Top@1: {0}".format(etop1)) for k in global_vars.keys(): global_vars[k] = [] return dict({"Evaluation Loss": eloss, "Evaluation Top@1": etop1}) diff --git a/nemo/backends/pytorch/tutorials/chatbot/data.py b/nemo/backends/pytorch/tutorials/chatbot/data.py index a4ea9124e4cb..0f0b2609fb32 100644 --- a/nemo/backends/pytorch/tutorials/chatbot/data.py +++ b/nemo/backends/pytorch/tutorials/chatbot/data.py @@ -7,6 +7,8 @@ import torch as t +from nemo import logging + # Default word tokens PAD_token = 0 # Used for padding short sentences SOS_token = 1 # Start-of-sentence token @@ -51,7 +53,7 @@ def trim(self, min_count): if v >= min_count: keep_words.append(k) - print( + logging.info( "keep_words {} / {} = {:.4f}".format( len(keep_words), len(self.word2index), len(keep_words) / len(self.word2index), ) @@ -97,7 +99,7 @@ def normalizeString(s): def readVocs(datafile, corpus_name): - print("Reading lines...") + logging.info("Reading lines...") # Read the file and split into lines lines = open(datafile, encoding="utf-8").read().strip().split("\n") # Split every line into pairs and normalize @@ -127,16 +129,16 @@ def filterPairs(pairs): def loadPrepareData(corpus_name, datafile): - print("Start preparing training data ...") + logging.info("Start preparing training data ...") voc, pairs = readVocs(datafile, corpus_name) - print("Read {!s} sentence pairs".format(len(pairs))) + logging.info("Read {!s} sentence pairs".format(len(pairs))) pairs = filterPairs(pairs) - print("Trimmed to {!s} sentence pairs".format(len(pairs))) - print("Counting words...") + logging.info("Trimmed to {!s} sentence pairs".format(len(pairs))) + logging.info("Counting words...") for pair in pairs: voc.addSentence(pair[0]) voc.addSentence(pair[1]) - print("Counted words:", voc.num_words) + logging.info("Counted words:", voc.num_words) return voc, pairs @@ -169,7 +171,7 @@ def trimRareWords(voc, pairs, MIN_COUNT): if keep_input and keep_output: keep_pairs.append(pair) - # print("Trimmed from {} pairs to {}, {:.4f} of total".format(len( + # logging.info("Trimmed from {} pairs to {}, {:.4f} of total".format(len( # pairs), len(keep_pairs), len(keep_pairs) / len(pairs))) return keep_pairs diff --git a/nemo/backends/pytorch/tutorials/toys.py b/nemo/backends/pytorch/tutorials/toys.py index b2449c5ddfd5..a6929f9d3b43 100644 --- a/nemo/backends/pytorch/tutorials/toys.py +++ b/nemo/backends/pytorch/tutorials/toys.py @@ -5,9 +5,10 @@ import torch.nn as nn import torch.utils.data as t_utils -from ....core import DeviceType, NeuralModule -from ....core.neural_types import * -from ..nm import DataLayerNM, LossNM, TrainableNM +from nemo import logging +from nemo.backends.pytorch.nm import DataLayerNM, LossNM, TrainableNM +from nemo.core import DeviceType, NeuralModule +from nemo.core.neural_types import * class TaylorNet(TrainableNM): # Note inheritance from TrainableNM @@ -104,9 +105,9 @@ def __init__(self, *, dim, **kwargs): def forward(self, x, o=None): lst = [] if o is None: - print("O is None") + logging.debug("O is None") else: - print("O is not None") + logging.debug("O is not None") for pw in range(self._dim): lst.append(x ** pw) nx = t.cat(lst, dim=-1) diff --git a/nemo/collections/asr/parts/cleaners.py b/nemo/collections/asr/parts/cleaners.py index 66d0a62fd62f..053fa078a0e8 100755 --- a/nemo/collections/asr/parts/cleaners.py +++ b/nemo/collections/asr/parts/cleaners.py @@ -5,6 +5,8 @@ import inflect from unidecode import unidecode +from nemo import logging + NUM_CHECK = re.compile(r'([$]?)(^|\s)(\S*[0-9]\S*)(?=(\s|$)((\S*)(\s|$))?)') TIME_CHECK = re.compile(r'([0-9]{1,2}):([0-9]{2})(am|pm)?') @@ -90,7 +92,7 @@ def clean_text(string, table, punctuation_to_replace): def warn_common_chars(string): if re.search(r'[£€]', string): - print("WARNING: Your transcript contains one of '£' or '€' which we do" "not currently handle") + logging.warning("Your transcript contains one of '£' or '€' which we do" "not currently handle") def clean_numbers(string): diff --git a/nemo/collections/asr/parts/dataset.py b/nemo/collections/asr/parts/dataset.py index c36f04432c6a..770bd9e2460f 100644 --- a/nemo/collections/asr/parts/dataset.py +++ b/nemo/collections/asr/parts/dataset.py @@ -7,7 +7,7 @@ import torch from torch.utils.data import Dataset -import nemo +from nemo import logging from nemo.collections.asr.parts import collections, parsers @@ -230,7 +230,7 @@ def __init__( f" utt2dur file not found in {kaldi_dir}." ) else: - nemo.logging.info( + logging.info( f"Did not find utt2dur when loading data from " f"{kaldi_dir}. Skipping dataset duration calculations." ) @@ -273,12 +273,12 @@ def __init__( duration += dur if max_utts > 0 and len(data) >= max_utts: - print(f"Stop parsing due to max_utts ({max_utts})") + logging.warning(f"Stop parsing due to max_utts ({max_utts})") break if id2dur: # utt2dur durations are in seconds - nemo.logging.info( + logging.info( f"Dataset loaded with {duration / 60 : .2f} hours. " f"Filtered {filtered_duration / 60 : .2f} hours." ) diff --git a/nemo/collections/asr/parts/features.py b/nemo/collections/asr/parts/features.py index e2fc53d99c32..792758f84575 100644 --- a/nemo/collections/asr/parts/features.py +++ b/nemo/collections/asr/parts/features.py @@ -7,9 +7,9 @@ import torch.nn as nn from torch_stft import STFT -import nemo -from .perturb import AudioAugmentor -from .segment import AudioSegment +from nemo import logging +from nemo.collections.asr.parts.perturb import AudioAugmentor +from nemo.collections.asr.parts.segment import AudioSegment CONSTANT = 1e-5 @@ -142,7 +142,7 @@ def __init__( f"{self} got an invalid value for either n_window_size or " f"n_window_stride. Both must be positive ints." ) - nemo.logging.info(f"PADDING: {pad_to}") + logging.info(f"PADDING: {pad_to}") self.win_length = n_window_size self.hop_length = n_window_stride @@ -150,7 +150,7 @@ def __init__( self.stft_conv = stft_conv if stft_conv: - nemo.logging.info("STFT using conv") + logging.info("STFT using conv") # Create helper class to patch forward func for use with AMP class STFTPatch(STFT): @@ -163,7 +163,7 @@ def forward(self, input_data): self.stft = STFTPatch(self.n_fft, self.hop_length, self.win_length, window) else: - print("STFT using torch") + logging.info("STFT using torch") torch_windows = { 'hann': torch.hann_window, 'hamming': torch.hamming_window, diff --git a/nemo/collections/asr/parts/perturb.py b/nemo/collections/asr/parts/perturb.py index 9b63dc704e61..63e062e44bbd 100644 --- a/nemo/collections/asr/parts/perturb.py +++ b/nemo/collections/asr/parts/perturb.py @@ -5,8 +5,9 @@ import librosa from scipy import signal -from .segment import AudioSegment +from nemo import logging from nemo.collections.asr.parts import collections, parsers +from nemo.collections.asr.parts.segment import AudioSegment class Perturbation(object): @@ -30,7 +31,7 @@ def perturb(self, data): speed_rate = self._rng.uniform(self._min_rate, self._max_rate) if speed_rate <= 0: raise ValueError("speed_rate should be greater than zero.") - # print("DEBUG: speed:", speed_rate) + logging.debug("speed: %f", speed_rate) data._samples = librosa.effects.time_stretch(data._samples, speed_rate) @@ -42,7 +43,7 @@ def __init__(self, min_gain_dbfs=-10, max_gain_dbfs=10, rng=None): def perturb(self, data): gain = self._rng.uniform(self._min_gain_dbfs, self._max_gain_dbfs) - # print("DEBUG: gain:", gain) + logging.debug("gain: %d", gain) data._samples = data._samples * (10.0 ** (gain / 20.0)) @@ -54,7 +55,7 @@ def __init__(self, manifest_path=None, rng=None): def perturb(self, data): impulse_record = self._rng.sample(self._manifest.data, 1)[0] impulse = AudioSegment.from_file(impulse_record['audio_filepath'], target_sr=data.sample_rate) - # print("DEBUG: impulse:", impulse_record['audio_filepath']) + logging.debug("impulse: %s", impulse_record['audio_filepath']) data._samples = signal.fftconvolve(data.samples, impulse.samples, "full") @@ -70,7 +71,7 @@ def perturb(self, data): # TODO: do something smarter than just ignore this condition return shift_samples = int(shift_ms * data.sample_rate // 1000) - # print("DEBUG: shift:", shift_samples) + logging.debug("shift: %s", shift_samples) if shift_samples < 0: data._samples[-shift_samples:] = data._samples[:shift_samples] data._samples[:-shift_samples] = 0 @@ -94,8 +95,7 @@ def perturb(self, data): noise_record = self._rng.sample(self._manifest.data, 1)[0] noise = AudioSegment.from_file(noise_record['audio_filepath'], target_sr=data.sample_rate) noise_gain_db = min(data.rms_db - noise.rms_db - snr_db, self._max_gain_db) - # print("DEBUG: noise:", snr_db, noise_gain_db, noise_record[ - # 'audio_filepath']) + logging.debug("noise: %s %s %s", snr_db, noise_gain_db, noise_record['audio_filepath']) # calculate noise segment to use start_time = self._rng.uniform(0.0, noise.duration - data.duration) @@ -137,7 +137,7 @@ def from_config(cls, config): ptbs = [] for p in config: if p['aug_type'] not in perturbation_types: - print(p['aug_type'], "perturbation not known. Skipping.") + logging.warning("%s perturbation not known. Skipping.", p['aug_type']) continue perturbation = perturbation_types[p['aug_type']] ptbs.append((p['prob'], perturbation(**p['cfg']))) diff --git a/nemo/collections/tts/parts/manifest.py b/nemo/collections/tts/parts/manifest.py index a9d4780dffd5..65a34386b3b8 100644 --- a/nemo/collections/tts/parts/manifest.py +++ b/nemo/collections/tts/parts/manifest.py @@ -1,6 +1,8 @@ # Copyright (c) 2019 NVIDIA Corporation import json +from nemo import logging + class AudioManifest(object): def __init__( @@ -27,7 +29,7 @@ def __init__( duration += data['duration'] if max_utts > 0 and len(ids) >= max_utts: - print('Stopping parsing %s as max_utts=%d' % (manifest_path, max_utts)) + logging.info('Stopping parsing %s as max_utts=%d' % (manifest_path, max_utts)) break if sort_by_duration: diff --git a/nemo/collections/tts/parts/tacotron2.py b/nemo/collections/tts/parts/tacotron2.py index ea2a6551b0d2..13e845231ec1 100644 --- a/nemo/collections/tts/parts/tacotron2.py +++ b/nemo/collections/tts/parts/tacotron2.py @@ -487,7 +487,7 @@ def infer(self, memory, memory_lengths): alignments += [alignment] if len(mel_outputs) == self.max_decoder_steps: - print("Warning! Reached max decoder steps") + logging.warning("Reached max decoder steps") break decoder_input = mel_output diff --git a/nemo/collections/tts/waveglow_modules.py b/nemo/collections/tts/waveglow_modules.py index b9f76e717243..954689b0bd3d 100644 --- a/nemo/collections/tts/waveglow_modules.py +++ b/nemo/collections/tts/waveglow_modules.py @@ -3,8 +3,9 @@ import numpy as np import torch -from .parts.waveglow import WaveGlow +from nemo import logging from nemo.backends.pytorch.nm import LossNM, TrainableNM +from nemo.collections.tts.parts.waveglow import WaveGlow from nemo.core.neural_types import * __all__ = ["WaveGlowNM", "WaveGlowInferNM", "WaveGlowLoss"] @@ -229,7 +230,7 @@ def denoise(self, audio, strength=0.1): def forward(self, mel_spectrogram): if not self._removed_weight_norm: - print("remove WN") + logging.info("remove WN") self.waveglow = self.waveglow.remove_weightnorm(self.waveglow) self._removed_weight_norm = True if self.training: diff --git a/nemo/core/neural_modules.py b/nemo/core/neural_modules.py index 663bb3da3184..94f0c7e5635b 100644 --- a/nemo/core/neural_modules.py +++ b/nemo/core/neural_modules.py @@ -19,6 +19,7 @@ NeuralTypeComparisonResult, NmTensor, ) +from nemo import logging from nemo.core import NeuralModuleFactory from nemo.utils.decorators.deprecated import deprecated @@ -71,11 +72,11 @@ def __init__( self._uuid = str(uuid.uuid4()) # if kwargs: - # nemo.logging.warning( + # logging.warning( # "When constructing {}. The base " # "NeuralModule class received the following unused " # "arguments:".format(self.__class__.__name__)) - # nemo.logging.warning("{}".format(kwargs.keys())) + # logging.warning("{}".format(kwargs.keys())) @deprecated() @staticmethod @@ -164,7 +165,7 @@ def __call__(self, **kwargs): ) ) if type_comatibility == NeuralTypeComparisonResult.LESS: - print('Types were raised') + logging.info('Types were raised') if len(output_port_defs) == 1: out_name = list(output_port_defs)[0] diff --git a/scripts/build_lm_text.py b/scripts/build_lm_text.py index d3b48f2bc442..197cfc5a2465 100644 --- a/scripts/build_lm_text.py +++ b/scripts/build_lm_text.py @@ -1,4 +1,5 @@ import argparse +import logging import os import pandas as pd @@ -16,10 +17,10 @@ lmplz_tmp = 'decoders/kenlm/build/bin/lmplz --text {} --arpa {} --o {}' command = lmplz_tmp.format(corpus_name, arpa_name, args.n) - print(command) + logging.info(command) os.system(command) tmp = 'decoders/kenlm/build/bin/build_binary trie -q 8 -b 7 -a 256 {} {}' command = tmp.format(arpa_name, lm_name) - print(command) + logging.info(command) os.system(command) diff --git a/scripts/convert_iob_format_to_token_classification_format.py b/scripts/convert_iob_format_to_token_classification_format.py index f9602216e307..e30345e547d8 100644 --- a/scripts/convert_iob_format_to_token_classification_format.py +++ b/scripts/convert_iob_format_to_token_classification_format.py @@ -13,6 +13,7 @@ # limitations under the License.**** import argparse +import logging import os @@ -63,9 +64,9 @@ def __convert_data(in_file, out_text, out_labels): "-NER/tree/master/data." ) - print(f'Processing {dataset}') + logging.info(f'Processing {dataset}') out_text = os.path.join(args.data_dir, 'text_' + dataset) out_labels = os.path.join(args.data_dir, 'labels_' + dataset) __convert_data(file_path, out_text, out_labels) - print(f'Processing of the {dataset} is complete') + logging.info(f'Processing of the {dataset} is complete') diff --git a/scripts/export_bert_to_trt.py b/scripts/export_bert_to_trt.py index a324da24b51f..566446a6f2aa 100644 --- a/scripts/export_bert_to_trt.py +++ b/scripts/export_bert_to_trt.py @@ -22,6 +22,8 @@ import tensorrt as trt import torch +from nemo import logging + nvinfer = ctypes.CDLL("libnvinfer_plugin.so", mode=ctypes.RTLD_GLOBAL) cm = ctypes.CDLL("libcommon.so", mode=ctypes.RTLD_GLOBAL) pg = ctypes.CDLL("libbert_plugins.so", mode=ctypes.RTLD_GLOBAL) @@ -37,10 +39,10 @@ gelu_plg_creator = plg_registry.get_plugin_creator("CustomGeluPluginDynamic", "1", "") emln_plg_creator = plg_registry.get_plugin_creator("CustomEmbLayerNormPluginDynamic", "1", "") -print( +logging.info( "creators:", plg_registry, qkv2_plg_creator, skln_plg_creator, gelu_plg_creator, emln_plg_creator, ) -print("\n".join([x.name for x in plg_registry.plugin_creator_list])) +logging.info("\n".join([x.name for x in plg_registry.plugin_creator_list])) """ Attentions Keys @@ -258,13 +260,13 @@ def squad_output(prefix, init_dict, network, input_tensor): def sequence_class_output(prefix, init_dict, network, input_tensor, softmax=True): - print(input_tensor.shape) + logging.info(input_tensor.shape) seq_len = input_tensor.shape[1] hidden_size = input_tensor.shape[2] shuf = network.add_shuffle(input_tensor) shuf.first_transpose = (0, 3, 4, 1, 2) - print("seq class in: ", shuf.get_output(0).shape) + logging.info("seq class in: ", shuf.get_output(0).shape) in_shape_tensor = network.add_shape(shuf.get_output(0)).get_output(0) out_shape_tensor = network.add_gather( @@ -296,7 +298,7 @@ def sequence_class_output(prefix, init_dict, network, input_tensor, softmax=True classifier.reshape_dims = trt.Dims([0, -1]) set_layer_name(classifier, prefix, "classifier") - print("seq class: ", classifier.get_output(0).shape) + logging.info("seq class: ", classifier.get_output(0).shape) return classifier @@ -317,7 +319,7 @@ def token_class_output(prefix, init_dict, network, input_tensor, softmax=True): classifier = network.add_shuffle(classifier.get_output(0)) classifier.reshape_dims = trt.Dims([0, 0, 0]) - print("tok class: ", classifier.get_output(0).shape) + logging.info("tok class: ", classifier.get_output(0).shape) return classifier @@ -550,8 +552,8 @@ def set_profile_shape(profile, batch_size, min_batch=None, max_batch=None): outputbase = opt.output config_path = opt.config - print("token class:", opt.token_classifier) - print("seq class: ", opt.seq_classifier) + logging.info("token class:", opt.token_classifier) + logging.info("seq class: ", opt.seq_classifier) main( opt.bert_weight, opt.class_weight, diff --git a/scripts/export_jasper_onnx_to_trt.py b/scripts/export_jasper_onnx_to_trt.py index e6d0988250c4..ca7b9f13d664 100644 --- a/scripts/export_jasper_onnx_to_trt.py +++ b/scripts/export_jasper_onnx_to_trt.py @@ -3,6 +3,8 @@ import onnx import tensorrt as trt +from nemo import logging + def build_engine( onnx_path, @@ -31,7 +33,7 @@ def build_engine( if trt_fp16: builder.fp16_mode = True - print("Optimizing for FP16") + logging.info("Optimizing for FP16") config_flags = 1 << int(trt.BuilderFlag.FP16) # | 1 << int(trt.BuilderFlag.STRICT_TYPES) else: config_flags = 0 @@ -58,7 +60,7 @@ def build_engine( with trt.OnnxParser(network, TRT_LOGGER) as parser: parsed = parser.parse(model) - print("Parsing returned ", parsed) + logging.info("Parsing returned ", parsed) return builder.build_engine(network, config=config) @@ -109,7 +111,7 @@ def get_parser(): if engine is not None: with open(args.trt_encoder, 'wb') as f: f.write(engine.serialize()) - print("TRT engine saved at " + args.trt_encoder + " ...") + logging.info("TRT engine saved at " + args.trt_encoder + " ...") engine = build_engine( args.onnx_decoder, @@ -123,4 +125,4 @@ def get_parser(): if engine is not None: with open(args.trt_decoder, 'wb') as f: f.write(engine.serialize()) - print("TRT engine saved at " + args.trt_decoder + " ...") + logging.info("TRT engine saved at " + args.trt_decoder + " ...") diff --git a/scripts/export_jasper_to_onnx.py b/scripts/export_jasper_to_onnx.py index 72a61503319b..84db7bddaf9a 100644 --- a/scripts/export_jasper_to_onnx.py +++ b/scripts/export_jasper_to_onnx.py @@ -43,11 +43,11 @@ def main( ): yaml = YAML(typ="safe") - print("Loading config file...") + logging.info("Loading config file...") with open(config_file) as f: jasper_model_definition = yaml.load(f) - print("Determining model shape...") + logging.info("Determining model shape...") if 'AudioPreprocessing' in jasper_model_definition: num_encoder_input_features = jasper_model_definition['AudioPreprocessing']['features'] elif 'AudioToMelSpectrogramPreprocessor' in jasper_model_definition: @@ -55,10 +55,10 @@ def main( else: num_encoder_input_features = 64 num_decoder_input_features = jasper_model_definition['JasperEncoder']['jasper'][-1]['filters'] - print(" Num encoder input features: {}".format(num_encoder_input_features)) - print(" Num decoder input features: {}".format(num_decoder_input_features)) + logging.info(" Num encoder input features: {}".format(num_encoder_input_features)) + logging.info(" Num decoder input features: {}".format(num_decoder_input_features)) - print("Initializing models...") + logging.info("Initializing models...") jasper_encoder = nemo_asr.JasperEncoder( feat_in=num_encoder_input_features, **jasper_model_definition['JasperEncoder'] ) @@ -68,9 +68,9 @@ def main( # This is necessary if you are using checkpoints trained with NeMo # version before 0.9 - print("Loading checkpoints...") + logging.info("Loading checkpoints...") if pre_v09_model: - print(" Converting pre v0.9 checkpoint...") + logging.info(" Converting pre v0.9 checkpoint...") ckpt = torch.load(nn_encoder) new_ckpt = {} for k, v in ckpt.items(): @@ -84,21 +84,21 @@ def main( jasper_decoder.restore_from(nn_decoder) nf = nemo.core.NeuralModuleFactory(create_tb_writer=False) - print("Exporting encoder...") + logging.info("Exporting encoder...") nf.deployment_export( jasper_encoder, nn_onnx_encoder, nemo.core.neural_factory.DeploymentFormat.ONNX, torch.zeros(batch_size, num_encoder_input_features, time_steps, dtype=torch.float, device="cuda:0",), ) - print("Exporting decoder...") + logging.info("Exporting decoder...") nf.deployment_export( jasper_decoder, nn_onnx_decoder, nemo.core.neural_factory.DeploymentFormat.ONNX, (torch.zeros(batch_size, num_decoder_input_features, time_steps // 2, dtype=torch.float, device="cuda:0",)), ) - print("Export completed successfully.") + logging.info("Export completed successfully.") if __name__ == "__main__": diff --git a/scripts/fisher_audio_to_wav.py b/scripts/fisher_audio_to_wav.py index 94507b5451ce..0400a421faae 100644 --- a/scripts/fisher_audio_to_wav.py +++ b/scripts/fisher_audio_to_wav.py @@ -10,6 +10,7 @@ import argparse import concurrent.futures import glob +import logging import os import subprocess @@ -70,13 +71,13 @@ def main(): data_root = args.data_root dest_root = args.dest_root - print("\n\nConverting audio for Part 1") + logging.info("\n\nConverting audio for Part 1") __process_set( os.path.join(data_root, "LDC2004S13-Part1", "fisher_eng_tr_sp_d*", "audio", "*", "*.sph",), os.path.join(dest_root, "LDC2004S13-Part1", "audio_wav"), ) - print("\n\nConverting audio for Part 2") + logging.info("\n\nConverting audio for Part 2") __process_set( os.path.join(data_root, "LDC2005S13-Part2", "fe_03_p2_sph*", "audio", "*", "*.sph",), os.path.join(dest_root, "LDC2005S13-Part2", "audio_wav"), diff --git a/scripts/get_aishell_data.py b/scripts/get_aishell_data.py index 5e8c00c7cdae..f054d980c9ee 100644 --- a/scripts/get_aishell_data.py +++ b/scripts/get_aishell_data.py @@ -4,6 +4,7 @@ import argparse import json +import logging import os import subprocess import tarfile @@ -29,12 +30,12 @@ def __maybe_download_file(destination: str, source: str): """ source = URL[source] if not os.path.exists(destination): - print("{0} does not exist. Downloading ...".format(destination)) + logging.info("{0} does not exist. Downloading ...".format(destination)) urllib.request.urlretrieve(source, filename=destination + '.tmp') os.rename(destination + '.tmp', destination) - print("Downloaded {0}.".format(destination)) + logging.info("Downloaded {0}.".format(destination)) else: - print("Destination {0} exists. Skipping.".format(destination)) + logging.info("Destination {0} exists. Skipping.".format(destination)) return destination @@ -46,7 +47,7 @@ def __extract_all_files(filepath: str, data_root: str, data_dir: str): for ftar in filelist: extract_file(os.path.join(subfolder, ftar), subfolder) else: - print('Skipping extracting. Data already there %s' % data_dir) + logging.info('Skipping extracting. Data already there %s' % data_dir) def extract_file(filepath: str, data_dir: str): @@ -55,7 +56,7 @@ def extract_file(filepath: str, data_dir: str): tar.extractall(data_dir) tar.close() except Exception: - print('Not extracting. Maybe already there?') + logging.info('Not extracting. Maybe already there?') def __process_data(data_folder: str, dst_folder: str): @@ -119,16 +120,16 @@ def __process_data(data_folder: str, dst_folder: str): def main(): data_root = args.data_root data_set = 'data_aishell' - print("\n\nWorking on: {0}".format(data_set)) + logging.info("\n\nWorking on: {0}".format(data_set)) file_path = os.path.join(data_root, data_set + ".tgz") - print("Getting {0}".format(data_set)) + logging.info("Getting {0}".format(data_set)) __maybe_download_file(file_path, data_set) - print("Extracting {0}".format(data_set)) + logging.info("Extracting {0}".format(data_set)) data_folder = os.path.join(data_root, data_set) __extract_all_files(file_path, data_root, data_folder) - print("Processing {0}".format(data_set)) + logging.info("Processing {0}".format(data_set)) __process_data(data_folder, data_folder) - print('Done!') + logging.info('Done!') if __name__ == "__main__": diff --git a/scripts/get_databaker_data.py b/scripts/get_databaker_data.py index bc044f1a0576..f60bff264506 100644 --- a/scripts/get_databaker_data.py +++ b/scripts/get_databaker_data.py @@ -19,6 +19,7 @@ import argparse import glob import json +import logging import os import random import urllib.request @@ -43,12 +44,12 @@ def __maybe_download_file(destination, source): """ source = URLS[source] if not os.path.exists(destination): - print("{0} does not exist. Downloading ...".format(destination)) + logging.info("{0} does not exist. Downloading ...".format(destination)) urllib.request.urlretrieve(source, filename=destination + ".tmp") os.rename(destination + ".tmp", destination) - print("Downloaded {0}.".format(destination)) + logging.info("Downloaded {0}.".format(destination)) else: - print("Destination {0} exists. Skipping.".format(destination)) + logging.info("Destination {0} exists. Skipping.".format(destination)) return destination @@ -68,16 +69,16 @@ def __extract_rar(rar_path, dest_dir): "Please install unrar and run the script again.\n" "On Ubuntu/Debian, run: sudo apt-get install unrar -y" ) - print(message) + logging.info(message) exit(1) os.makedirs(dest_dir) - print("Extracting... This might take a few minutes.", flush=True) + logging.info("Extracting... This might take a few minutes.", flush=True) status = os.system("unrar x {0} {1} > /dev/null".format(rar_path, dest_dir)) if status != 0: - print("Extraction failed.") + logging.info("Extraction failed.") exit(1) else: - print("Skipping extracting. Data already there {0}.".format(data_dir)) + logging.info("Skipping extracting. Data already there {0}.".format(data_dir)) def __convert_waves(wavedir, converted_wavedir, wavename, sr): @@ -143,14 +144,14 @@ def __prepare_databaker_csmsc(data_root, train_size, sr=22050): "Ltd. Supports Non-Commercial use only. \nFor more info about this" " dataset, visit: https://www.data-baker.com/open_source.html" ) - print(copyright_statement) + logging.info(copyright_statement) rar_path = os.path.join(data_root, dataset_name + '.rar') dataset_dir = os.path.join(data_root, dataset_name) __maybe_download_file(rar_path, dataset_name) __extract_rar(rar_path, dataset_dir) wavedir = os.path.join(dataset_dir, "Wave") wavepaths = glob.glob(os.path.join(wavedir, "*.wav")) - print( + logging.info( "Found {} wav files, converting them to {} HZ sample rate...".format(len(wavepaths), sr), flush=True, ) converted_wavedir = os.path.join(dataset_dir, str(sr)) @@ -166,7 +167,7 @@ def __prepare_databaker_csmsc(data_root, train_size, sr=22050): wavename, dur = duration.result() duration_dict[wavename] = dur del durations - print("Phoneticizing transcripts...", flush=True) + logging.info("Phoneticizing transcripts...", flush=True) transcriptfile = os.path.join(dataset_dir, "ProsodyLabeling", "000001-010000.txt") with open(transcriptfile, "r", encoding="utf-8") as f: all_lines = f.readlines() @@ -187,7 +188,7 @@ def __prepare_databaker_csmsc(data_root, train_size, sr=22050): eval_wavenames = wavenames[train_num:] train_lines = [] eval_lines = [] - print("Generating Manifest...", flush=True) + logging.info("Generating Manifest...", flush=True) for wavename in tqdm(train_wavenames): tmp_dict = {} tmp_dict["audio_filepath"] = os.path.join(converted_wavedir, wavename) @@ -212,7 +213,7 @@ def __prepare_databaker_csmsc(data_root, train_size, sr=22050): with open(os.path.join(data_root, ev_mani), "w", encoding="utf-8") as f: for line in eval_lines: f.write("%s\n" % line) - print("Complete.") + logging.info("Complete.") def main(): @@ -223,7 +224,7 @@ def main(): args = parser.parse_args() if args.train_size > 1 or args.train_size <= 0: - print("train_size should > 0 and <= 1") + logging.info("train_size should > 0 and <= 1") if not os.path.exists(args.data_root): os.makedirs(args.data_root) @@ -231,7 +232,7 @@ def main(): if args.dataset_name == 'databaker_csmsc': __prepare_databaker_csmsc(args.data_root, args.train_size) else: - print("Unsupported dataset.") + logging.info("Unsupported dataset.") if __name__ == "__main__": diff --git a/scripts/get_librispeech_data.py b/scripts/get_librispeech_data.py index 68b24ce6adbc..4975b507c906 100755 --- a/scripts/get_librispeech_data.py +++ b/scripts/get_librispeech_data.py @@ -9,6 +9,7 @@ import argparse import fnmatch import json +import logging import os import subprocess import tarfile @@ -46,12 +47,12 @@ def __maybe_download_file(destination: str, source: str): """ source = URLS[source] if not os.path.exists(destination): - print("{0} does not exist. Downloading ...".format(destination)) + logging.info("{0} does not exist. Downloading ...".format(destination)) urllib.request.urlretrieve(source, filename=destination + '.tmp') os.rename(destination + '.tmp', destination) - print("Downloaded {0}.".format(destination)) + logging.info("Downloaded {0}.".format(destination)) else: - print("Destination {0} exists. Skipping.".format(destination)) + logging.info("Destination {0} exists. Skipping.".format(destination)) return destination @@ -61,7 +62,7 @@ def __extract_file(filepath: str, data_dir: str): tar.extractall(data_dir) tar.close() except Exception: - print('Not extracting. Maybe already there?') + logging.info('Not extracting. Maybe already there?') def __process_data(data_folder: str, dst_folder: str, manifest_file: str): @@ -119,19 +120,19 @@ def main(): data_sets = "dev_clean,dev_other,train_clean_100,train_clean_360," "train_other_500,test_clean,test_other" for data_set in data_sets.split(','): - print("\n\nWorking on: {0}".format(data_set)) + logging.info("\n\nWorking on: {0}".format(data_set)) filepath = os.path.join(data_root, data_set + ".tar.gz") - print("Getting {0}".format(data_set)) + logging.info("Getting {0}".format(data_set)) __maybe_download_file(filepath, data_set.upper()) - print("Extracting {0}".format(data_set)) + logging.info("Extracting {0}".format(data_set)) __extract_file(filepath, data_root) - print("Processing {0}".format(data_set)) + logging.info("Processing {0}".format(data_set)) __process_data( os.path.join(os.path.join(data_root, "LibriSpeech"), data_set.replace("_", "-"),), os.path.join(os.path.join(data_root, "LibriSpeech"), data_set.replace("_", "-"),) + "-processed", os.path.join(data_root, data_set + ".json"), ) - print('Done!') + logging.info('Done!') if __name__ == "__main__": diff --git a/scripts/get_ljspeech_data.py b/scripts/get_ljspeech_data.py index 7ca160921a95..5d5701a89a33 100644 --- a/scripts/get_ljspeech_data.py +++ b/scripts/get_ljspeech_data.py @@ -4,6 +4,7 @@ import argparse import json +import logging import os import random import tarfile @@ -27,12 +28,12 @@ def __maybe_download_file(destination: str, source: str): """ source = URL if not os.path.exists(destination): - print(f"{destination} does not exist. Downloading ...") + logging.info(f"{destination} does not exist. Downloading ...") urllib.request.urlretrieve(source, filename=destination + '.tmp') os.rename(destination + '.tmp', destination) - print(f"Downloaded {destination}.") + logging.info(f"Downloaded {destination}.") else: - print(f"Destination {destination} exists. Skipping.") + logging.info(f"Destination {destination} exists. Skipping.") return destination @@ -44,7 +45,7 @@ def __extract_all_files(filepath: str, data_root: str, data_dir: str): for ftar in filelist: extract_file(os.path.join(subfolder, ftar), subfolder) else: - print(f'Skipping extracting. Data already there {data_dir}') + logging.info(f'Skipping extracting. Data already there {data_dir}') def extract_file(filepath: str, data_dir: str): @@ -53,7 +54,7 @@ def extract_file(filepath: str, data_dir: str): tar.extractall(data_dir) tar.close() except Exception: - print('Not extracting. Maybe already there?') + logging.info('Not extracting. Maybe already there?') def __process_data(data_folder: str, dst_folder: str): @@ -111,19 +112,19 @@ def main(): data_set = "LJSpeech-1.1" data_folder = os.path.join(data_root, data_set) - print(f"Working on: {data_set}") + logging.info(f"Working on: {data_set}") # Download and extract if not os.path.exists(data_folder): file_path = os.path.join(data_root, data_set + ".tar.bz2") - print(f"Getting {data_set}") + logging.info(f"Getting {data_set}") __maybe_download_file(file_path, data_set) - print(f"Extracting {data_set}") + logging.info(f"Extracting {data_set}") __extract_all_files(file_path, data_root, data_folder) - print(f"Processing {data_set}") + logging.info(f"Processing {data_set}") __process_data(data_folder, data_folder) - print('Done!') + logging.info('Done!') if __name__ == "__main__": diff --git a/scripts/get_tatoeba_data.py b/scripts/get_tatoeba_data.py index e714c3ee43a3..47cb09791b72 100644 --- a/scripts/get_tatoeba_data.py +++ b/scripts/get_tatoeba_data.py @@ -13,6 +13,7 @@ # limitations under the License.**** import argparse +import logging import os import random import re @@ -33,8 +34,8 @@ def __maybe_download_file(destination: str, source: str): """ source = URL[source] if not os.path.exists(destination): - print(f'Downloading {source}') - print( + logging.info(f'Downloading {source}') + logging.info( f'Downloading could take a long time ' + 'To get the data faster consider running in a terminal:\n' + 'wget https://downloads.tatoeba.org/exports/sentences.csv\n' @@ -202,11 +203,11 @@ def __delete_file(file_to_del): if args.dataset != 'tatoeba': raise ValueError("Unsupported dataset.") - print(f'Downloading tatoeba dataset') + logging.info(f'Downloading tatoeba dataset') tatoeba_dataset = os.path.join(args.data_dir, 'sentences.csv') __maybe_download_file(tatoeba_dataset, args.dataset) - print(f'Processing English sentences...') + logging.info(f'Processing English sentences...') clean_eng_sentences = os.path.join(args.data_dir, 'clean_eng_sentences.txt') __process_english_sentences( tatoeba_dataset, clean_eng_sentences, args.percent_to_cut, args.num_lines_to_combine, args.num_samples, @@ -215,17 +216,19 @@ def __delete_file(file_to_del): train_file = os.path.join(args.data_dir, 'train.txt') dev_file = os.path.join(args.data_dir, 'dev.txt') - print(f'Splitting the {args.dataset} dataset into train and dev sets' + ' and creating labels and text files') + logging.info( + f'Splitting the {args.dataset} dataset into train and dev sets' + ' and creating labels and text files' + ) __split_into_train_dev(clean_eng_sentences, train_file, dev_file, args.percent_dev) - print(f'Creating text and label files for training') + logging.info(f'Creating text and label files for training') __create_text_and_labels(args.data_dir, 'train.txt') __create_text_and_labels(args.data_dir, 'dev.txt') if args.clean_dir: - print(f'Cleaning up {args.data_dir}') + logging.info(f'Cleaning up {args.data_dir}') __delete_file(clean_eng_sentences) __delete_file(tatoeba_dataset) __delete_file(train_file) __delete_file(dev_file) - print(f'Processing of the {args.dataset} is complete') + logging.info(f'Processing of the {args.dataset} is complete') diff --git a/scripts/get_timit_data.py b/scripts/get_timit_data.py index c0b52b185d3a..ea70404b080c 100644 --- a/scripts/get_timit_data.py +++ b/scripts/get_timit_data.py @@ -5,6 +5,7 @@ import argparse import fnmatch import json +import logging import os import subprocess import sys @@ -217,13 +218,13 @@ def __process_data(data_folder: str, dst_folder: str): elif spk in TEST_LIST and 'SA' not in filename: files_test.append(os.path.join(r, filename)) - print("Training samples:" + str(len(files_train))) - print("Validation samples:" + str(len(files_dev))) - print("Test samples:" + str(len(files_test))) + logging.info("Training samples:" + str(len(files_train))) + logging.info("Validation samples:" + str(len(files_dev))) + logging.info("Test samples:" + str(len(files_test))) for data_set in ['train', 'dev', 'test']: - print("Processing: " + data_set) + logging.info("Processing: " + data_set) entries = [] if data_set == 'train': files = files_train @@ -260,7 +261,7 @@ def main(): data_new_root = args.data_new_root __process_data(data_root, data_new_root) - print('Done!') + logging.info('Done!') if __name__ == "__main__": diff --git a/scripts/process_aishell2_data.py b/scripts/process_aishell2_data.py index 3cab5b55950a..38db95cba282 100644 --- a/scripts/process_aishell2_data.py +++ b/scripts/process_aishell2_data.py @@ -5,6 +5,7 @@ # --dest_folder= import argparse import json +import logging import os import subprocess import sys @@ -93,10 +94,10 @@ def __get_vocab(data_folder: str, des_dir: str): def main(): source_data = args.audio_folder des_dir = args.dest_folder - print("begin to process data...") + logging.info("begin to process data...") __process_data(source_data, des_dir) __get_vocab(source_data, des_dir) - print("finish all!") + logging.info("finish all!") if __name__ == "__main__": diff --git a/scripts/process_an4_data.py b/scripts/process_an4_data.py index 69e67b7ae69a..10e018c4df24 100644 --- a/scripts/process_an4_data.py +++ b/scripts/process_an4_data.py @@ -14,6 +14,7 @@ import argparse import glob import json +import logging import os import subprocess import tarfile @@ -57,30 +58,30 @@ def main(): data_root = os.path.abspath(args.data_root) # Convert from .sph to .wav - print("Converting audio files to .wav...") + logging.info("Converting audio files to .wav...") sph_list = glob.glob(os.path.join(data_root, 'an4/**/*.sph'), recursive=True) for sph_path in sph_list: wav_path = sph_path[:-4] + '.wav' cmd = ['sox', sph_path, wav_path] subprocess.run(cmd) - print("Finished conversion.") + logging.info("Finished conversion.") # Build manifests - print("Building training manifest...") + logging.info("Building training manifest...") train_transcripts = os.path.join(data_root, 'an4/etc/an4_train.transcription') train_manifest = os.path.join(data_root, 'an4/train_manifest.json') train_wavs = os.path.join(data_root, 'an4/wav/an4_clstk') build_manifest(data_root, train_transcripts, train_manifest, train_wavs) - print("Training manifests created.") + logging.info("Training manifests created.") - print("Building test manifest...") + logging.info("Building test manifest...") test_transcripts = os.path.join(data_root, 'an4/etc/an4_test.transcription') test_manifest = os.path.join(data_root, 'an4/test_manifest.json') test_wavs = os.path.join(data_root, 'an4/wav/an4test_clstk') build_manifest(data_root, test_transcripts, test_manifest, test_wavs) - print("Test manifest created.") + logging.info("Test manifest created.") - print("Done with AN4 processing!") + logging.info("Done with AN4 processing!") if __name__ == '__main__': diff --git a/tests/asr/test_asr.py b/tests/asr/test_asr.py index 1f21df4f07e0..f3aeb12ee81c 100644 --- a/tests/asr/test_asr.py +++ b/tests/asr/test_asr.py @@ -1,16 +1,3 @@ -# Copyright (c) 2019 NVIDIA Corporation -import os -import shutil -import tarfile - -from ruamel.yaml import YAML - -import nemo -import nemo.collections.asr as nemo_asr -from nemo.collections.asr.parts import AudioDataset, WaveformFeaturizer, collections, parsers -from nemo.core import DeviceType -from tests.common_setup import NeMoUnitTest - # ! /usr/bin/python # -*- coding: utf-8 -*- @@ -28,8 +15,19 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================= +import os +import shutil +import tarfile + +from ruamel.yaml import YAML +import nemo +import nemo.collections.asr as nemo_asr +from nemo.collections.asr.parts import AudioDataset, WaveformFeaturizer, collections, parsers +from nemo.core import DeviceType +from tests.common_setup import NeMoUnitTest +logging = nemo.logging freq = 16000 @@ -83,20 +81,20 @@ class TestASRPytorch(NeMoUnitTest): def setUpClass(cls) -> None: super().setUpClass() data_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data/")) - print("Looking up for test ASR data") + logging.info("Looking up for test ASR data") if not os.path.exists(os.path.join(data_folder, "asr")): - print("Extracting ASR data to: {0}".format(os.path.join(data_folder, "asr"))) + logging.info("Extracting ASR data to: {0}".format(os.path.join(data_folder, "asr"))) tar = tarfile.open(os.path.join(data_folder, "asr.tar.gz"), "r:gz") tar.extractall(path=data_folder) tar.close() else: - print("ASR data found in: {0}".format(os.path.join(data_folder, "asr"))) + logging.info("ASR data found in: {0}".format(os.path.join(data_folder, "asr"))) @classmethod def tearDownClass(cls) -> None: super().tearDownClass() data_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data/")) - print("Looking up for test ASR data") + logging.info("Looking up for test ASR data") if os.path.exists(os.path.join(data_folder, "asr")): shutil.rmtree(os.path.join(data_folder, "asr")) @@ -175,8 +173,8 @@ def test_pytorch_audio_dataset(self): for i in range(len(ds)): if i == 5: - print(ds[i]) - # print(ds[i][0].shape) + logging.info(ds[i]) + # logging.info(ds[i][0].shape) # self.assertEqual(freq, ds[i][0].shape[0]) def test_dataloader(self): @@ -358,14 +356,14 @@ def test_jasper_training(self): processed_signal, p_length = preprocessing(input_signal=audio_signal, length=a_sig_length) encoded, encoded_len = jasper_encoder(audio_signal=processed_signal, length=p_length) - # print(jasper_encoder) + # logging.info(jasper_encoder) log_probs = jasper_decoder(encoder_output=encoded) loss = ctc_loss( log_probs=log_probs, targets=transcript, input_length=encoded_len, target_length=transcript_len, ) callback = nemo.core.SimpleLossLoggerCallback( - tensors=[loss], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[loss], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( @@ -427,7 +425,9 @@ def test_double_jasper_training(self): log_probs=log_probs, targets=transcript, input_length=encoded_len, target_length=transcript_len, ) - callback = nemo.core.SimpleLossLoggerCallback(tensors=[loss], print_func=lambda x: print(str(x[0].item()))) + callback = nemo.core.SimpleLossLoggerCallback( + tensors=[loss], print_func=lambda x: logging.info(str(x[0].item())) + ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( backend=nemo.core.Backend.PyTorch, local_rank=None, create_tb_writer=False, @@ -478,7 +478,7 @@ def test_quartznet_training(self): ) callback = nemo.core.SimpleLossLoggerCallback( - tensors=[loss], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[loss], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( @@ -525,13 +525,15 @@ def test_stft_conv(self): processed_signal, p_length = preprocessing(input_signal=audio_signal, length=a_sig_length) encoded, encoded_len = jasper_encoder(audio_signal=processed_signal, length=p_length) - # print(jasper_encoder) + # logging.info(jasper_encoder) log_probs = jasper_decoder(encoder_output=encoded) loss = ctc_loss( log_probs=log_probs, targets=transcript, input_length=encoded_len, target_length=transcript_len, ) - callback = nemo.core.SimpleLossLoggerCallback(tensors=[loss], print_func=lambda x: print(str(x[0].item()))) + callback = nemo.core.SimpleLossLoggerCallback( + tensors=[loss], print_func=lambda x: logging.info(str(x[0].item())) + ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( backend=nemo.core.Backend.PyTorch, local_rank=None, create_tb_writer=False, @@ -586,7 +588,9 @@ def test_clas(self): loss = loss(log_probs=log_probs, targets=transcripts) # Train - callback = nemo.core.SimpleLossLoggerCallback(tensors=[loss], print_func=lambda x: print(str(x[0].item()))) + callback = nemo.core.SimpleLossLoggerCallback( + tensors=[loss], print_func=lambda x: logging.info(str(x[0].item())) + ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( backend=nemo.core.Backend.PyTorch, local_rank=None, create_tb_writer=False, @@ -630,7 +634,7 @@ def test_jasper_eval(self): processed_signal, p_length = preprocessing(input_signal=audio_signal, length=a_sig_length) encoded, encoded_len = jasper_encoder(audio_signal=processed_signal, length=p_length) - # print(jasper_encoder) + # logging.info(jasper_encoder) log_probs = jasper_decoder(encoder_output=encoded) loss = ctc_loss( log_probs=log_probs, targets=transcript, input_length=encoded_len, target_length=transcript_len, diff --git a/tests/asr/test_weight_share.py b/tests/asr/test_weight_share.py index b5840630d1fd..4bc1d6125da9 100644 --- a/tests/asr/test_weight_share.py +++ b/tests/asr/test_weight_share.py @@ -31,6 +31,8 @@ from nemo.core.neural_types import * from tests.common_setup import NeMoUnitTest +logging = nemo.logging + class TestWeightSharing(NeMoUnitTest): labels = [ @@ -82,20 +84,20 @@ class TestWeightSharing(NeMoUnitTest): def setUpClass(cls) -> None: super().setUpClass() data_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data/")) - print("Looking up for test ASR data") + logging.info("Looking up for test ASR data") if not os.path.exists(os.path.join(data_folder, "asr")): - print("Extracting ASR data to: {0}".format(os.path.join(data_folder, "asr"))) + logging.info("Extracting ASR data to: {0}".format(os.path.join(data_folder, "asr"))) tar = tarfile.open(os.path.join(data_folder, "asr.tar.gz"), "r:gz") tar.extractall(path=data_folder) tar.close() else: - print("ASR data found in: {0}".format(os.path.join(data_folder, "asr"))) + logging.info("ASR data found in: {0}".format(os.path.join(data_folder, "asr"))) @classmethod def tearDownClass(cls) -> None: super().tearDownClass() data_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data/")) - print("Looking up for test ASR data") + logging.info("Looking up for test ASR data") if os.path.exists(os.path.join(data_folder, "asr")): shutil.rmtree(os.path.join(data_folder, "asr")) @@ -202,14 +204,14 @@ def test_freeze_unfreeze_TrainableNM(self): processed_signal, p_length = preprocessing(input_signal=audio_signal, length=a_sig_length) encoded, encoded_len = jasper_encoder(audio_signal=processed_signal, length=p_length) - # print(jasper_encoder) + # logging.info(jasper_encoder) log_probs = jasper_decoder(encoder_output=encoded) loss = ctc_loss( log_probs=log_probs, targets=transcript, input_length=encoded_len, target_length=transcript_len, ) callback = nemo.core.SimpleLossLoggerCallback( - tensors=[loss], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[loss], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( @@ -259,7 +261,7 @@ def test_freeze_unfreeze_Wrapper(self): train_loss = L_train(predictions=outputs, labels=labels) callback = nemo.core.SimpleLossLoggerCallback( - tensors=[train_loss], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[train_loss], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( diff --git a/tests/asr/test_zeroDS.py b/tests/asr/test_zeroDS.py index 304d63d67d9e..6197d74cc014 100644 --- a/tests/asr/test_zeroDS.py +++ b/tests/asr/test_zeroDS.py @@ -28,6 +28,8 @@ from nemo.core.neural_types import * from tests.common_setup import NeMoUnitTest +logging = nemo.logging + class TestZeroDL(NeMoUnitTest): labels = [ @@ -67,25 +69,25 @@ class TestZeroDL(NeMoUnitTest): def setUpClass(cls) -> None: super().setUpClass() data_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data/")) - print("Looking up for test ASR data") + logging.info("Looking up for test ASR data") if not os.path.exists(os.path.join(data_folder, "asr")): - print("Extracting ASR data to: {0}".format(os.path.join(data_folder, "asr"))) + logging.info("Extracting ASR data to: {0}".format(os.path.join(data_folder, "asr"))) tar = tarfile.open(os.path.join(data_folder, "asr.tar.gz"), "r:gz") tar.extractall(path=data_folder) tar.close() else: - print("ASR data found in: {0}".format(os.path.join(data_folder, "asr"))) + logging.info("ASR data found in: {0}".format(os.path.join(data_folder, "asr"))) @classmethod def tearDownClass(cls) -> None: super().tearDownClass() data_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data/")) - print("Looking up for test ASR data") + logging.info("Looking up for test ASR data") if os.path.exists(os.path.join(data_folder, "asr")): shutil.rmtree(os.path.join(data_folder, "asr")) def test_simple_train(self): - print("Simplest train test with ZeroDL") + logging.info("Simplest train test with ZeroDL") neural_factory = nemo.core.neural_factory.NeuralModuleFactory( backend=nemo.core.Backend.PyTorch, create_tb_writer=False ) @@ -105,14 +107,14 @@ def test_simple_train(self): loss_tensor = loss(predictions=y_pred, target=y) callback = nemo.core.SimpleLossLoggerCallback( - tensors=[loss_tensor], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[loss_tensor], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) neural_factory.train( [loss_tensor], callbacks=[callback], optimization_params={"num_epochs": 3, "lr": 0.0003}, optimizer="sgd", ) def test_asr_with_zero_ds(self): - print("Testing ASR NMs with ZeroDS and without pre-processing") + logging.info("Testing ASR NMs with ZeroDS and without pre-processing") path = os.path.abspath(os.path.join(os.path.dirname(__file__), "../data/jasper_smaller.yaml")) with open(path) as file: jasper_model_definition = self.yaml.load(file) @@ -145,14 +147,14 @@ def test_asr_with_zero_ds(self): # DAG processed_signal, p_length, transcript, transcript_len = dl() encoded, encoded_len = jasper_encoder(audio_signal=processed_signal, length=p_length) - # print(jasper_encoder) + # logging.info(jasper_encoder) log_probs = jasper_decoder(encoder_output=encoded) loss = ctc_loss( log_probs=log_probs, targets=transcript, input_length=encoded_len, target_length=transcript_len, ) callback = nemo.core.SimpleLossLoggerCallback( - tensors=[loss], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[loss], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( diff --git a/tests/common_setup.py b/tests/common_setup.py index d98e2e54cce7..6d9a1e30f234 100644 --- a/tests/common_setup.py +++ b/tests/common_setup.py @@ -20,10 +20,12 @@ import nemo +logging = nemo.logging + class NeMoUnitTest(unittest.TestCase): def setUp(self) -> None: nemo.core.neural_factory.NeuralModuleFactory.reset_default_factory() - print("---------------------------------------------------------") - print(self._testMethodName) - print("---------------------------------------------------------") + logging.info("---------------------------------------------------------") + logging.info(self._testMethodName) + logging.info("---------------------------------------------------------") diff --git a/tests/test_neural_types.py b/tests/test_neural_types.py index efcfff2065f7..eb52abcffd7b 100644 --- a/tests/test_neural_types.py +++ b/tests/test_neural_types.py @@ -21,6 +21,7 @@ from ruamel.yaml import YAML import nemo.collections.asr as nemo_asr +from nemo import logging from nemo.core import * from tests.common_setup import NeMoUnitTest @@ -32,14 +33,14 @@ class TestNeuralTypes(NeMoUnitTest): def setUp(self) -> None: super().setUp() data_folder = "tests/data/" - print("Looking up for test ASR data") + logging.info("Looking up for test ASR data") if not os.path.exists(data_folder + "asr"): - print("Extracting ASR data to: {0}".format(data_folder + "asr")) + logging.info("Extracting ASR data to: {0}".format(data_folder + "asr")) tar = tarfile.open("tests/data/asr.tar.gz", "r:gz") tar.extractall(path=data_folder) tar.close() else: - print("ASR data found in: {0}".format(data_folder + "asr")) + logging.info("ASR data found in: {0}".format(data_folder + "asr")) def test_same(self): btc = NeuralType(axis2type={0: AxisType(BatchTag), 1: AxisType(TimeTag), 2: AxisType(ChannelTag),}) diff --git a/tests/test_pytorch_trainers.py b/tests/test_pytorch_trainers.py index 9638b3f3ab15..583f26709478 100644 --- a/tests/test_pytorch_trainers.py +++ b/tests/test_pytorch_trainers.py @@ -19,10 +19,12 @@ import nemo from tests.common_setup import NeMoUnitTest +logging = nemo.logging + class TestPytorchTrainers(NeMoUnitTest): def test_simple_train(self): - print("Simplest train test") + logging.info("Simplest train test") data_source = nemo.backends.pytorch.tutorials.RealFunctionDataLayer(n=10000, batch_size=128) trainable_module = nemo.backends.pytorch.tutorials.TaylorNet(dim=4) loss = nemo.backends.pytorch.tutorials.MSELoss() @@ -36,7 +38,7 @@ def test_simple_train(self): ) def test_simple_train_named_output(self): - print('Simplest train test with using named output.') + logging.info('Simplest train test with using named output.') data_source = nemo.backends.pytorch.tutorials.RealFunctionDataLayer(n=10000, batch_size=128,) trainable_module = nemo.backends.pytorch.tutorials.TaylorNet(dim=4) loss = nemo.backends.pytorch.tutorials.MSELoss() @@ -56,7 +58,7 @@ def test_simple_train_named_output(self): ) def test_simple_chained_train(self): - print("Chained train test") + logging.info("Chained train test") data_source = nemo.backends.pytorch.tutorials.RealFunctionDataLayer(n=10000, batch_size=32) trainable_module1 = nemo.backends.pytorch.tutorials.TaylorNet(dim=4) trainable_module2 = nemo.backends.pytorch.tutorials.TaylorNet(dim=2) diff --git a/tests/test_tutorials_pytorch.py b/tests/test_tutorials_pytorch.py index 30bbf98c846d..183fd67e1d1b 100644 --- a/tests/test_tutorials_pytorch.py +++ b/tests/test_tutorials_pytorch.py @@ -23,7 +23,7 @@ # class TestPytorchChatBotTutorial(NeMoUnitTest): # def test_simple_train(self): # datafile = "tests/data/dialog_sample.txt" -# print(datafile) +# logging.info(datafile) # voc, pairs = loadPrepareData("cornell", datafile=datafile) # self.assertEqual(voc.name, 'cornell') # self.assertEqual(voc.num_words, 675) diff --git a/tests/tts/test_tts.py b/tests/tts/test_tts.py index f867cce001ab..a6b0c0421c0e 100644 --- a/tests/tts/test_tts.py +++ b/tests/tts/test_tts.py @@ -24,6 +24,8 @@ import nemo.collections.tts as nemo_tts from tests.common_setup import NeMoUnitTest +logging = nemo.logging + class TestTTSPytorch(NeMoUnitTest): labels = [ @@ -61,14 +63,14 @@ class TestTTSPytorch(NeMoUnitTest): def setUp(self) -> None: super().setUp() data_folder = "tests/data/" - print("Looking up for test speech data") + logging.info("Looking up for test speech data") if not os.path.exists(data_folder + "asr"): - print("Extracting speech data to: {0}".format(data_folder + "asr")) + logging.info("Extracting speech data to: {0}".format(data_folder + "asr")) tar = tarfile.open("tests/data/asr.tar.gz", "r:gz") tar.extractall(path=data_folder) tar.close() else: - print("speech data found in: {0}".format(data_folder + "asr")) + logging.info("speech data found in: {0}".format(data_folder + "asr")) def test_tacotron2_training(self): data_layer = nemo_asr.AudioToTextDataLayer( @@ -130,7 +132,7 @@ def test_tacotron2_training(self): ) callback = nemo.core.SimpleLossLoggerCallback( - tensors=[loss_t], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[loss_t], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory( @@ -174,7 +176,7 @@ def test_waveglow_training(self): loss_t = waveglow_loss(z=z, log_s_list=log_s_list, log_det_W_list=log_det_W_list) callback = nemo.core.SimpleLossLoggerCallback( - tensors=[loss_t], print_func=lambda x: print(f'Train Loss: {str(x[0].item())}'), + tensors=[loss_t], print_func=lambda x: logging.info(f'Train Loss: {str(x[0].item())}'), ) # Instantiate an optimizer to perform `train` action neural_factory = nemo.core.NeuralModuleFactory(