You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/08/18 08:11:30 UTC
[GitHub] [tvm] vvchernov opened a new pull request #8781: WIP: [Frontend] [Torch] [ONNX] GRU layer
vvchernov opened a new pull request #8781:
URL: https://github.com/apache/tvm/pull/8781
WORK IN PROGRESS:
The following issues were observed during testing:
1. Current onnx frontend implementation with activation fix fails accuracy test for stacked modification after tuning. There is no issue without tuning and for stacked bidiractional one (or may be not observed)!
2. New pytorch GRU has the same problem. Note: onnx and pytorch GRU close but different implementations.
3. More advanced implementation of GRU is faster on more than 20% but has stable accuracy failures for tvm tuning and no problem without it. It is implemented locally while issue is not resolved.
4. Onnx GRU has issues related wrong implementation but unit test checks accuracy and does not catch it. Need more detail investigation, potentially it can be big problem.
5. Strong difference of performance results for ONNX and new pytroch GRU. Adding new implementation to ONNX frontend instead of current one is planned.
GRU cell was unified and implemented in common.py. It is used by pytorch frontend of TVM. Critical fix was done on ONNX GRU implementation side. Performance tests for different modification of GRU before and after new implementation were carried out. The results are collected in the table:
Table 1. Average time per run (microsec) for 10000 runs. The following parameters are used (small input size): with biases = True, batch first = True, linear before reset = True, feature size = 5, hidden size = 10, number of stacked layers = 2, sequence length = 3, batch size = 1, trials number = 100. TVM target is “llvm -mcpu=core-avx2”
| Frontend name/GRU type | uni | b | s | sb |
| :-----------------------------| :-----:|:------:|:-------:|:-------:|
|Onnx | 23.3 | 48.6 | 46.4 | 100.8 |
|Onnx tuned | 8.37 | 15.25 | 14.35 | 28.1 |
Pytorch implemented | 7.42 | 13.0 | 12.8 | 24.7 |
Pytorch impl tuned | 3.2 | 4.91 | 4.77 | 8.43 |
Onnxruntime | 13.06 | 16.89 | 19.2 | 25.9 |
There are several GRU types: uni – unidirectional, b – bidirectional, s – stacked (2 layers are used in the tests), sb - stacked bidirectional. Compiled by TVM pytorch GRU is faster than tuned ONNX GRU and onnxruntime! Tuned pytorch is strongly quicker.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi commented on pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#issuecomment-903414959
@vvchernov Please add PyTorch GRU tests.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a change in pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#discussion_r693628005
##########
File path: python/tvm/relay/frontend/common.py
##########
@@ -658,6 +658,92 @@ def unbind(data, axis=0):
return _expr.TupleWrapper(_expr.Tuple(ret), selections)
+def gru_cell(
+ input_seqs,
+ hidden_state,
+ w_inp,
+ w_hid,
+ b_inp=None,
+ b_hid=None,
+ rz_act=_op.sigmoid,
+ n_act=_op.tanh,
+ backwards=False,
+ linear_before_reset=True,
+):
+ """
+ Common implementation of GRU cell for all frontends of TVM
+ TODO(vvchernov): currently it is used by pytorch. Extend for other frontends
+
+ Parameters
+ ----------
+ input_seqs : List[relay.Expr]
+ The sequence of input tensors
+ Input tensor should be 2d while issue #8412 is not resolved
+ Shape = (batch, feature_size)
+ hidden_state : relay.Expr
+ Hidden state. shape = (batch_size, hidden_size)
+ w_inp, w_hid : relay.Expr
+ weight matrices. wi shape = (3 * hidden_size, feature_size)
+ wh shape = (3 * hidden_size, hidden_size)
+ NOTE: wi = (w_ir|w_iz|w_in) for reset, update and new gates.
+ The order is important for correct GRU calculation!
+ b_inp, b_hid : relay.Expr
+ bias matrices. The same order of internal parts as for weights. shape = (3 * hidden_size)
+ r_act : relay.op
+ activation funtion for reset gate. it is sigmoid by default
+ z_act : relay.op
+ activation funtion for update gate. it is sigmoid by default
+ n_act : relay.op
+ activation funtion for new gate. it is tanh by default
+ backwards : bool
+ Flag for reverse pass of GRU
+
+ Returns
+ -------
+ result : List[relay.Expr], relay.Expr, relay.Expr
+ The sequence of computed result, final hidden and cell state
+ """
+
+ outputs_list = []
+ for x_t in input_seqs if not backwards else reversed(input_seqs):
+ xwt = _op.nn.dense(x_t, w_inp)
+ if linear_before_reset:
+ hwt = _op.nn.dense(hidden_state, w_hid)
+ # TODO(vvchernov): It is assumed that both bias are or not
Review comment:
What do you mean by `both bias are or not`? This sentence doesn't make sense, needs correction
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a change in pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#discussion_r693627752
##########
File path: python/tvm/relay/frontend/common.py
##########
@@ -658,6 +658,92 @@ def unbind(data, axis=0):
return _expr.TupleWrapper(_expr.Tuple(ret), selections)
+def gru_cell(
+ input_seqs,
+ hidden_state,
+ w_inp,
+ w_hid,
+ b_inp=None,
+ b_hid=None,
+ rz_act=_op.sigmoid,
+ n_act=_op.tanh,
+ backwards=False,
+ linear_before_reset=True,
+):
+ """
+ Common implementation of GRU cell for all frontends of TVM
+ TODO(vvchernov): currently it is used by pytorch. Extend for other frontends
Review comment:
Also used by ONNX?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vvchernov commented on a change in pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
vvchernov commented on a change in pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#discussion_r693711953
##########
File path: python/tvm/relay/frontend/common.py
##########
@@ -658,6 +658,92 @@ def unbind(data, axis=0):
return _expr.TupleWrapper(_expr.Tuple(ret), selections)
+def gru_cell(
+ input_seqs,
+ hidden_state,
+ w_inp,
+ w_hid,
+ b_inp=None,
+ b_hid=None,
+ rz_act=_op.sigmoid,
+ n_act=_op.tanh,
+ backwards=False,
+ linear_before_reset=True,
+):
+ """
+ Common implementation of GRU cell for all frontends of TVM
+ TODO(vvchernov): currently it is used by pytorch. Extend for other frontends
Review comment:
done
##########
File path: python/tvm/relay/frontend/common.py
##########
@@ -658,6 +658,92 @@ def unbind(data, axis=0):
return _expr.TupleWrapper(_expr.Tuple(ret), selections)
+def gru_cell(
+ input_seqs,
+ hidden_state,
+ w_inp,
+ w_hid,
+ b_inp=None,
+ b_hid=None,
+ rz_act=_op.sigmoid,
+ n_act=_op.tanh,
+ backwards=False,
+ linear_before_reset=True,
+):
+ """
+ Common implementation of GRU cell for all frontends of TVM
+ TODO(vvchernov): currently it is used by pytorch. Extend for other frontends
+
+ Parameters
+ ----------
+ input_seqs : List[relay.Expr]
+ The sequence of input tensors
+ Input tensor should be 2d while issue #8412 is not resolved
+ Shape = (batch, feature_size)
+ hidden_state : relay.Expr
+ Hidden state. shape = (batch_size, hidden_size)
+ w_inp, w_hid : relay.Expr
+ weight matrices. wi shape = (3 * hidden_size, feature_size)
+ wh shape = (3 * hidden_size, hidden_size)
+ NOTE: wi = (w_ir|w_iz|w_in) for reset, update and new gates.
+ The order is important for correct GRU calculation!
+ b_inp, b_hid : relay.Expr
+ bias matrices. The same order of internal parts as for weights. shape = (3 * hidden_size)
+ r_act : relay.op
+ activation funtion for reset gate. it is sigmoid by default
+ z_act : relay.op
+ activation funtion for update gate. it is sigmoid by default
+ n_act : relay.op
+ activation funtion for new gate. it is tanh by default
+ backwards : bool
+ Flag for reverse pass of GRU
+
+ Returns
+ -------
+ result : List[relay.Expr], relay.Expr, relay.Expr
+ The sequence of computed result, final hidden and cell state
+ """
+
+ outputs_list = []
+ for x_t in input_seqs if not backwards else reversed(input_seqs):
+ xwt = _op.nn.dense(x_t, w_inp)
+ if linear_before_reset:
+ hwt = _op.nn.dense(hidden_state, w_hid)
+ # TODO(vvchernov): It is assumed that both bias are or not
Review comment:
fixed
##########
File path: python/tvm/relay/frontend/common.py
##########
@@ -658,6 +658,92 @@ def unbind(data, axis=0):
return _expr.TupleWrapper(_expr.Tuple(ret), selections)
+def gru_cell(
+ input_seqs,
+ hidden_state,
+ w_inp,
+ w_hid,
+ b_inp=None,
+ b_hid=None,
+ rz_act=_op.sigmoid,
+ n_act=_op.tanh,
+ backwards=False,
+ linear_before_reset=True,
+):
+ """
+ Common implementation of GRU cell for all frontends of TVM
+ TODO(vvchernov): currently it is used by pytorch. Extend for other frontends
+
+ Parameters
+ ----------
+ input_seqs : List[relay.Expr]
+ The sequence of input tensors
+ Input tensor should be 2d while issue #8412 is not resolved
+ Shape = (batch, feature_size)
+ hidden_state : relay.Expr
+ Hidden state. shape = (batch_size, hidden_size)
+ w_inp, w_hid : relay.Expr
+ weight matrices. wi shape = (3 * hidden_size, feature_size)
+ wh shape = (3 * hidden_size, hidden_size)
+ NOTE: wi = (w_ir|w_iz|w_in) for reset, update and new gates.
+ The order is important for correct GRU calculation!
+ b_inp, b_hid : relay.Expr
+ bias matrices. The same order of internal parts as for weights. shape = (3 * hidden_size)
+ r_act : relay.op
+ activation funtion for reset gate. it is sigmoid by default
+ z_act : relay.op
+ activation funtion for update gate. it is sigmoid by default
+ n_act : relay.op
+ activation funtion for new gate. it is tanh by default
+ backwards : bool
+ Flag for reverse pass of GRU
+
+ Returns
+ -------
+ result : List[relay.Expr], relay.Expr, relay.Expr
+ The sequence of computed result, final hidden and cell state
+ """
+
+ outputs_list = []
+ for x_t in input_seqs if not backwards else reversed(input_seqs):
+ xwt = _op.nn.dense(x_t, w_inp)
+ if linear_before_reset:
+ hwt = _op.nn.dense(hidden_state, w_hid)
+ # TODO(vvchernov): It is assumed that both bias are or not
+ if b_inp is not None:
+ xwt += b_inp
+ hwt += b_hid
+ i_r, i_z, i_n = _op.split(xwt, 3, axis=-1)
+ h_r, h_z, h_n = _op.split(hwt, 3, axis=-1)
+ r_gate = rz_act(i_r + h_r)
+ z_gate = rz_act(i_z + h_z)
+ n_gate = n_act(i_n + r_gate * h_n)
+ else:
+ i_r, i_z, i_n = _op.split(xwt, 3, axis=1)
+ w_hr, w_hz, w_hn = _op.split(w_hid, 3, axis=0)
+ r_gate = i_r + _op.nn.dense(hidden_state, w_hr)
+ z_gate = i_z + _op.nn.dense(hidden_state, w_hz)
+ # TODO(vvchernov): It is assumed that both bias are or not
Review comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vvchernov commented on pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
vvchernov commented on pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#issuecomment-903498602
Seems that https://github.com/apache/tvm/blob/main/tests/python/frontend/pytorch/test_forward.py#L4105 duplicates custom lstm test (pytest finds it by its-self). My lstm and gru tests in test_rnns.py but I can transfer them to test_forward.py if need.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi commented on pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#issuecomment-905267004
Thanks @vvchernov
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi merged pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi merged pull request #8781:
URL: https://github.com/apache/tvm/pull/8781
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a change in pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#discussion_r693628005
##########
File path: python/tvm/relay/frontend/common.py
##########
@@ -658,6 +658,92 @@ def unbind(data, axis=0):
return _expr.TupleWrapper(_expr.Tuple(ret), selections)
+def gru_cell(
+ input_seqs,
+ hidden_state,
+ w_inp,
+ w_hid,
+ b_inp=None,
+ b_hid=None,
+ rz_act=_op.sigmoid,
+ n_act=_op.tanh,
+ backwards=False,
+ linear_before_reset=True,
+):
+ """
+ Common implementation of GRU cell for all frontends of TVM
+ TODO(vvchernov): currently it is used by pytorch. Extend for other frontends
+
+ Parameters
+ ----------
+ input_seqs : List[relay.Expr]
+ The sequence of input tensors
+ Input tensor should be 2d while issue #8412 is not resolved
+ Shape = (batch, feature_size)
+ hidden_state : relay.Expr
+ Hidden state. shape = (batch_size, hidden_size)
+ w_inp, w_hid : relay.Expr
+ weight matrices. wi shape = (3 * hidden_size, feature_size)
+ wh shape = (3 * hidden_size, hidden_size)
+ NOTE: wi = (w_ir|w_iz|w_in) for reset, update and new gates.
+ The order is important for correct GRU calculation!
+ b_inp, b_hid : relay.Expr
+ bias matrices. The same order of internal parts as for weights. shape = (3 * hidden_size)
+ r_act : relay.op
+ activation funtion for reset gate. it is sigmoid by default
+ z_act : relay.op
+ activation funtion for update gate. it is sigmoid by default
+ n_act : relay.op
+ activation funtion for new gate. it is tanh by default
+ backwards : bool
+ Flag for reverse pass of GRU
+
+ Returns
+ -------
+ result : List[relay.Expr], relay.Expr, relay.Expr
+ The sequence of computed result, final hidden and cell state
+ """
+
+ outputs_list = []
+ for x_t in input_seqs if not backwards else reversed(input_seqs):
+ xwt = _op.nn.dense(x_t, w_inp)
+ if linear_before_reset:
+ hwt = _op.nn.dense(hidden_state, w_hid)
+ # TODO(vvchernov): It is assumed that both bias are or not
Review comment:
What do you mean by `both bias are or not`?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a change in pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#discussion_r693628271
##########
File path: python/tvm/relay/frontend/common.py
##########
@@ -658,6 +658,92 @@ def unbind(data, axis=0):
return _expr.TupleWrapper(_expr.Tuple(ret), selections)
+def gru_cell(
+ input_seqs,
+ hidden_state,
+ w_inp,
+ w_hid,
+ b_inp=None,
+ b_hid=None,
+ rz_act=_op.sigmoid,
+ n_act=_op.tanh,
+ backwards=False,
+ linear_before_reset=True,
+):
+ """
+ Common implementation of GRU cell for all frontends of TVM
+ TODO(vvchernov): currently it is used by pytorch. Extend for other frontends
+
+ Parameters
+ ----------
+ input_seqs : List[relay.Expr]
+ The sequence of input tensors
+ Input tensor should be 2d while issue #8412 is not resolved
+ Shape = (batch, feature_size)
+ hidden_state : relay.Expr
+ Hidden state. shape = (batch_size, hidden_size)
+ w_inp, w_hid : relay.Expr
+ weight matrices. wi shape = (3 * hidden_size, feature_size)
+ wh shape = (3 * hidden_size, hidden_size)
+ NOTE: wi = (w_ir|w_iz|w_in) for reset, update and new gates.
+ The order is important for correct GRU calculation!
+ b_inp, b_hid : relay.Expr
+ bias matrices. The same order of internal parts as for weights. shape = (3 * hidden_size)
+ r_act : relay.op
+ activation funtion for reset gate. it is sigmoid by default
+ z_act : relay.op
+ activation funtion for update gate. it is sigmoid by default
+ n_act : relay.op
+ activation funtion for new gate. it is tanh by default
+ backwards : bool
+ Flag for reverse pass of GRU
+
+ Returns
+ -------
+ result : List[relay.Expr], relay.Expr, relay.Expr
+ The sequence of computed result, final hidden and cell state
+ """
+
+ outputs_list = []
+ for x_t in input_seqs if not backwards else reversed(input_seqs):
+ xwt = _op.nn.dense(x_t, w_inp)
+ if linear_before_reset:
+ hwt = _op.nn.dense(hidden_state, w_hid)
+ # TODO(vvchernov): It is assumed that both bias are or not
+ if b_inp is not None:
+ xwt += b_inp
+ hwt += b_hid
+ i_r, i_z, i_n = _op.split(xwt, 3, axis=-1)
+ h_r, h_z, h_n = _op.split(hwt, 3, axis=-1)
+ r_gate = rz_act(i_r + h_r)
+ z_gate = rz_act(i_z + h_z)
+ n_gate = n_act(i_n + r_gate * h_n)
+ else:
+ i_r, i_z, i_n = _op.split(xwt, 3, axis=1)
+ w_hr, w_hz, w_hn = _op.split(w_hid, 3, axis=0)
+ r_gate = i_r + _op.nn.dense(hidden_state, w_hr)
+ z_gate = i_z + _op.nn.dense(hidden_state, w_hz)
+ # TODO(vvchernov): It is assumed that both bias are or not
Review comment:
Fix this comment too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi commented on pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#issuecomment-903623984
Please try removing duplication between GRU and LSTM tests. For example, I don't want to see
```
for batch_first in (True, False):
for use_bias in (True, False):
for rnd_weights in [True]: # (True, False):
```
repeated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] masahi commented on a change in pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
masahi commented on a change in pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#discussion_r693834511
##########
File path: tests/python/frontend/pytorch/test_rnns.py
##########
@@ -173,6 +253,115 @@ def compare(input, gold_data, rtol=1e-5, atol=1e-5):
tvm.testing.assert_allclose(input, gold_data, rtol=rtol, atol=atol)
+def check_gru_with_type(gru_type, target=tvm.target.Target("llvm -mcpu=core-avx2"), dev=tvm.cpu(0)):
+ device = torch.device("cpu")
+ hidden_layers_num = 1
+ model = None
+ for batch_first in (True, False):
+ for use_bias in (True, False):
+ for rnd_weights in [True]: # (True, False):
+ if gru_type == "uni":
+ model = GRU_Model(
+ device,
+ batch_first=batch_first,
+ rnd_weights_init=rnd_weights,
+ use_bias=use_bias,
+ )
+ elif gru_type == "b":
+ model = GRU_Model(
+ device,
+ batch_first=batch_first,
+ bidirectional=True,
+ rnd_weights_init=rnd_weights,
+ use_bias=use_bias,
+ )
+ hidden_layers_num = 2
+ elif gru_type == "s":
+ model = GRU_Model(
+ device,
+ batch_first=batch_first,
+ layer_num=gru_num_layers,
+ rnd_weights_init=rnd_weights,
+ use_bias=use_bias,
+ )
+ hidden_layers_num = gru_num_layers
+ elif gru_type == "sb":
+ model = GRU_Model(
+ device,
+ batch_first=batch_first,
+ bidirectional=True,
+ layer_num=gru_num_layers,
+ rnd_weights_init=rnd_weights,
+ use_bias=use_bias,
+ )
+ hidden_layers_num = 2 * gru_num_layers
+ else:
+ print("WARNING: GRU type {} is not supported here!".format(gru_type))
+ return
+
+ model.eval()
+
+ # Get golden output from original model
+ input_hidden_shape = (hidden_layers_num, batch_size, gru_hidden_size)
+ dummy_input, input_shape = model.get_dummy_input()
+ golden_output_batch = model.forward(dummy_input.to(device)).detach().cpu().numpy()
+
+ dtype = "float32"
+ h_zeros = np.zeros(input_hidden_shape, dtype=dtype)
+
+ tvm_output = None
+ for format in ["ts"]: # ["ts", "onnx"]:
Review comment:
This looks like copy paste form the LSTM test. Remove onnx stuff, or use common function for testing both GRU or LSTM.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] vvchernov commented on a change in pull request #8781: [Frontend] [Torch] [ONNX] GRU layer
Posted by GitBox <gi...@apache.org>.
vvchernov commented on a change in pull request #8781:
URL: https://github.com/apache/tvm/pull/8781#discussion_r694704248
##########
File path: tests/python/frontend/pytorch/test_rnns.py
##########
@@ -173,6 +253,115 @@ def compare(input, gold_data, rtol=1e-5, atol=1e-5):
tvm.testing.assert_allclose(input, gold_data, rtol=rtol, atol=atol)
+def check_gru_with_type(gru_type, target=tvm.target.Target("llvm -mcpu=core-avx2"), dev=tvm.cpu(0)):
+ device = torch.device("cpu")
+ hidden_layers_num = 1
+ model = None
+ for batch_first in (True, False):
+ for use_bias in (True, False):
+ for rnd_weights in [True]: # (True, False):
+ if gru_type == "uni":
+ model = GRU_Model(
+ device,
+ batch_first=batch_first,
+ rnd_weights_init=rnd_weights,
+ use_bias=use_bias,
+ )
+ elif gru_type == "b":
+ model = GRU_Model(
+ device,
+ batch_first=batch_first,
+ bidirectional=True,
+ rnd_weights_init=rnd_weights,
+ use_bias=use_bias,
+ )
+ hidden_layers_num = 2
+ elif gru_type == "s":
+ model = GRU_Model(
+ device,
+ batch_first=batch_first,
+ layer_num=gru_num_layers,
+ rnd_weights_init=rnd_weights,
+ use_bias=use_bias,
+ )
+ hidden_layers_num = gru_num_layers
+ elif gru_type == "sb":
+ model = GRU_Model(
+ device,
+ batch_first=batch_first,
+ bidirectional=True,
+ layer_num=gru_num_layers,
+ rnd_weights_init=rnd_weights,
+ use_bias=use_bias,
+ )
+ hidden_layers_num = 2 * gru_num_layers
+ else:
+ print("WARNING: GRU type {} is not supported here!".format(gru_type))
+ return
+
+ model.eval()
+
+ # Get golden output from original model
+ input_hidden_shape = (hidden_layers_num, batch_size, gru_hidden_size)
+ dummy_input, input_shape = model.get_dummy_input()
+ golden_output_batch = model.forward(dummy_input.to(device)).detach().cpu().numpy()
+
+ dtype = "float32"
+ h_zeros = np.zeros(input_hidden_shape, dtype=dtype)
+
+ tvm_output = None
+ for format in ["ts"]: # ["ts", "onnx"]:
Review comment:
done. Tests were unified
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org