Skip to content

[jit] tracer flag to guard risky behaivors#36277

Closed
wanchaol wants to merge 5 commits intogh/wanchaol/95/basefrom
gh/wanchaol/95/head
Closed

[jit] tracer flag to guard risky behaivors#36277
wanchaol wants to merge 5 commits intogh/wanchaol/95/basefrom
gh/wanchaol/95/head

Conversation

@wanchaol
Copy link
Copy Markdown
Collaborator

@wanchaol wanchaol commented Apr 8, 2020

Stack from ghstack:

This PR introduce a flag to the tracer that guard the risky behaviors
like adding list/dict as output of the tracer. Currently to ensure not
BC breaking user, we throw warning if the tracer output is list, and
will throw error when the tracer output is dict to enforce using this
flag (next PR)

Differential Revision: D20998157

This PR introduce a flag to the tracer that guard the risky behaviors
like adding list/dict as output of the tracer. Currently to ensure not
BC breaking user, we throw warning if the tracer output is list, and
will throw error when the tracer output is dict to enforce using this
flag (next PR)

[ghstack-poisoned]
@wanchaol wanchaol requested a review from apaszke as a code owner April 8, 2020 22:47
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Apr 8, 2020
@dr-ci
Copy link
Copy Markdown

dr-ci Bot commented Apr 8, 2020

💊 Build failures summary and remediations

As of commit 22e5567 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker.

See how this bot performed.

This comment has been revised 18 times.

@wanchaol wanchaol requested a review from jamesr66a April 8, 2020 22:58
This PR introduce a flag to the tracer that guard the risky behaviors
like adding list/dict as output of the tracer. Currently to ensure not
BC breaking user, we throw warning if the tracer output is list, and
will throw error when the tracer output is dict to enforce using this
flag (next PR)

[ghstack-poisoned]
@wanchaol wanchaol requested a review from houseroad April 9, 2020 00:36
Comment thread torch/onnx/utils.py

trace_graph, torch_out, inputs_states = \
torch.jit._get_trace_graph(func, args, _force_outplace=False, _return_inputs_states=True)
torch.jit._get_trace_graph(func, args, strict=False, _force_outplace=False, _return_inputs_states=True)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@houseroad I am relaxing the constraints of onnx exporter to use this strict=False flag, let me know if you see any issues from this.

Copy link
Copy Markdown
Collaborator

@jamesr66a jamesr66a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks! Just some small comments. Functionality looks good

Comment thread torch/testing/_internal/jit_utils.py Outdated

return ge

def checkTracerWarning(self, *args, **kwargs):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having this function, can we use unittest.TestCase.assertWarnsRegex? e.g. all existing callsites can be mechanically replaced like:

self.checkTracerWarning(foo, torch.rand(3, 4), _force_outplace=True)

to

with self.assertWarnsRegex(torch.jit.TracerWarning, "cause the trace to be incorrect""):
  torch.jit.trace(foo, torch.rand(3, 4), _force_outplace=True)

This will have the benefit that it's more explicit about what's going on and will force the writer to think about if there is a more specific string they could match on, helping to alleviate the risk of false-positives

Comment thread test/test_jit.py Outdated
with self.assertRaisesRegex(RuntimeError, r"Only tensors.+can be output from traced functions"):
traced_f = torch.jit.trace(f, [])


Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra newline

Comment thread torch/csrc/jit/frontend/tracer.cpp
Comment thread torch/jit/__init__.py

def _get_trace_graph(f, args=(), kwargs=None, _force_outplace=False,
def _get_trace_graph(f, args=(), kwargs=None, strict=True, _force_outplace=False,
return_inputs=False, _return_inputs_states=False):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing actionable on this PR, but we'll have to keep an eye on the proliferation of boolean flags. Four boolean flags means 16 different "modes" the code can go through, and it's unlikely that we're testing all 16. I wonder if we can coalesce some of the other flags into one (e.g. an onnx flag or something)

This PR introduce a flag to the tracer that guard the risky behaviors
like adding list/dict as output of the tracer. Currently to ensure not
BC breaking user, we throw warning if the tracer output is list, and
will throw error when the tracer output is dict to enforce using this
flag (next PR)

[ghstack-poisoned]
This PR introduce a flag to the tracer that guard the risky behaviors
like adding list/dict as output of the tracer. Currently to ensure not
BC breaking user, we throw warning if the tracer output is list, and
will throw error when the tracer output is dict to enforce using this
flag (next PR)

[ghstack-poisoned]
@wanchaol wanchaol requested a review from jamesr66a April 13, 2020 17:05
This PR introduce a flag to the tracer that guard the risky behaviors
like adding list/dict as output of the tracer. Currently to ensure not
BC breaking user, we throw warning if the tracer output is list, and
will throw error when the tracer output is dict to enforce using this
flag (next PR)

[ghstack-poisoned]
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@wanchaol merged this pull request in 999d7f6.

@facebook-github-bot facebook-github-bot deleted the gh/wanchaol/95/head branch April 17, 2020 14:17
laurentdupin pushed a commit to laurentdupin/pytorch that referenced this pull request Apr 24, 2026
Summary:
Pull Request resolved: pytorch#36277

This PR introduce a flag to the tracer that guard the risky behaviors
like adding list/dict as output of the tracer. Currently to ensure not
BC breaking user, we throw warning if the tracer output is list, and
will throw error when the tracer output is dict to enforce using this
flag (next PR)

Test Plan: Imported from OSS

Differential Revision: D20998157

Pulled By: wanchaol

fbshipit-source-id: 0d2c55f1a263a48b1b92dd6ad54407815e0a6f72
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants