Skip to content
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

[ONNX] [Test] fix GRU modification and reduce tolerance for RNN tests #8923

Merged
merged 2 commits into from
Sep 8, 2021
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
3 changes: 2 additions & 1 deletion python/tvm/relay/frontend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,12 +726,13 @@ def gru_cell(
b_ir, b_iz, b_in = _op.split(b_inp, 3, axis=-1)
b_hr, b_hz, b_hn = _op.split(b_hid, 3, axis=-1)
r_gate += b_ir + b_hr
r_gate = rz_act(r_gate)
z_gate += b_iz + b_hz
i_n += b_in
h_n = _op.nn.dense((r_gate * hidden_state), w_hn) + b_hn
else:
r_gate = rz_act(r_gate)
h_n = _op.nn.dense((r_gate * hidden_state), w_hn)
r_gate = rz_act(r_gate)
z_gate = rz_act(z_gate)
n_gate = n_act(i_n + h_n)

Expand Down
26 changes: 24 additions & 2 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,8 @@ def verify_rnn(
use_peep=False,
linear_before_reset=False,
directions=1,
rtol=1e-5,
atol=1e-5,
target=None,
dev=None,
):
Expand Down Expand Up @@ -3433,7 +3435,7 @@ def register(name, shape, proto_type):
model = helper.make_model(graph, producer_name="rnn_test")

verify_with_ort_with_inputs(
model, input_values, output_shapes, atol=1e-2, rtol=1e-2, target=target, dev=dev
model, input_values, output_shapes, atol=atol, rtol=rtol, target=target, dev=dev
)


Expand Down Expand Up @@ -3589,6 +3591,8 @@ def test_lstm(target, dev):

@tvm.testing.parametrize_targets
def test_gru(target, dev):
# Set seed for test reproduction
np.random.seed(137)
for directions in [1, 2]:
# No bias.
verify_rnn(
Expand All @@ -3599,10 +3603,12 @@ def test_gru(target, dev):
use_bias=False,
rnn_type="GRU",
directions=directions,
rtol=1e-6,
atol=1e-6,
target=target,
dev=dev,
)
# large batch.
# large batch. linear before reset
verify_rnn(
seq_length=4,
batch_size=8,
Expand All @@ -3624,6 +3630,8 @@ def test_gru(target, dev):
use_bias=True,
rnn_type="GRU",
directions=directions,
rtol=1e-6,
atol=1e-6,
target=target,
dev=dev,
)
Expand All @@ -3636,6 +3644,8 @@ def test_gru(target, dev):
use_bias=True,
rnn_type="GRU",
directions=directions,
rtol=1e-6,
atol=1e-6,
target=target,
dev=dev,
)
Expand All @@ -3648,6 +3658,8 @@ def test_gru(target, dev):
use_bias=True,
rnn_type="GRU",
directions=directions,
rtol=1e-6,
atol=1e-6,
target=target,
dev=dev,
)
Expand All @@ -3660,6 +3672,8 @@ def test_gru(target, dev):
use_bias=True,
rnn_type="GRU",
directions=directions,
rtol=1e-6,
atol=1e-6,
target=target,
dev=dev,
)
Expand All @@ -3675,6 +3689,8 @@ def test_gru(target, dev):
activations=["HardSigmoid", "Softsign"] * directions,
rnn_type="GRU",
directions=directions,
rtol=1e-6,
atol=1e-6,
target=target,
dev=dev,
)
Expand All @@ -3690,6 +3706,8 @@ def test_gru(target, dev):
betas=[0.3, 0.0] * directions,
rnn_type="GRU",
directions=directions,
rtol=1e-8,
atol=1e-8,
target=target,
dev=dev,
)
Expand All @@ -3705,6 +3723,8 @@ def test_gru(target, dev):
betas=[0.3, 0.1] * directions,
rnn_type="GRU",
directions=directions,
rtol=1e-8,
atol=1e-8,
target=target,
dev=dev,
)
Expand All @@ -3719,6 +3739,8 @@ def test_gru(target, dev):
use_initial_state=True,
rnn_type="GRU",
directions=directions,
rtol=1e-6,
atol=1e-6,
target=target,
dev=dev,
)
Expand Down