Skip to content

Conversation

wip

wip

Initial guard env

Working

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Dec 7, 2022

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/90370

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 2 Failures

As of commit 937d912:

The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

voznesenskym added a commit that referenced this pull request Dec 7, 2022
wip

wip

Initial guard env

Working

ghstack-source-id: b41e577
Pull Request resolved: #90370
@voznesenskym voznesenskym changed the title [WIP] Initial Guard Env [WIP] [Do not review] Initial Guard Env Dec 7, 2022
wip

wip

Initial guard env

Working

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
@voznesenskym voznesenskym changed the title [WIP] [Do not review] Initial Guard Env Initial Guard Env Dec 7, 2022
wip

wip

Initial guard env

Working

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
@voznesenskym voznesenskym changed the title Initial Guard Env Initial Guard Env, duplicate tensor guards Dec 7, 2022
Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
) -> Optional[GuardedCode]:
output: Optional[OutputGraph] = None

# from .utils import print_once; print_once(code.co_filename)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

to reviewer note: There are no meaningful changes here, it is just tabbed over.

Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
voznesenskym added a commit that referenced this pull request Dec 8, 2022
wip

wip

Initial guard env

Working

ghstack-source-id: fd885de
Pull Request resolved: #90370

Docs, tests, cleanups

Lint

add nice test line

Feedback, lint

intermed

Fix

Feedback

test fixes

Fixy fixy

Fixy fixy

Fix
Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
voznesenskym added a commit that referenced this pull request Dec 8, 2022
wip

wip

Initial guard env

Working

ghstack-source-id: 29447aa
Pull Request resolved: #90370

Docs, tests, cleanups

Lint

add nice test line

Feedback, lint

intermed

Fix

Feedback

test fixes

Fixy fixy

Fixy fixy

Fix

Fix public api thin
Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
voznesenskym added a commit that referenced this pull request Dec 8, 2022
wip

wip

Initial guard env

Working

ghstack-source-id: 0129253
Pull Request resolved: #90370

Docs, tests, cleanups

Lint

add nice test line

Feedback, lint

intermed

Fix

Feedback

test fixes

Fixy fixy

Fixy fixy

Fix

Fix public api thin

Fix import
@dataclasses.dataclass
class DuplicateInputs(GuardEnvExpr):
arg_a: str
arg_b: str
Copy link
Contributor

Choose a reason for hiding this comment

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

I think, directionally, my biggest discomfort with introducing a new GuardEnvExpr concept here that is distinct from Dynamo guards, is that Dynamo may very well WANT to generate guards like this (e.g., it is processing a conditional a is b) and it seems weird to have two possible ways to generate a guard (regular Guard, or GuardEnvExpr)

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, it would be good to consolidate how we manage guards into a single place. That doesn't mean all guards need to be sympy guards (or dynamo guards)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is due to a layering issue - aot_autograd is below dynamo, so this needs to be in another place. We could violate layering and reuse the definitions in guards.py, or we could lower those down to a shared place, or we could do something like this. This felt the more reasonable, especially given the fact that we have another guard system in shape_env already that follows a similar pattern.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is also different from dynamo guards as all dynamo guards handle a single object at a time, the entire guards static_fn pattern is predicated on passing a Guard object which represent a single arg (see the self.get calls in guards.py). We could break that assumption and make multi-target guards, and rewrite that file, or we could carve out a special one-off guard that takes multiple tensors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fwiw, I understand the concern, and we could do something like:

  1. throw out DuplicateInputs
  2. Make the mapping tensor:source instead of tensor:name
  3. define a new Guard type that is multi-source / or a Source type that is multi-guard (we need to model the fact that this is a 2 object guard somewhere)
  4. Call Guards.DUPLICATE_INPUTS with either the 2 object guard, or with 2 guards for the 2 sources

Would you prefer that? Does that feel cleaner to you both? it does not to me.

instructions[:] = output.output_instructions
code_options.update(output.code_options)
guard_env = GuardEnv()
with guarding(guard_env):
Copy link
Contributor

@jansel jansel Dec 8, 2022

Choose a reason for hiding this comment

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

This with can go around the function call instead of the def ... part. The env doesn't matter for a function def. This will make this file's diff easier to read.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done! I added a comment about why it is where it is too.

self._guards.clear()
self._tensor_to_names.clear()

CURRENT_GUARD_ENV = None
Copy link
Contributor

Choose a reason for hiding this comment

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

How are we passing the shape env to each part of the stack today? Is it a different global variable somewhere? I'd suggest some sort of tracing context class (and if needed just one global pointer to that) that holds pointers to these sorts of things and also allows us to guarantee they are set.

Copy link
Contributor

Choose a reason for hiding this comment

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

ShapeEnv is accessible from all SymInts, so all the points when we may want to register guards (e.g. an equality test on symint) can just directly add the guard to the SymInt. So ShapeEnv didn't really need a context class (although maybe it should.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We were talking about global vs passed around and Ed suggested this dynamic scoping to be a medium between the two. I don't have strong opinions on either way, but the plumbing story right now to backends is not amazing (as you recall from the kwargs/pass fake_mode around PRs we tried and failed prior).

There's a few ways we could take this:

  1. Leave as is, its a one off for now, until another thing with a similar lifecycle and pass-through-backends story needs to be developed
  2. Match the fake_mode pattern more closely, and ride guard_env down on the inputs (I dislike it, but its worth mentioning for consistency)
  3. Make a tracing context we pass around, move the shape_env and guard_env there

Adds the guard env defined here: https://docs.google.com/document/d/1VbiXkIhKy744Q7Lx2e8UUBvP_5RH_WU0FEc3VadVX4U/edit#heading=h.bk4qqlofhsq

cc mlazos soumith yanboliang penguinwu anijain2305 EikanWang jgong5 Guobing-Chen chunyuan-w XiaobingSuper zhuhaozhe blzheng Xia-Weiwen wenzhe-nrv jiayisunx desertfire

[ghstack-poisoned]
voznesenskym added a commit that referenced this pull request Dec 8, 2022
wip

wip

Initial guard env

Working

ghstack-source-id: 07e2b8a
Pull Request resolved: #90370

Docs, tests, cleanups

Lint

add nice test line

Feedback, lint

intermed

Fix

Feedback

test fixes

Fixy fixy

Fixy fixy

Fix

Fix public api thin

Fix import

Feedback
@voznesenskym voznesenskym requested a review from jansel December 8, 2022 18:34
@facebook-github-bot facebook-github-bot deleted the gh/voznesenskym/36/head branch June 8, 2023 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants