Skip to content

Commit e9baa60

Browse files
committed
More updates from discussion
1 parent d272df6 commit e9baa60

File tree

1 file changed

+30
-18
lines changed

1 file changed

+30
-18
lines changed

RFC-0026-logging-system.md

+30-18
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ Create a message logging system for PyTorch with the following requirements:
2424
- **Error**: Emits a message as an error. If an error is never caught, the
2525
application will print the error to stderr and quit.
2626

27-
- TODO: Do we also need a **Fatal** severity for integration with Meta's
28-
internal logging system (glog)? A fatal message terminates the program
29-
3027
* Offer different message classes under each severity level.
3128

3229
- Every message is emitted as an instance of a message class.
@@ -48,35 +45,34 @@ Create a message logging system for PyTorch with the following requirements:
4845
we should probably have unit tests for it.
4946
See [documentation](https://docs.python.org/3/library/warnings.html#the-warnings-filter)
5047

51-
* Settings to disable specific message classes and severity levels
52-
53-
- TODO: Error classes should never be disableable, right?
48+
* Settings to disable specific **Warning** or **Info** classes
5449

5550
- Disabling warnings in Python is already possible with the `warnings`
5651
module filter. See [documentation](https://docs.python.org/3/library/warnings.html#the-warnings-filter).
5752
There is no similar system in C++ at the moment, and building one is probably
5853
low priority.
5954

60-
- Filtering out **Info** severity messages would also be nice to have, since
61-
excessive printouts can degrade the user experience. Related to
62-
issue [#68768](https://github.com/pytorch/pytorch/issues/68768)
55+
- Filtering out **Info** messages would be nice to have because excessive
56+
printouts can degrade the user experience. Related to issue
57+
[#68768](https://github.com/pytorch/pytorch/issues/68768)
6358

6459
* Settings to enable/disable emitting duplicate messages generated by multiple
6560
`torch.distributed` ranks. Related to issue
6661
[#68768](https://github.com/pytorch/pytorch/issues/68768)
6762

68-
* Ability to make a particular warning only warn once. Warn-once should be the
69-
default for most warnings.
63+
* Ability to make a particular **Warning** or **Info** message only emit once.
64+
Warn-once should be the default for most warnings.
7065

7166
- Currently `TORCH_WARN_ONCE` does this in C++, but there is no Python
7267
equivalent
7368

69+
- Offer a filter to override warn- and log-once, so that they always emit.
70+
The filter could work similarly to the Python `warnings` filter. This is
71+
a low priority feature.
72+
7473
- TODO: `torch.set_warn_always()` currently controls some warnings (maybe
7574
only the ones from C++? I need to find out for sure.)
7675

77-
- TODO: Should there be a setting to turn a warn-once into a warn-always and
78-
vice versa for an entire message class?
79-
8076
* Settings can be changed from Python, C++, or environment variables
8177

8278
- Filtering warnings with Python command line arguments should
@@ -170,10 +166,14 @@ exists in C++, and it is not implemented as a C++ class that can be inherited
170166
* **`c10::BetaWarning`** - Python `torch.BetaWarning`
171167
- Emitted when a beta feature is called. See
172168
[PyTorch feature classifications](https://pytorch.org/blog/pytorch-feature-classification-changes/).
169+
- TODO: This warning type might not be very useful--find out if we really
170+
want this
173171

174172
* **`c10::PrototypeWarning`** - Python `torch.PrototypeWarning`
175173
- Emitted when a prototype feature is called. See
176174
[PyTorch feature classifications](https://pytorch.org/blog/pytorch-feature-classification-changes/).
175+
- TODO: This warning type might not be very useful--find out if we really
176+
want this
177177

178178
* **`c10::NondeterministicWarning`** - Python `torch.NondeterministicWarning`
179179
- Emitted when `torch.use_deterministic_algorithms(True)` and
@@ -198,9 +198,18 @@ In order to emit messages, developers can use the APIs defined in this section.
198198

199199
These APIs all have a variable length argument list, `...` in C++ and `*args`
200200
in Python. When a message is emitted, these arguments are concatenated into
201-
a string, and the string becomes the body of the message. In C++, the arguments
202-
must all have the `std::ostream& operator<<` function defined so that they can
203-
be concatenated, and in Python, they must all have a `__str__` function.
201+
a string, and the string becomes the body of the message.
202+
203+
In C++, the arguments in `...` must all have the `std::ostream& operator<<`
204+
function defined so that they can be concatenated.
205+
206+
In Python, each element in `*args` must either have a `__str__` function or it
207+
must be a callable that, when called, produces another object that has
208+
a `__str__` fuction. Providing the body of a message as a callable can provide
209+
better performance in cases where the message would not be emitted, as in
210+
`torch.check(True, lambda: expensive_function())` if `cond == True`, since the
211+
`expensive_function()` would not be called in that case.
212+
204213

205214
#### Error APIs
206215

@@ -414,6 +423,7 @@ Python error class:
414423

415424
| C++ error class | Python error class |
416425
| ------------------------------- | -------------------------- |
426+
| `std::exception` | `RuntimeError` |
417427
| `c10::Error` | `RuntimeError` |
418428
| `c10::IndexError` | `IndexError` |
419429
| `c10::ValueError` | `ValueError` |
@@ -450,9 +460,11 @@ However, not all of the `c10::Error` subclasses in the table above appear here.
450460
I'm not sure yet what's up with that.
451461

452462
`CATCH_CORE_ERRORS` is included within the `END_HANDLE_TH_ERRORS` macro that
453-
every Python-bound C++ function uses for handling errors. For instance,
463+
most Python-bound C++ functions use for handling errors. For instance,
454464
`THPVariable__is_view` uses the error handling macro
455465
[here](https://github.com/pytorch/pytorch/blob/72e4aab74b927c1ba5c3963cb17b4c0dce6e56bf/tools/autograd/templates/python_variable_methods.cpp#L76).
466+
There is also a similar `END_HANDLE_TH_ERRORS_PYBIND` macro that is used for
467+
pybind-based bindings.
456468

457469

458470
#### `torch::PyTorchError`

0 commit comments

Comments
 (0)