Skip to content

Conversation

jansel
Copy link
Contributor

@jansel jansel commented Nov 30, 2023

Stack from ghstack (oldest at bottom):

Fixes #104797

  File "/home/jansel/pytorch/torch/_dynamo/utils.py", line 1486, in <lambda>
    lambda: run_node(tx.output, node, args, kwargs, nnmodule)
  File "/home/jansel/pytorch/torch/_dynamo/utils.py", line 1591, in run_node
    raise RuntimeError(fn_str + str(e)).with_traceback(e.__traceback__) from e
  File "/home/jansel/pytorch/torch/_dynamo/utils.py", line 1570, in run_node
    return node.target(*args, **kwargs)
  File "/home/jansel/conda/envs/pytorch/lib/python3.10/site-packages/einops/packing.py", line 153, in unpack
    n_unknown_composed_axes = sum(x == -1 for x in lengths_of_composed_axes)
torch._dynamo.exc.TorchRuntimeError: Failed running call_function <function unpack at 0x7f644b962710>(*(FakeTensor(..., device='cuda:0', size=(1, s0*s1, 128)), [(s0, s1)], 'b * c'), **{}):
unsupported operand type(s) for +: 'int' and 'SymBool'

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @aakhundov @kadeng

Fixes #104797

[ghstack-poisoned]
Copy link

pytorch-bot bot commented Nov 30, 2023

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 2f4f346 with merge base f128616 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@pytorch-bot pytorch-bot bot added the release notes: fx release notes category label Nov 30, 2023
jansel added a commit that referenced this pull request Nov 30, 2023
Fixes #104797

ghstack-source-id: f02373d
Pull Request resolved: #114828
@jansel jansel requested review from eellison and lezcano November 30, 2023 03:27
@jansel jansel added the topic: not user facing topic category label Nov 30, 2023
@jansel jansel added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 30, 2023
def promote(x):
"""Implements True+True=2, which works in python but not sympy"""
if isinstance(x, SymBool):
return SymInt(x.node.wrap_int(int(x)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

calling int(x) guards on the value of x. It would be better to implement a casting method similar to sym_float that casts a bool to an int, similar to the method sym_float.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. SymPy doesn't seem to support this
  2. All the usage of this pattern I found are immediately fed into conditionals, so we need to guard on it anyway

Copy link
Collaborator

Choose a reason for hiding this comment

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

Regarding 1, we can work around it by using Where

class Where(sympy.Function):
"""
Good ol' ternary operator
"""
nargs = (3,)
@classmethod
def eval(cls, c, p, q):
if c == sympy.true:
return p
elif c == sympy.false:
return q
.

Regarding 2, fair enough, although it's not an extremely unusual pattern to use True as 1 when doing things like modular computations. May be good to leave a comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we guard on 0/1, wouldn't something like sym_float end up guarding anyway ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, good point :D

def promote(x):
"""Implements True+True=2, which works in python but not sympy"""
if isinstance(x, SymBool):
return SymInt(x.node.wrap_int(int(x)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Regarding 1, we can work around it by using Where

class Where(sympy.Function):
"""
Good ol' ternary operator
"""
nargs = (3,)
@classmethod
def eval(cls, c, p, q):
if c == sympy.true:
return p
elif c == sympy.false:
return q
.

Regarding 2, fair enough, although it's not an extremely unusual pattern to use True as 1 when doing things like modular computations. May be good to leave a comment.

@jansel
Copy link
Contributor Author

jansel commented Nov 30, 2023

Inductor's codegen will likely choke on sympy.Where, so it might be extra work to support that. Since there isn't a real usecase needing that, I'll leave that unimplemented for now.

@jansel
Copy link
Contributor Author

jansel commented Nov 30, 2023

@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

@lezcano
Copy link
Collaborator

lezcano commented Nov 30, 2023

I added Where and I already implemented the relevant codegen. This is used for wrapping negative indices when we have indirect indexing. But sure, this is good as-is for now.

huydhn added a commit to huydhn/pytorch that referenced this pull request Dec 1, 2023
huydhn added a commit to huydhn/pytorch that referenced this pull request Dec 1, 2023
huydhn added a commit to huydhn/pytorch that referenced this pull request Dec 1, 2023
pytorchmergebot pushed a commit that referenced this pull request Dec 1, 2023
@facebook-github-bot facebook-github-bot deleted the gh/jansel/192/head branch December 4, 2023 15:29
dmenig pushed a commit to dmenig/pytorch that referenced this pull request Dec 21, 2023
Fixes pytorch#104797

```
  File "/home/jansel/pytorch/torch/_dynamo/utils.py", line 1486, in <lambda>
    lambda: run_node(tx.output, node, args, kwargs, nnmodule)
  File "/home/jansel/pytorch/torch/_dynamo/utils.py", line 1591, in run_node
    raise RuntimeError(fn_str + str(e)).with_traceback(e.__traceback__) from e
  File "/home/jansel/pytorch/torch/_dynamo/utils.py", line 1570, in run_node
    return node.target(*args, **kwargs)
  File "/home/jansel/conda/envs/pytorch/lib/python3.10/site-packages/einops/packing.py", line 153, in unpack
    n_unknown_composed_axes = sum(x == -1 for x in lengths_of_composed_axes)
torch._dynamo.exc.TorchRuntimeError: Failed running call_function <function unpack at 0x7f644b962710>(*(FakeTensor(..., device='cuda:0', size=(1, s0*s1, 128)), [(s0, s1)], 'b * c'), **{}):
unsupported operand type(s) for +: 'int' and 'SymBool'
```

Pull Request resolved: pytorch#114828
Approved by: https://github.com/lezcano
dmenig pushed a commit to dmenig/pytorch that referenced this pull request Dec 21, 2023
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 release notes: fx release notes category topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants