Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions python/tvm/relax/frontend/onnx/onnx_frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,10 @@ def _impl_v17(cls, bb, inputs, attr, params):
axis = attr.get("axis", -1)
epsilon = attr.get("epsilon", 1e-05)

if bias is None:
seq_len = data.struct_info.shape[1].value
bias = relax.const([0.0] * seq_len, dtype="float32")

output = relax.op.nn.layer_norm(data, scale, bias, axis, epsilon)
# Onnx layernorm has 3 outputs but only the first is used.
# We construct two empty constants for this.
Expand Down
18 changes: 18 additions & 0 deletions tests/python/relax/test_frontend_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1303,6 +1303,24 @@ def test_layer_norm():
model = helper.make_model(graph, producer_name="layer_norm_test")
check_correctness(model)

# Test case with no bias that is an optional input
layer_norm_node = helper.make_node("LayerNormalization", ["a", "b"], ["d"], epsilon=1e-12)

graph = helper.make_graph(
[layer_norm_node],
"layer_norm_test",
inputs=[
helper.make_tensor_value_info("a", TensorProto.FLOAT, [32, 32]),
helper.make_tensor_value_info("b", TensorProto.FLOAT, [32]),
],
outputs=[
helper.make_tensor_value_info("d", TensorProto.FLOAT, [32, 32]),
],
)

model = helper.make_model(graph, producer_name="layer_norm_test")
check_correctness(model)


# TODO Enable dynamism
@pytest.mark.parametrize("dynamic", [False])
Expand Down