-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add support for clamp op #1093
base: main
Are you sure you want to change the base?
Add support for clamp op #1093
Conversation
mmanzoorTT
commented
Oct 28, 2024
•
edited
Loading
edited
- Add end-to-end implementation of the ops.
- Add stablehlo to ttir conversion for clamp op.
9e02a6c
to
e577be2
Compare
e577be2
to
22c9ac2
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.
add a clamp and clip test for perf_unit under Silicon/TTNN/perf_unit
22c9ac2
to
e5b91bb
Compare
@tapspatel tests added. thanks |
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.
flatbuffer files and .mlir files look good!
Clip is just an alias for clamp op, do we want both ops in TTIR? |
I added it to have one-to-one mapping between TTIR and TTNN. I can remove |
Example: | ||
min: 2.000000+00 | ||
input: [[0, 1, 2, 3, 4, 5, 6, 7]] | ||
max: 5.000000+00 |
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.
Doesn't stablehlo.clamp
support more general form of this op where all three are tensors?
https://openxla.org/stablehlo/spec#clamp
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.
Yes, stablehlo.clamp
uses tensor operands for all inputs. However ttnn.clamp
uses floats for min
and max
. If we can determine single value for min
and max
tensor (e.g. min and max tensors are constant splat vectors). Then I am using these single values as floats and lowering stablehlo.clamp
to ttir.clamp
and then to ttnn.clamp
. If a single value can not be determined then stablehlo.clamp
is lowered to sequence of ttir.minimum
and ttir.maximum
ops as below.
output = ttnn.minimum(ttnn.maximum(input , min_tensor), max_tensor)
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.
Hm, interesting. I had the same problem with power
op #1094.
@mrakitaTT since stablehlo.clamp
defines args like this
let arguments = (ins
HLO_Tensor:$min, /*clamp_i1*/
HLO_Tensor:$operand, /*clamp_c3, clamp_i2*/
HLO_Tensor:$max /*clamp_i3*/
);
let results = (outs HLO_Tensor:$result);
should TTIR
have 1:1 matching arg interface or is
let arguments = (ins AnyRankedTensor:$input,
AnyRankedTensor:$output,
F32Attr:$min,
F32Attr:$max,
TT_OperandConstraintArrayAttr:$operand_constraints);
ok, considering what Asif said above?
I am not blocking, just wondering what would be the best solution. I saw that TTNN also aliases one op to another, hence maybe we should keep them both... |
e5b91bb
to
d74020f
Compare
b9ca61f
to
07dcf58
Compare
We agreed to keep a single op per the discussion here: Please keep only the clamp and remove the clip op from this PR. |
@sdjordjevicTT Do you mean to remove |
We synced over the slack and agreed to remove the ttir.clip op entirely. |
07dcf58
to
f72633f
Compare
@sdjordjevicTT clip op removed entirely. |
f72633f
to
669e8a0
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.
Runtime changes look good!
* Add end-to-end implementation of the ops. * Add stablehlo to ttir conversion for clamp op.
669e8a0
to
eb276be
Compare
@@ -850,6 +850,33 @@ def TTIR_UnsqueezeOp : TTIR_DPSOp<"unsqueeze"> { | |||
let hasVerifier = 1; | |||
} | |||
|
|||
def TTIR_ClampOp : TTIR_DPSOp<"clamp"> { |
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.
Should we add some verifier for the op? For example, should we check that the output shape is the same as the input shape?