-
Notifications
You must be signed in to change notification settings - Fork 14
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
feat: simplify operations with sign
#336
base: main
Are you sure you want to change the base?
Conversation
Some of these need to be qualified using no_nan |
// (select (x > 0) z (neg z)) -> (mul (sign x) z) | ||
// (select (x >= 0) z (neg z)) -> (mul (sign x) z) | ||
// (select (x > 0) (neg z) z) -> (mul (sign x) (neg z)) | ||
// (select (x >= 0) (neg z) z) -> (mul (sign x) (neg z)) |
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.
is this actually simpler/faster?
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 one mostly enables the other optimizations.
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.
a select is usually faster than a mul, so this in isolation makes things locally worse. Is it feasible for the downstream operations to work on select style forms?
}; | ||
|
||
// (mul (sign x) (abs x)) -> x | ||
// (mul (abs x) (sign x)) -> x |
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 seems reasonable, can you split to do this individually?
}; | ||
|
||
// (mul (neg x) (neg y)) -> (mul x y) | ||
// (mul (neg x) y) -> (neg (mul x y)) |
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.
top one is always good, the one negation variations we should separate since there's a separate question of whether we want to propagate them up or down (e.g. if we had mul (neg x), constant) we'd want to do mul x (-constant)
|
||
// This pattern only does partially the following. We rely on transforming the op to a | ||
// pattern which further uses the above pattern. | ||
// (mul (sign x) (add (abs x) (abs x))) -> (mul x x) |
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.
longer term i feel like this merits a broader sign analysis (alongside perhaps a transpose analysis)
Trying to simplify
most of the internal operations are actually no-ops (this is from a chunk inside a transformer so kind of a common pattern). After these passes