-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[Relay/TOPI][ONNX/TFLite] Refactor MATRIX_SET_DIAG Operator for Relay… #9329
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
Changes from 1 commit
e69cf62
59ae654
139f815
ae01089
26bb240
8003ec1
ab40d80
1ddf089
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4226,6 +4226,35 @@ def _impl_v1(cls, inputs, attr, params): | |
| return _expr.TupleWrapper(_expr.Tuple(result), len(result)) | ||
|
|
||
|
|
||
| class Trilu(OnnxOpConverter): | ||
| """Operator converter for Trilu""" | ||
|
|
||
| @classmethod | ||
| def _impl_v1(cls, inputs, attr, params): | ||
|
||
| upper = attr.get("upper") | ||
|
||
| input_shape = shape_of(inputs[0]) | ||
| input_dims = infer_shape(input_shape)[0] | ||
| data_type = infer_type(inputs[0]).checked_type.dtype | ||
| k_tensor = relay.const(np.asarray([0], dtype=np.int64)) | ||
| if len(inputs) == 2: | ||
| k_tensor = inputs[1] | ||
|
|
||
| diag_input = relay.zeros(fold_constant(shape_of(inputs[0])), dtype=data_type) | ||
|
|
||
| if upper == 0: | ||
| k1 = relay.add(k_tensor, relay.const(1, dtype="int64")) | ||
| k2 = relay.take(input_shape, relay.const(input_dims - 1, dtype="int32")) | ||
| k2 = relay.expand_dims(k2, axis=0) | ||
| return relay.matrix_set_diag(inputs[0], diag_input, k=(k1, k2)) | ||
| else: | ||
| k1 = relay.take(input_shape, relay.const(input_dims-2, dtype="int32")) | ||
| k1 = relay.multiply(k1, relay.const(-1, dtype="int64")) | ||
| k1 = relay.subtract(k1, relay.const(1, dtype="int64")) | ||
| k1 = relay.expand_dims(k1, axis=0) | ||
| k2 = relay.subtract(k_tensor, relay.const(1, dtype="int64")) | ||
| return relay.matrix_set_diag(inputs[0], diag_input, k=(k1, k2)) | ||
|
|
||
|
|
||
| # compatible operators that do NOT require any conversion. | ||
| _identity_list = [] | ||
|
|
||
|
|
@@ -4425,6 +4454,7 @@ def _get_convert_map(opset): | |
| "Adagrad": Adagrad.get_converter(opset), | ||
| "Adam": Adam.get_converter(opset), | ||
| "Momentum": Momentum.get_converter(opset), | ||
| "Trilu": Trilu.get_converter(opset), | ||
| } | ||
|
|
||
|
|
||
|
|
||
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.
I believe (though please check) that you can just do k2() for 0-D tensor access.
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.
ok
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.
k2() will report error
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.
Eh ok