Skip to content

[JIT] Allow type cast between int and float in Script#10168

Closed
wanchaol wants to merge 2 commits intopytorch:masterfrom
wanchaol:pytorch-intfloat
Closed

[JIT] Allow type cast between int and float in Script#10168
wanchaol wants to merge 2 commits intopytorch:masterfrom
wanchaol:pytorch-intfloat

Conversation

@wanchaol
Copy link
Collaborator

@wanchaol wanchaol commented Aug 2, 2018

The PR allows int→float and float→int casts. Current we only allow tensor→int and tensor→float casts.

@wanchaol wanchaol added the oncall: jit Add this issue/PR to JIT oncall triage queue label Aug 2, 2018
setup.py Outdated

This comment was marked as off-topic.

This comment was marked as off-topic.

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 -- Just some small changes.

setup.py Outdated

This comment was marked as off-topic.

result->output()->setType(type);
return result;
}
Node* createIntToFloat(const TypePtr& type, Value* value) {

This comment was marked as off-topic.

result->output()->setType(type);
return result;
}
Node* createFloatToInt(const TypePtr& type, Value* value) {

This comment was marked as off-topic.

prim::IntToFloat,
[](Node* node) -> Operation {
return [](Stack& stack) {
at::Scalar s;

This comment was marked as off-topic.

prim::FloatToInt,
[](Node* node) -> Operation {
return [](Stack& stack) {
at::Scalar s;

This comment was marked as off-topic.

return [](Stack& stack) {
at::Scalar s;
pop(stack, s);
push(stack, s.toFloat());

This comment was marked as off-topic.

return [](Stack& stack) {
at::Scalar s;
pop(stack, s);
push(stack, s.toInt());

This comment was marked as off-topic.

n = graph.createIntToFloat(dst, value);
} else {
throw ErrorReport(loc) << "Cannot cast type '" << orig->str() << "' to type '"
<< dst->str() << "', no available type casting.";

This comment was marked as off-topic.

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.

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

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.

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

@zdevito
Copy link
Contributor

zdevito commented Aug 3, 2018

@pytorchbot retest this please

@wanchaol wanchaol deleted the pytorch-intfloat branch August 6, 2018 20:29
goodlux pushed a commit to goodlux/pytorch that referenced this pull request Aug 15, 2018
Summary:
The PR allows int→float and float→int casts. Current we only allow `tensor→int` and `tensor→float` casts.
Pull Request resolved: pytorch#10168

Differential Revision: D9141163

Pulled By: wanchaol

fbshipit-source-id: 5e5591a98b4985a675641dfc9a385b2a0bf8e208
@ezyang ezyang added the merged label Jun 26, 2019
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.

4 participants