Skip to content

Commit 15c24ec

Browse files
committed
Create RFC for a logging system and list some required features
1 parent b379b19 commit 15c24ec

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

RFC-0026-logging-system.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# PyTorch Logging System
2+
3+
## **Summary**
4+
Create a message logging system for PyTorch with the following requirements:
5+
6+
* All errors, warnings, and other messages generated by PyTorch should be
7+
emitted using the the logging system API
8+
9+
* The APIs for emitting messages and changing settings should all be consistent
10+
between C++ and Python
11+
12+
* Continue using warning/error APIs that currently exist in PyTorch wherever
13+
possible. For instance, `TORCH_CHECK`, `TORCH_WARN`, and `TORCH_WARN_ONCE`
14+
should continue to be used in C++
15+
16+
* Offer different message severity levels, including at least the following:
17+
18+
- **Info**: Emits a message without creating a warning or error. By default,
19+
this gets printed to stdout
20+
21+
- **Warning**: Emits a message as a warning. By default, this will turn into
22+
a Python warning
23+
24+
- **Error**: Emits a message as an error. By default, this will turn into
25+
a Python error
26+
27+
- TODO: Should we also have a **Fatal** severity for integration with
28+
Meta's internal logging system? A fatal message terminates the program
29+
30+
* Offer different classes of messages, including at least the following:
31+
32+
- **Default**: A catch-all message class
33+
34+
- **Nondeterministic**: Emitted when `torch.use_deterministic_algorithms(True)`
35+
is set and a nondeterministic operation is called
36+
37+
- **Deprecated**: Emitted when a deprecated function is called
38+
39+
- **Beta**: Emitted when a beta feature is called. See
40+
[PyTorch feature classifications](https://pytorch.org/blog/pytorch-feature-classification-changes/)
41+
42+
- **Prototype**: Emitted when a prototype feature is called. See
43+
[PyTorch feature classifications](https://pytorch.org/blog/pytorch-feature-classification-changes/)
44+
45+
* Creating new message classes and severity levels should be easy
46+
47+
* Settings to turn warnings for a specific message class into errors
48+
49+
* Settings to disable specific message classes and severity levels
50+
51+
- TODO: However, most errors should not be disableable, right? Perhaps only
52+
some message classes should allow disabling or downgrading errors
53+
54+
* Settings to avoid emitting duplicate messages generated by multiple
55+
`torch.distribted` ranks (related to issue
56+
[#68768](https://github.com/pytorch/pytorch/issues/68768))
57+
58+
* Ability to make a particular warning only warn once
59+
60+
- NOTE: Currently `TORCH_WARN_ONCE` does this in C++, but there is no Python
61+
equivalent. Also, `TORCH_WARN_ONCE` has no concept of message classes
62+
63+
- TODO: Should there be a setting to turn a warn-always into a warn-once for
64+
a given message class and vice versa?
65+
66+
- TODO: Should warn-once be its own separate severity level?
67+
68+
* Settings can be changed from Python, C++, or environment variables
69+
70+
- Filtering warnings with Python command line arguments should
71+
remain possible. For instance, the following turns a `DeprecationWarning`
72+
into an error: `python -W error::DeprecationWarning your_script.py`
73+
74+
* Should integrate with Meta's internal logging system, which is
75+
[glog](https://github.com/google/glog)
76+
77+
- TODO: What are all the requirements that define "integrating with glog"
78+
79+
* Must be OSS-friendly, so it shouldn't require libraries (like glog) which may
80+
cause incompatibility issues for projects that use PyTorch
81+
82+
* TODO: Determine the requirements for the following concepts:
83+
84+
- Log files (default behavior and any settings)
85+
86+
87+
## **Motivation**
88+
Original issue: [link](https://github.com/pytorch/pytorch/issues/72948)
89+
90+
Currently, it is challenging for PyTorch developers to provide messages that
91+
act consistently between Python and C++.
92+
93+
It is also challenging for PyTorch users to manage the messages that PyTorch
94+
emits. For instance, if a PyTorch user happens to be calling PyTorch functions
95+
that emit lots of warnings, it can be difficult for them to filter out those
96+
warnings so that their project's users don't get bombarded with warnings that
97+
they don't need to see.

0 commit comments

Comments
 (0)