-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[JIT][fuser] Emit math functions specific to output type #18815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
49d2db4
to
5a12bd3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In person: can we put all templates into a single list and use an object to track the different templates for float, double, and vector things. Also resolve cast_0 vs 0
torch/csrc/jit/fuser/codegen.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor this into a function please.
torch/csrc/jit/fuser/codegen.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
struct Template {
Template(const char* flor_float, const char* for_double);
const char * for_float;
const char * for_double;
};
Then the lines can be much shorter:
{aten::sigmoid, {"1.f / (1.f + expf(-${0}))", "1. / (1. + exp(-${0}))"}},
5be3a9a
to
35a54fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamesr66a has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but add #documentation
torch/csrc/jit/fuser/codegen.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused
torch/csrc/jit/fuser/codegen.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining what this struct is for
test/test_jit.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a brief comment explaining what tests are supposed to check
43fbbac
to
696a4a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamesr66a is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jamesr66a is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
@jamesr66a merged this pull request in 34382e4. |
Summary: Stacked on #18815 and #18811. This makes it so that we emit a higher-precision literal for float values in the fusion kernel, as well as assign that to a `double` variable. This prevents us from losing precision for values such as `pi`, but with the previous fixes this will also get downcasted to `float` if downstream operations require it. Therefore, we should not lose performance because of implicit promotions Pull Request resolved: #18817 Differential Revision: D14820842 Pulled By: jamesr66a fbshipit-source-id: 519671c6ca5e7adac746a4c4c72760a6d91e332f
Summary: Stacked on pytorch#18811 This makes it so that we only emit the *f variants of math functions if the output value's type is FloatTensor, otherwise we call the double variants to prevent loss of precision. This fixes more numerical issues Pull Request resolved: pytorch#18815 Differential Revision: D14816965 Pulled By: jamesr66a fbshipit-source-id: 464be644168875ede987142281fb2168f4041e81
Summary: Stacked on pytorch#18815 and pytorch#18811. This makes it so that we emit a higher-precision literal for float values in the fusion kernel, as well as assign that to a `double` variable. This prevents us from losing precision for values such as `pi`, but with the previous fixes this will also get downcasted to `float` if downstream operations require it. Therefore, we should not lose performance because of implicit promotions Pull Request resolved: pytorch#18817 Differential Revision: D14820842 Pulled By: jamesr66a fbshipit-source-id: 519671c6ca5e7adac746a4c4c72760a6d91e332f
Stacked on #18811
This makes it so that we only emit the *f variants of math functions if the output value's type is FloatTensor, otherwise we call the double variants to prevent loss of precision. This fixes more numerical issues