Skip to content

Commit

Permalink
Add flag torch_jit_disable_warning_prints to allow disabling all warn…
Browse files Browse the repository at this point in the history
…ings.warn (pytorch#49313)

Summary:
Adding a flag torch_jit_disable_warning_prints to optimize interpreter performance by suppressing (potentially large amount) of warnings.warn.

This is to work around TorchScript's warning behavior mismatch with Python. Python by default triggers a warning once per location but TorchScript doesn't support it. This causes same warning to trigger and print once per inference run, hurting performance.

Pull Request resolved: pytorch#49313

Reviewed By: SplitInfinity

Differential Revision: D25534274

Pulled By: gmagogsfm

fbshipit-source-id: eaeb57a335c3e6c7eb259671645db05d781e80a2
  • Loading branch information
gmagogsfm authored and facebook-github-bot committed Dec 15, 2020
1 parent aff0b68 commit 7518f54
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions torch/csrc/jit/runtime/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ struct CodeImpl {
}

void emitWarn(Node* node) {
if (FLAGS_torch_jit_disable_warning_prints) {
return;
}

emitLoadInputs(node->inputs());
int32_t idx = -1;
if (node->hasAttribute(attr::warn_id)) {
Expand Down
2 changes: 2 additions & 0 deletions torch/csrc/jit/runtime/interpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <torch/csrc/WindowsTorchApiMacro.h>
#include <torch/csrc/jit/frontend/source_range.h>

C10_DECLARE_bool(torch_jit_disable_warning_prints);

namespace at {
class Tensor;
CAFFE2_API void launch(std::function<void()> func);
Expand Down
5 changes: 5 additions & 0 deletions torch/csrc/jit/runtime/profiling_graph_executor_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ C10_DEFINE_bool(
true,
"If this flag is set to false TorchScript will be using the legacy/original executor");

C10_DEFINE_bool(
torch_jit_disable_warning_prints,
false,
"Disables warning.warn prints in TorchScript graph");

constexpr size_t kDefaultNumProfiledRuns = 1;
constexpr size_t kDefaultBailoutDepth = 20;

Expand Down

0 comments on commit 7518f54

Please sign in to comment.