Skip to content

Conversation

@eellison
Copy link
Contributor

In schema matching we allow a homogenous tuple to be matched to list arguments. This logic wasn't yet extended for vartype lists, causing stuff like len((1, 2, 3)) to fail.

Fix for #20500

@eellison eellison requested a review from suo September 10, 2019 20:21
@eellison eellison requested a review from apaszke as a code owner September 10, 2019 20:21
@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: cpp Related to C++ API module: internals Related to internal abstractions in c10 and ATen labels Sep 10, 2019
@suo
Copy link
Member

suo commented Sep 10, 2019

I would prefer if @zdevito reviewed this as he was working on changing schema matching stuff recently

@suo suo requested a review from zdevito September 10, 2019 20:30
@eellison
Copy link
Contributor Author

@suo most of the PR is just test / mechanical changes

@eellison
Copy link
Contributor Author

@pytorchbot rebase this please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/pytorch/pytorch/blob/master/torch/csrc/utils/python_arg_parser.cpp#L490

Specifies that this functionality is only supposed to work for intlists, but looking at test failures it looks like this is also being used for broadcast_tensors

@zdevito
Copy link
Contributor

zdevito commented Sep 12, 2019

We hit a particularly nasty bug in the same codepath that is going to take a week of work to sort out, so I do want to carefully review this. Any change to type promotion rules should always have high scrutiny.

Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

This looks correct. A couple cleanups:

  1. Test if the allow_conversions flag is really required, I think it will get caught by the isSubtypeOf checks that happen after matching anyway and it bloats the footprint of this change substantially.
  2. Potentially move the tests to python if possible.

Copy link
Contributor

Choose a reason for hiding this comment

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

A for loop would be a lot cleaner here. It would remove the weird nullptr propagation logic, and allow for the short circute and return of nullptr.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this return optional but unifyTypes return TypePtr that might be null. This should be consistent with TypePtr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unifyTypes returns an optional

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this bool because we still check subtyping relationships after matching type variables. Even if we always allow potential matches, it will still have the same behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

use the testing namespace. Otherwise someone can write torch.test_vartype in the C++ frontend and it will work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will use the testing namespace - however this op only gets defined when the test is run right ? i don't think torch.test_vartype would be defined

Copy link
Contributor

Choose a reason for hiding this comment

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

as it is written, yes it will only appear here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid using low-level APIs like this in tests, it adds work to any refactoring. Please use Module and its define methods and ways of running methods.

Copy link
Contributor

Choose a reason for hiding this comment

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

actually, why are these C++ tests at all? If this is just running code but using a custom op, then just define the testing op in register_builtin_ops and write python tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote the tests in c++ so that the op only gets defined when the tests are run and we don't have unnecessary ops in in the runtime.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is not specific to intlist, the comment is wrong.

@suo suo removed their request for review September 13, 2019 07:11
Copy link
Contributor Author

@eellison eellison left a comment

Choose a reason for hiding this comment

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

Good point about not needing the allow_conversions arg. Re: c++. I would rather not mix together test ops and real ones. previously I used c++ for test ops

"prim::test_none() -> int?",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unifyTypes returns an optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wrote the tests in c++ so that the op only gets defined when the tests are run and we don't have unnecessary ops in in the runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will use the testing namespace - however this op only gets defined when the test is run right ? i don't think torch.test_vartype would be defined

@eellison eellison force-pushed the fix_tuple_listvartype_matching branch from 8597000 to b3aa3af Compare September 16, 2019 22:12
@eellison eellison requested review from zdevito and removed request for zdevito September 17, 2019 00:03
@eellison eellison requested a review from zdevito September 17, 2019 17:21
Copy link
Contributor

@zdevito zdevito left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@eellison is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Sep 17, 2019
Summary:
In schema matching we allow a homogenous tuple to be matched to list arguments. This logic wasn't yet extended for vartype lists, causing stuff like `len((1, 2, 3))` to fail.

Fix for pytorch/pytorch#20500
Pull Request resolved: pytorch/pytorch#25944

Differential Revision: D17431514

Pulled By: eellison

fbshipit-source-id: 2ad98bab15eaa496471df651572735eb35183323
@facebook-github-bot
Copy link
Contributor

@eellison merged this pull request in a8073f3.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@eellison
Copy link
Contributor Author

@pytorchbot rebase this please

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@eellison has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Sep 20, 2019
Summary:
In schema matching we allow a homogenous tuple to be matched to list arguments. This logic wasn't yet extended for vartype lists, causing stuff like `len((1, 2, 3))` to fail.

Fix for pytorch/pytorch#20500
Pull Request resolved: pytorch/pytorch#25944

Differential Revision: D17482510

Pulled By: eellison

fbshipit-source-id: aa63318c27a01d965a7a7b68ce8bec638168dc26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged module: cpp Related to C++ API module: internals Related to internal abstractions in c10 and ATen oncall: jit Add this issue/PR to JIT oncall triage queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants