Skip to content

Conversation

@suo
Copy link
Member

@suo suo commented Oct 17, 2022

Right now, example_value is doing two jobs:

  • We use it to propagate metadata (e.g. return type, shapes, etc.)
    throughout the graph
  • We use it to satisfy queries for the actual value (e.g. torch.cond,
    assume_constant_result)

This is further complicated by the fact that we have two modes, one
where example_value is a fake tensor, and one where it is a real
tensor (this is the fake_tensor_propagation config flag).

This leads to scenarios where we don't support every combination of
job + mode,
e.g. if fake_tensor_propagation=False, assume_constant_result is
broken.

This is made worse by the fact that "fake tensor mode" is the default
and is required if you want dynamic shapes to work.

So, this PR introduces a get_real_value API that just runs the graph
up to node in order to get a concrete value. This API is orthogonal
to
example_value, so it doesn't care about fake_tensor_propagation.

When fake_tensor_propagation=True: example_value is a fake tensor,
you must use the get_real_value API to get a concrete value. This
will
be the only configuration in the future.

When fake_tensor_propagation=False: example_value and
get_real_value will produce the same value. This is redundant but we
will be removing this config soon.

To support this, I introduce a cache for computed real values, to
memoize the work involved if we're asking for real values a lot.

I attached this state to OutputGraph because it seems to be what
historically managed example_value lifetimes, but idk.

@suo suo requested a review from jansel as a code owner October 17, 2022 17:03
@pytorch-bot
Copy link

pytorch-bot bot commented Oct 17, 2022

🔗 Helpful Links

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

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

❌ 1 Failures, 1 Pending

As of commit 19c4384:

The following jobs have failed:

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

Right now, example_value is doing two jobs:
- We use it to propagate metadata (e.g. return type, shapes, etc.)
  throughout the graph
  - We use it to satisfy queries for the actual value (e.g. torch.cond,
  `assume_constant_result`)

  This is further complicated by the fact that we have two modes, one
  where `example_value` is a fake tensor, and one where it is a real
  tensor (this is the `fake_tensor_propagation` config flag).

  This leads to scenarios where we don't support every combination of
  job + mode,
  e.g. if `fake_tensor_propagation=False`, `assume_constant_result` is
  broken.

  This is made worse by the fact that "fake tensor mode" is the default
  and is required if you want dynamic shapes to work.

  So, this PR introduces a `get_real_value` API that just runs the graph
  up to `node` in order to get a concrete value. This API is orthogonal
  to
  `example_value`, so it doesn't care about `fake_tensor_propagation`.

  When `fake_tensor_propagation=True`: `example_value` is a fake tensor,
  you must use the `get_real_value` API to get a concrete value. This
  will
  be the only configuration in the future.

  When `fake_tensor_propagation=False`: `example_value` and
  `get_real_value` will produce the same value. This is redundant but we
  will be removing this config soon.

  To support this, I introduce a cache for computed real values, to
  memoize the work involved if we're asking for real values a lot.

  I attached this state to `OutputGraph` because it seems to be what
  historically managed `example_value` lifetimes, but idk.
@suo suo force-pushed the suo/example-value branch from 1409f6f to 19c4384 Compare October 17, 2022 17:05
Copy link
Contributor

@wconstab wconstab left a comment

Choose a reason for hiding this comment

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

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 17, 2022
@suo
Copy link
Member Author

suo commented Oct 17, 2022

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: 2 additional jobs have failed, first few of them are: trunk ,trunk / macos-12-py3-arm64 / build

Details for Dev Infra team Raised by workflow job

@suo
Copy link
Member Author

suo commented Oct 17, 2022

@pytorchbot merge -f "flaky mac"

@pytorchmergebot
Copy link
Collaborator

Merge started

Your change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
Copy link
Contributor

Hey @suo.
You've committed this PR, but it does not have both a 'release notes: ...' and 'topics: ...' label. Please add one of each to the PR. The 'release notes: ...' label should represent the part of PyTorch that this PR changes (fx, autograd, distributed, etc) and the 'topics: ...' label should represent the kind of PR it is (not user facing, new feature, bug fix, perf improvement, etc). The list of valid labels can be found here for the 'release notes: ...' and here for the 'topics: ...'.
For changes that are 'topic: not user facing' there is no need for a release notes label.

suo added a commit that referenced this pull request Oct 27, 2022
This works now because of #87091,
so don't error out anymore.

[ghstack-poisoned]
suo added a commit that referenced this pull request Oct 27, 2022
This works now because of #87091,
so don't error out anymore.

ghstack-source-id: 437bd01
Pull Request resolved: #87895
@github-actions github-actions bot deleted the suo/example-value branch April 18, 2024 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged module: dynamo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants