Skip to content

Conversation

@driazati
Copy link
Contributor

@driazati driazati commented Apr 24, 2019

Stack from ghstack:

The try-catch here gets tripped pretty often when constant prop is run which screws up catch throw in gdb.
Differential Revision: D15170134

@pytorchbot pytorchbot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Apr 24, 2019
@driazati driazati requested a review from eellison April 24, 2019 18:47
suo
suo previously requested changes Apr 24, 2019
Copy link
Member

@suo suo left a comment

Choose a reason for hiding this comment

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

I think it's better if insertConstant doesn't throw at all. It should return an optional which users are supposed to check, just like toValue. Otherwise I think it's too easy for canInsertConstant to get out of sync with insertConstant.

// we cannot actually represent the IValue as a constant node,
// so we give up replacing it
} else {
// If we cannot insert the IValue as a
Copy link
Contributor

Choose a reason for hiding this comment

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

you probably don't need the empty else branch here (but retain the comment please)

@eellison
Copy link
Contributor

I think it's better if insertConstant doesn't throw at all. It should return an optional which users are supposed to check, just like toValue. Otherwise I think it's too easy for canInsertConstant to get out of sync with insertConstant.

I'm not sure it should return an optional. It's only the case of constant propagation in which it throws

@suo
Copy link
Member

suo commented Apr 24, 2019

I'm not sure it should return an optional. It's only the case of constant propagation in which it throws

In general, it is bad practice to use exceptions in cases where a failed result is expected (i.e. not exceptional). It's true that insertConstant is used in different contexts, some where failure is expected and some where it isn't. But I think that means we should take the lowest common denominator

@eellison
Copy link
Contributor

Can we have a tryInsertConstant and insertConstant maybe ? There are 90 callsites of insertConstant. Only one of them has any expectation of failure. It would be pretty annoying to have to assert success on all 89

@suo
Copy link
Member

suo commented Apr 24, 2019

I think you are confusing with graph::insertConstant, I see only six uses:
image

edit: I see that CSE uses graph's insertConstant as well so you're right that it's effectively 90. Anyway, tryInsert and insert seems like a good compromise to me

// so we give up replacing it
} else {
// If we cannot insert the IValue as a
// constant, give up replacing it and let DCE remove it.
Copy link
Contributor

Choose a reason for hiding this comment

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

Well DCE is not guaranteed to remove this node if we fail to do this, so this comment is a bit misleading (or I am missing something).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, DCE is removing n, not the IValue, as in the original version of the comment

@driazati driazati requested a review from eellison May 1, 2019 19:05
@driazati driazati dismissed suo’s stale review May 1, 2019 19:05

addressed

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!

You still have to handle the two AT_ASSERT for a Tensor or TensorList that requires grad. Although I'm 99% sure the error here isn't user visible anywhere I still think it's not a bad idea to special case the error message for those two cases

// auto new_output = tryInsertConstant(graph, outputs[i]);
if (outputs[i].isNone()) {
new_output->setType(n->outputs()[i]->type());
(*new_output)->setType(n->outputs()[i]->type());
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you not do new_output->setType... ? would think pointer works here but maybe not. Also, semi related if you don't mind adding a comment above throw c10::Error("Can't insert requires grad as to say something along the lines of // error gets caught within constant prop

@zou3519 zou3519 deleted the gh/driazati/29/head branch May 1, 2019 23:29
@eellison
Copy link
Contributor

eellison commented May 1, 2019

You still didn't handle the two cases of AT_ASSERT for a Tensor or TensorList that requires grad

@driazati
Copy link
Contributor Author

driazati commented May 1, 2019

Those are actual bugs, we shouldn't ever be trying to make a variable a constant, so I think they are still useful as is.

@facebook-github-bot
Copy link
Contributor

@driazati merged this pull request in 8987ae3.

zhangguanheng66 pushed a commit to zhangguanheng66/pytorch that referenced this pull request May 6, 2019
Summary:
Stack from [ghstack](https://github.com/ezyang/ghstack):
* **pytorch#19686 [jit] Remove try/catch in constant propagation**

The try-catch here gets tripped pretty often when constant prop is run which screws up `catch throw` in gdb.](https://our.intern.facebook.com/intern/diff/15170134/)
Pull Request resolved: pytorch#19686

Pulled By: driazati

Differential Revision: D15170134

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

Labels

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