Skip to content

Conversation

@smessmer
Copy link
Contributor

@smessmer smessmer commented Jul 23, 2019

Stack from ghstack:

Differential Revision: D16448942

@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: internals Related to internal abstractions in c10 and ATen labels Jul 23, 2019
smessmer added a commit that referenced this pull request Jul 23, 2019
Differential Revision: [D16448942](https://our.internmc.facebook.com/intern/diff/D16448942/)

ghstack-source-id: 87040601
Pull Request resolved: #23270
@smessmer smessmer requested review from dzhulgakov and zdevito July 23, 2019 21:49
@eellison
Copy link
Contributor

eellison commented Jul 24, 2019

This was fixed separately in #23267 , you might need to rebase past that

@smessmer
Copy link
Contributor Author

I rebased past it

smessmer added a commit that referenced this pull request Jul 24, 2019
Pull Request resolved: #23270
ghstack-source-id: 87092122

Differential Revision: [D16448942](https://our.internmc.facebook.com/intern/diff/D16448942/)
Copy link
Contributor

@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.

What is the goal of the PR?

c10::List<Elem> makeListForDictKeysOrValues(
const std::pair<c10::optional<TypePtr>, c10::optional<TypePtr>>& types,
const std::vector<std::pair<IValue, IValue>>& order) {
TORCH_INTERNAL_ASSERT(
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the point of the changes to this function ? it already worked

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additional error checking that the lists we're passing around have the correct type

Copy link
Contributor

Choose a reason for hiding this comment

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

the typesystem should already ensure that it's the correct type. if we're adding runtime enforcements here shouldn't we be adding a runtime enforcement to every op that involves a list?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a huge deal either way but I still would prefer not to set the precedent that we don't trust the input types of the statically typed langauge.

@zdevito thoughts ?

Copy link
Contributor Author

@smessmer smessmer Jul 24, 2019

Choose a reason for hiding this comment

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

to reiterate from our offline discussion: What this code should do is take the type from the source dict and write it to the target list, same as what makeGenericListForDictKeysOrValues is doing.

Unfortunately, only GenericList has a constructor that takes a runtime type and can do this. List<T> doesn't need that constructor because it infers the runtime type from its T type parameter. So instead of getting the runtime type from the dict and passing it to the list, the only thing we can do is check that this inferred type is the same we would have passed in if we could have.

Note that this is a TORCH_INTERNAL_ASSERT and not a TORCH_CHECK because this is not a type check that reports errors to users. Static typing should make sure that this never fails. But it can fail if there's a PyTorch bug and if that happens, I'd rather we catch that here than just ignore it.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is just an assert, so it is ok. It improves the error message that would otherwise happen in the to call.

const std::pair<c10::optional<TypePtr>, c10::optional<TypePtr>>& types,
const std::vector<std::pair<IValue, IValue>>& order) {
auto values = c10::impl::GenericList(c10::impl::deprecatedUntypedList());
auto type = std::get<Index>(types);
Copy link
Contributor

Choose a reason for hiding this comment

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

same here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here, it's more than just error checking. Without this, the runtime key/value type of the Dict wouldn't propagate into the resulting list.

Copy link
Contributor

Choose a reason for hiding this comment

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

We create the type of the list based on the static type. E.g. an optional list of ints with a value of [1] should be a generic list. If it this created an intlist that would be a bug.

how exactly is the runtime type set ? and as with ^^^ the type system should already enforce the correct runtime value

@smessmer
Copy link
Contributor Author

smessmer commented Jul 24, 2019

@eellison Each Dict and List stores a type pointer for their elements at runtime and this PR makes sure that this type information is correctly propagated when calling these ops.

@smessmer smessmer requested a review from eellison July 24, 2019 22:27
c10::List<Elem> makeListForDictKeysOrValues(
const std::pair<c10::optional<TypePtr>, c10::optional<TypePtr>>& types,
const std::vector<std::pair<IValue, IValue>>& order) {
TORCH_INTERNAL_ASSERT(
Copy link
Contributor

Choose a reason for hiding this comment

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

This is just an assert, so it is ok. It improves the error message that would otherwise happen in the to call.

smessmer added a commit that referenced this pull request Jul 30, 2019
Pull Request resolved: #23270
ghstack-source-id: 87389530

Differential Revision: [D16448942](https://our.internmc.facebook.com/intern/diff/D16448942/)
@zou3519 zou3519 deleted the gh/smessmer/5/head branch July 30, 2019 03:03
zdevito pushed a commit to zdevito/ATen that referenced this pull request Jul 30, 2019
Summary:
Pull Request resolved: pytorch/pytorch#23270
ghstack-source-id: 87389530

Differential Revision: D16448942

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

This pull request has been merged in 30bc19d.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Merged 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.

7 participants