Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: transactional translation validation insertion. #107523

Closed
wants to merge 1 commit into from

Conversation

ysiraichi
Copy link
Collaborator

@ysiraichi ysiraichi commented Aug 19, 2023

Stack from ghstack (oldest at bottom):

This PR fixes transactional behavior of translation validation insertion.

Previously, this transactional behavior was implemented by removing the FX node if any
issues occurred until the end of evaluate_expr. However, since we cache FX nodes, we
might end up removing something that wasn't inserted in the same function call.

Solution: when creating an FX node for call_function, we also return whether this is
a fresh FX node or not. Then, we can appropriately handle each case.

This PR fixes transactional behavior of translation validation insertion.

Previously, this transactional behavior was implemented by removing the FX node if any
issues occurred until the end of `evaluate_expr`. However, since we cache FX nodes, we
might end up removing something that wasn't inserted in the same function call.

**Solution:** when creating an FX node for `call_function`, we also return whether this is
a fresh FX node or not. Then, we can appropriately handle each case.

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Aug 19, 2023

🔗 Helpful Links

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

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

✅ No Failures

As of commit 4ca97ff with merge base 36141de (image):
💚 Looks good so far! There are no failures yet. 💚

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

@ysiraichi ysiraichi marked this pull request as ready for review August 21, 2023 13:23
pytorchmergebot pushed a commit that referenced this pull request Aug 22, 2023
This PR stops `SymNode` from mutating (i.e. simplifying) its expression. Instead, the
simplification (without mutation) is deferred to the `SymNode.maybe_as_int` method.

```python
- FakeTensor(size=(s0,), ...)
- FakeTensor(size=(s1, s2, s3), ...)

- Eq(s0, s1 + s2 + s3)

- FakeTensor(size=(s0,), ...)
- FakeTensor(size=(s1, s2, s3), ...)
```

In summary, this PR:
- Replaces `SymNode._expr` by `SymNode.expr`, removing the old property function
    - This makes it so `SymNode` instances never update their expression
- Creates `SymNode.simplified_expr()` method for actually calling `ShapeEnv.replace` on
  its expression. Note that this doesn't updates `SymNode.expr`
- Changes how `tensor.size()` gets converted to its Python `torch.Size` type
    - Instead of calling `SymInt::maybe_as_int()` method, we create a new
      `SymInt::is_symbolic()` method for checking whether it is actually a symbolic value
    - This is needed so that when we call `tensor.size()` in the Python side, the returned
      sequence is faithful to the actual data, instead of possibly simplifying it and
      returning an integer
    - 2 files needs this modification:
        - _torch/csrc/Size.cpp_: for handling `torch.Tensor.size` Python calls
        - _torch/csrc/utils/pybind.cpp_: for handling `symint.cast()` C++ calls

Pull Request resolved: #107492
Approved by: https://github.com/ezyang
ghstack dependencies: #107523
@facebook-github-bot facebook-github-bot deleted the gh/ysiraichi/75/head branch August 25, 2023 14:18
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