-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[dynamo] Clean up assert in dynamo [1/N] #165430
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
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/165430
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ✅ You can merge normally! (1 Unrelated Failure)As of commit dcdbab2 with merge base beb6b62 ( FLAKY - The following job failed but was likely due to flakiness present on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anijain2305 can you confirm these are the right way to update these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor nits but generally this looks close to ready
For ease of review, can you also add an example of running a program that triggers one of these exceptions and the error before/after in the summary? That can serve as the testplan here - thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meta point (cc @anijain2305)
The pattern
msg = ConstantVariable.create(...)
raise_observed_exception(TypeError, tx, args=[msg])
shows up a lot - could we refactor this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes - I will second @williamwen42's comment that we should put this in a helper fn since it appears so much. We can probably add it to variables/base.py
. Something like
def raise_type_error_exc(tx: InstructionTranslator, msg_str: str) -> None:
msg = ConstantVariable.create(msg_str)
raise_observed_exception(TypeError, tx, args=[msg])
torch/_dynamo/variables/lists.py
Outdated
raise_observed_exception(TypeError, tx, args=[msg]) | ||
|
||
assert not kwargs and len(args) == 1 | ||
if kwargs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we dropped the check for len(args) here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pytorch/torch/_dynamo/variables/lists.py
Lines 150 to 156 in 21697fe
if len(args) != 1: | |
msg = ConstantVariable.create( | |
f"{name} takes exactly one argument ({len(args)} given)" | |
) | |
raise_observed_exception(TypeError, tx, args=[msg]) | |
assert not kwargs and len(args) == 1 |
Yeah.. But we can combine these two into one check because len(args) != 1
promises len(args) == 1
, doesn't it?
torch/_dynamo/variables/lists.py
Outdated
) -> "VariableTracker": | ||
if name == "__getitem__": | ||
assert not kwargs and len(args) == 1 | ||
if len(args) != 1 or kwargs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's keep the order (kwargs or len(args) != 1) for consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
@Lucaskabela I was also thinking of a followup where we potentially don't need to even hardcode the TypeError's string - this would probably involve somehow calling the function with the invalid arguments just to get the TypeError. I wonder if |
@Lucaskabela Thanks for the advice. I have added this fn into
import inspect
def func(a, b):
pass
sig = inspect.signature(func)
try:
sig.bind(1, 2, 3)
except TypeError as e:
print(e) # too many positional arguments
try:
func(1, 2, 3)
except TypeError as e:
print(e) # func() takes 2 positional arguments but 3 were given It seems like |
1 similar comment
@Lucaskabela Thanks for the advice. I have added this fn into
import inspect
def func(a, b):
pass
sig = inspect.signature(func)
try:
sig.bind(1, 2, 3)
except TypeError as e:
print(e) # too many positional arguments
try:
func(1, 2, 3)
except TypeError as e:
print(e) # func() takes 2 positional arguments but 3 were given It seems like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - will probably need to rebase since another change to graph_break_registry landed
Might be easiest to:
- Rebase on main
2)git checkout main torch/_dynamo/graph_break_registry.json
- Run lintrunner to repopulate the graph_break_registry change automagically
Thanks for working hard on this!
Still shows a conflict on GitHub o_O? Anyway, I rebased the branch and everything works fine now. Thanks for the review @Lucaskabela @williamwen42 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working hard to clean up asserts here! LGTM
Errr, seems that the gb registry isn't happy still - lintrunner should hopefully fix but if it still gives you trouble feel free to ping @williamwen42 who has more context on this |
@can-gaa-hou the registry and the |
Co-authored-by: Lucas Kabela <lucasakabela@gmail.com>
Co-authored-by: Lucas Kabela <lucasakabela@gmail.com>
@pytorchbot merge |
Merge startedYour 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 |
Fixes some part of pytorch#162852 and pytorch#164878. These two issues have some relationship though. * __->__ pytorch#165430 Pull Request resolved: pytorch#165430 Approved by: https://github.com/Lucaskabela, https://github.com/williamwen42 Co-authored-by: Lucas Kabela <lucasakabela@gmail.com>
Fixes some part of #162852 and #164878. These two issues have some relationship though.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @chenyang78 @kadeng @chauhang @amjames @Lucaskabela @williamwen42 @albanD