Skip to content

Conversation

@driazati
Copy link
Contributor

@driazati driazati commented Jun 8, 2019

This refactors pybind_utils so we can have all our type-inferring stuff in
1 place (e.g. for #21379)

There is some follow up work to make the error messages better, but I think that's fine to save for another PR.

Differential Revision: D15727002

This readies pybind_utils so we can have all our type-inferring stuff in
1 place
@pytorchbot pytorchbot added oncall: jit Add this issue/PR to JIT oncall triage queue module: internals Related to internal abstractions in c10 and ATen module: pybind Related to our Python bindings / interactions with other Python libraries labels Jun 8, 2019
davidriazati added 2 commits June 7, 2019 17:06
@driazati driazati requested review from eellison and suo June 10, 2019 18:58
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.

Looks good, have a few comments

// not create a CompleteTensorType
return MatchTypeReturn(DimensionedTensorType::create(tensor));
}
return MatchTypeReturn(CompleteTensorType::create(tensor));
Copy link
Contributor

@eellison eellison Jun 12, 2019

Choose a reason for hiding this comment

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

Can you add a test case where the element / list element is a tensor type, and/or make sure we are not overspecializing here? When we try to use specialized tensor types it messes up things in a lot of places.
e.g.

self.list = [Float(*, *)]
dim_tensor = self.list[0]
dim_tensor = torch.tensor()

Here, torch.tensor is not a subtype of Float(*, *) so it would throw. You might need this for the tracer, but for the script type inference a call to unshapedType() should fix the problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should do that in a follow up, this is just a refactor and behavior shouldn't change here

element_types.push_back(*type_match.type);
} else {
// Forward error message along
return type_match.errMsg;
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 just return the error here ? ^^ relating to my other comment about nesting the error message

size_t len = py::len(list);
if (!len) {
AT_ERROR("List trace inputs must have elements");
return MatchTypeReturn("List trace inputs must have elements");
Copy link
Contributor

Choose a reason for hiding this comment

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

Trace is too specific of an error message now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you mean? This is only for lists

Copy link
Contributor

Choose a reason for hiding this comment

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

It says List trace inputs

@eellison
Copy link
Contributor

What is the reason for putting the type inference logic on python objects and not ivalues ?

@driazati
Copy link
Contributor Author

The tracer doesn't have IValues here, it's trying to infer the types so it can make IValues

@pytorchbot pytorchbot added the module: cpp Related to C++ API label Jun 12, 2019
@suo
Copy link
Member

suo commented Jun 13, 2019

is this ready for re-review?

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.

Looks good, a few more comments. I think you need to check the tracer inputs for non-Tensors types before landing, also you have a failing test:

what_without_backtrace()) .find("forward() expected a value of type 'Tensor' " "for argument 'input' but instead found type 'int'") == 0 INTERNAL ASSERT FAILED at /var/lib/jenkins/workspace/test/custom_operator/test_custom_ops.cpp:85

@pytorchbot pytorchbot added the module: custom-operators custom operators, custom ops, custom-operators, custom-ops label Jun 13, 2019
@driazati driazati requested a review from eellison June 13, 2019 22:52
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.

Looks good!

}
auto type = *match.type;

if (isTraceableType(type)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure exactly, but I wonder if we can get away with not checking the types here since the values are checked at

static IValue addInput(const std::shared_ptr<TracingState> & state, const IValue& input, const TypePtr& type, Value* value) {

Still, I think it is fine in this PR and we can look into removing as a follow up.

zdevito pushed a commit to zdevito/ATen that referenced this pull request Jun 15, 2019
Summary:
This refactors pybind_utils so we can have all our type-inferring stuff in
1 place (e.g. for #21379)

There is some follow up work to make the error messages better, but I think that's fine to save for another PR.
](https://our.intern.facebook.com/intern/diff/15727002/)
Pull Request resolved: pytorch/pytorch#21550

Pulled By: driazati

Differential Revision: D15727002

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

@driazati merged this pull request in 220efdb.

@facebook-github-bot facebook-github-bot deleted the driazati/refactor_pybind branch July 13, 2020 17:55
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: custom-operators custom operators, custom ops, custom-operators, custom-ops module: internals Related to internal abstractions in c10 and ATen module: pybind Related to our Python bindings / interactions with other Python libraries 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