Uh oh!
There was an error while loading. Please reload this page.
[ONNX] Add imports for BERT contrib operators - #10949
Conversation
Co-authored-by: An Wang <anwang2009@gmail.com>
AndrewZhaoLuo
left a comment
There was a problem hiding this comment.
Do you have reference implementation of these operators? Did not look too closely at impl but a few comments.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
AndrewZhaoLuo
left a comment
There was a problem hiding this comment.
LGTM generally, but would appreciate another pair of eyes @margaretqian@sfvaroglu
Uh oh!
There was an error while loading. Please reload this page.
| if beta: | ||
| output = _op.add(output, beta) | ||
| placeholder = _op.const(0, dtype="float32") |
There was a problem hiding this comment.
what is this placeholder for? optional returns are mean and inverse standard variance right?
There was a problem hiding this comment.
that's true according to the documentation, however both CUDA and C++ onnxruntime implementations of the kernels do not actually ever return or calculate values for these outputs:
https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/contrib_ops/cpu/skip_layer_norm.cc
https://github.com/microsoft/onnxruntime/blob/master/onnxruntime/contrib_ops/cuda/bert/skip_layer_norm.cc
| eps_dtype = infer_type(x).checked_type.dtype | ||
| u, s = _op.mean_variance(x, axis=-1, keepdims=True) | ||
| output = _op.divide( | ||
| _op.subtract(x, u), | ||
| _op.sqrt(_op.add(s, _op.const(eps, dtype=eps_dtype))), | ||
| ) | ||
| output = _op.multiply(output, gamma) |
There was a problem hiding this comment.
nit: this is basically same normalization calculation as 877-886 above right? if it's easy, can we pull it out into a common helper function?
| if segment_ids: | ||
| vec_sum = _op.add(vec_sum, segment_vec) | ||
| ln = SkipLayerNormalization._compute_layer_norm(vec_sum, eps, gamma, beta) |
There was a problem hiding this comment.
nit: maybe instead of referencing SkipLayerNormalization here, you could create a LayerNormalization base class that contains _compute_layer_norm? sort of like how Pool is the base class for MaxPool/AveragePool etc?
There was a problem hiding this comment.
redefining _compute_layer_norm as a global func in this file -- won't put it in a separate class as semantically LayerNorm is not an onnx operator.
Uh oh!
There was an error while loading. Please reload this page.
* main: (527 commits) [hexagon] 'add_hvx' test to explore HVX usage. (apache#10604) [COMMUNITY] @yzh119 -> Reviewer (apache#10993) [Metaschedule] Make custom schedule_rule registration optional (apache#10975) [ONNX] Add imports for BERT contrib operators (apache#10949) sort axes (apache#10985) [Hexagon] Remove HexagonBuffer external constructor and support (apache#10978) [CI] Update GPU image (apache#10992) [Runtime][Vulkan] Add RGP support to TVM for vulkan device (apache#10953) [FIX] resolve int64/32 for AttrStmtNode (apache#10983) [TVMC] Allow output module name to be passed as a command line argument (apache#10962) [ONNX] Add MatMulInteger importer (apache#10450) [COMMUNITY] @guberti -> Reviewer (apache#10976) Support `qnn.conv2d` in FoldExplicitPading (apache#10982) change Hexagon docker version (apache#10981) remove exception handling of autotvm xgboost extract functions (apache#10948) [CUDNN] Add partitioning support for conv2d and log_softmax (apache#10961) [Hexagon][LLVM] Enable/test tensorized Hexagon DMA on 2d transformed layout (apache#10905) [Hexagon] Move aot/graph_executor interactions into launcher (apache#10907) [HEXAGON] Split huge 1D DMA Transfers into smaller transfers with legal sizes. (apache#10971) [CI][DOCKER] Add pytest-lazy-fixture to images (apache#10970) ...
* EmbedLayerNormalization, Attention * fix Attention * SkipLayerNormalization * fix dtype bug in Gelu Co-authored-by: An Wang <anwang2009@gmail.com> * missing parameterize_targets * lint * lint * comments * fix small thing * factor out layer norm computation * layernorm func * add optional args to test * upgrade onnxrt version * no upgrade onnx * fix tests * int32 * fix tests Co-authored-by: An Wang <anwang2009@gmail.com>
Attention,EmbedLayerNormalization,SkipLayerNormalizationGeluimportcc @AndrewZhaoLuo@margaretqian@sfvaroglu