@@ -24,9 +24,6 @@ Create a message logging system for PyTorch with the following requirements:
24
24
- ** Error** : Emits a message as an error. If an error is never caught, the
25
25
application will print the error to stderr and quit.
26
26
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
-
30
27
* Offer different message classes under each severity level.
31
28
32
29
- 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:
48
45
we should probably have unit tests for it.
49
46
See [ documentation] ( https://docs.python.org/3/library/warnings.html#the-warnings-filter )
50
47
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
54
49
55
50
- Disabling warnings in Python is already possible with the ` warnings `
56
51
module filter. See [ documentation] ( https://docs.python.org/3/library/warnings.html#the-warnings-filter ) .
57
52
There is no similar system in C++ at the moment, and building one is probably
58
53
low priority.
59
54
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 )
63
58
64
59
* Settings to enable/disable emitting duplicate messages generated by multiple
65
60
` torch.distributed ` ranks. Related to issue
66
61
[ #68768 ] ( https://github.com/pytorch/pytorch/issues/68768 )
67
62
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.
70
65
71
66
- Currently ` TORCH_WARN_ONCE ` does this in C++, but there is no Python
72
67
equivalent
73
68
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
+
74
73
- TODO: ` torch.set_warn_always() ` currently controls some warnings (maybe
75
74
only the ones from C++? I need to find out for sure.)
76
75
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
-
80
76
* Settings can be changed from Python, C++, or environment variables
81
77
82
78
- 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
170
166
* ** ` c10::BetaWarning ` ** - Python ` torch.BetaWarning `
171
167
- Emitted when a beta feature is called. See
172
168
[ 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
173
171
174
172
* ** ` c10::PrototypeWarning ` ** - Python ` torch.PrototypeWarning `
175
173
- Emitted when a prototype feature is called. See
176
174
[ 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
177
177
178
178
* ** ` c10::NondeterministicWarning ` ** - Python ` torch.NondeterministicWarning `
179
179
- 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.
198
198
199
199
These APIs all have a variable length argument list, ` ... ` in C++ and ` *args `
200
200
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
+
204
213
205
214
#### Error APIs
206
215
@@ -335,13 +344,6 @@ TODO: Should we have a `TOCH_WARN_RANK` (and others) in C++ as well? Is there
335
344
an existing use case for it?
336
345
337
346
338
- ### Other details
339
-
340
- At the moment in PyTorch, the Python ` warnings ` module is being publicly
341
- included in ` torch ` as ` torch.warnings ` . This should probably be removed or
342
- renamed to ` _warnings ` to avoid confusion.
343
-
344
-
345
347
# PyTorch's current messaging API
346
348
347
349
The rest of this document contains details about the current messaging API in
@@ -414,6 +416,7 @@ Python error class:
414
416
415
417
| C++ error class | Python error class |
416
418
| ------------------------------- | -------------------------- |
419
+ | ` std::exception ` | ` RuntimeError ` |
417
420
| ` c10::Error ` | ` RuntimeError ` |
418
421
| ` c10::IndexError ` | ` IndexError ` |
419
422
| ` c10::ValueError ` | ` ValueError ` |
@@ -446,13 +449,15 @@ message using `operator<<`.
446
449
` c10::Error ` and its subclasses are translated into their corresponding Python
447
450
errors [ in ` CATCH_CORE_ERRORS ` ] ( https://github.com/pytorch/pytorch/blob/72e4aab74b927c1ba5c3963cb17b4c0dce6e56bf/torch/csrc/Exceptions.h#L54-L100 ) .
448
451
449
- However, not all of the ` c10::Error ` subclasses in the table above appear here.
450
- I'm not sure yet what's up with that .
452
+ However, not all of the ` c10::Error ` subclasses in the table above appear here,
453
+ which could just be an oversight .
451
454
452
455
` 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,
456
+ most Python-bound C++ functions use for handling errors. For instance,
454
457
` THPVariable__is_view ` uses the error handling macro
455
458
[ here] ( https://github.com/pytorch/pytorch/blob/72e4aab74b927c1ba5c3963cb17b4c0dce6e56bf/tools/autograd/templates/python_variable_methods.cpp#L76 ) .
459
+ There is also a similar ` END_HANDLE_TH_ERRORS_PYBIND ` macro that is used for
460
+ pybind-based bindings.
456
461
457
462
458
463
#### ` torch::PyTorchError `
0 commit comments