texar-pytorch icon indicating copy to clipboard operation
texar-pytorch copied to clipboard

Use a unified and controllable logging interface for library outputs

Open huzecong opened this issue 5 years ago • 1 comments

In a few places Texar-PyTorch would print out information (e.g., "download complete", "pre-trained weights loaded") using the Python builtin print function. The behavior might not be desired and is not controllable (cannot be suppressed).

We could use the logging builtin library for this purpose. A couple of points to make sure are:

  • Provide a Texar interface to set logging levels, so even if we switch libraries old code would still work.
  • If users also use the logging library, their settings should not overwrite ours, and vice versa.

Certain outputs should be converted to exception messages, such as the following two examples: https://github.com/asyml/texar-pytorch/blob/c6935c2e8ebed4d4e7e917e15ef81e5a21f3407d/texar/torch/modules/pretrained/gpt2.py#L308-L310 https://github.com/asyml/texar-pytorch/blob/c6935c2e8ebed4d4e7e917e15ef81e5a21f3407d/texar/torch/modules/pretrained/gpt2.py#L185-L189

huzecong avatar Oct 07 '19 02:10 huzecong

Oh, one problem with using logging would be that it's probably not possible to log download progress in this way, because logging does not support clear lines. Also, there's a bug in the current download progress logging logic, so that small files will show a percentage greater than 100%.

huzecong avatar Oct 07 '19 03:10 huzecong