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

fix gru, rnn, lstm test cases to match the specification and add some cases #920

Merged
merged 18 commits into from
May 24, 2018

Conversation

fumihwh
Copy link
Contributor

@fumihwh fumihwh commented May 9, 2018

lstm

  • cast zeros to np.float32. default np.float64 causes inconsistency of input's dtype.

lstm, rnn and gru

  • expand Y dim to match [seq_length, num_directions, batch_size, hidden_size]
  • add input seq_length = 2 's test case

@fumihwh fumihwh changed the title fix lstm test cases to match the specification and add precomputed case fix rnn, lstm test cases to match the specification and add some cases May 12, 2018
@fumihwh fumihwh changed the title fix rnn, lstm test cases to match the specification and add some cases fix gru, rnn, lstm test cases to match the specification and add some cases May 13, 2018
@prasanthpul prasanthpul requested a review from ebarsoum May 15, 2018 20:44
# Conflicts:
#	onnx/backend/test/case/node/gru.py
#	onnx/backend/test/case/node/lstm.py
#	onnx/backend/test/case/node/rnn.py
#	onnx/backend/test/data/node/test_gru_defaults/model.onnx
#	onnx/backend/test/data/node/test_gru_defaults/test_data_set_0/output_0.pb
#	onnx/backend/test/data/node/test_gru_with_initial_bias/model.onnx
#	onnx/backend/test/data/node/test_gru_with_initial_bias/test_data_set_0/output_0.pb
#	onnx/backend/test/data/node/test_lstm_defaults/model.onnx
#	onnx/backend/test/data/node/test_lstm_defaults/test_data_set_0/output_0.pb
#	onnx/backend/test/data/node/test_lstm_with_initial_bias/model.onnx
#	onnx/backend/test/data/node/test_lstm_with_initial_bias/test_data_set_0/output_0.pb
#	onnx/backend/test/data/node/test_lstm_with_peepholes/model.onnx
#	onnx/backend/test/data/node/test_lstm_with_peepholes/test_data_set_0/output_0.pb
#	onnx/backend/test/data/node/test_simple_rnn_defaults/model.onnx
#	onnx/backend/test/data/node/test_simple_rnn_defaults/test_data_set_0/output_0.pb
#	onnx/backend/test/data/node/test_simple_rnn_with_initial_bias/model.onnx
#	onnx/backend/test/data/node/test_simple_rnn_with_initial_bias/test_data_set_0/output_0.pb
@AppVeyorBot
Copy link

Build onnx 0.3.3299 completed (commit f7ad67e7e7 by @fumihwh)

@AppVeyorBot
Copy link

Build onnx 0.3.3301 completed (commit c0ee7c17b9 by @fumihwh)

# Conflicts:
#	onnx/backend/test/case/node/lstm.py
#	onnx/backend/test/data/node/test_lstm_defaults/model.onnx
#	onnx/backend/test/data/node/test_lstm_defaults/test_data_set_0/output_0.pb
#	onnx/backend/test/data/node/test_lstm_with_initial_bias/model.onnx
#	onnx/backend/test/data/node/test_lstm_with_initial_bias/test_data_set_0/output_0.pb
@AppVeyorBot
Copy link

Build onnx 0.3.3393 failed (commit 88f45dc176 by @fumihwh)

@linkerzhang linkerzhang requested a review from pk-g May 19, 2018 17:52
@bddppq bddppq requested a review from houseroad May 21, 2018 19:07

H = self.f(np.dot(self.X, np.transpose(self.W)) + np.dot(self.H_0, self.R) + w_b + r_b)
return np.reshape(H, (self.num_directions, self.batch_size, self.hidden_size))
h_list = []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of having this step function/implementation, shall we have the output result explicitly set in the test case please? otherwise, I'm seeing this case is testing "test code" (this step function).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@linkerzhang
I didn't get you.
Basically, we need this numpy implemented function to calculate the output result.
Maybe the name of function step is not good for you?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha, I was seeing this test case is testing the "step" function. I understood that it's used to generate the data. ignore this.


self.hidden_size = params[R].shape[-1]
Copy link
Contributor

@pk-g pk-g May 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other comment: Is there any specific reason why we are removing these parameters from the class and instead rely on local variables? this may put unnecessary limitations on reusing the values elsewhere.


b = params[B] if B in params else np.zeros(2 * number_of_gates * self.hidden_size)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any specific reason why we are removing these parameters from the class and instead rely on local variables? this may put unnecessary limitations on reusing the values elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to reuse hidden_size. All things (init b, p, h, c) need hidden_size is done when initialize class.
Even until last version doesn't have it.
The author of this version wanted to use hidden_size in step (to reshape the result) and put it in to class.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, sounds good.

lstm = LSTM_Helper(X=x, W=w, R=r, B=b)
output = lstm.step()

output_precomputed = np.array([[[[-0.09183919, -0.20181324, 0.04475278, -0.12022446,
Copy link
Contributor

@pk-g pk-g May 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these numbers coming from and what is the need to have them here instead of relying on reference implementation? Using precomputed numbers may create unnecessary complications going forward. For instance, If a particular framework generates numbers that do not match these numbers in future, how can we resolve conflicts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It comes from pytorch.
Yes, make sense. I will remove this.

# Conflicts:
#	onnx/backend/test/case/node/gru.py
#	onnx/backend/test/case/node/lstm.py
#	onnx/backend/test/case/node/rnn.py
@AppVeyorBot
Copy link

Build onnx 0.3.3468 failed (commit a88545a49f by @fumihwh)

# Conflicts:
#	onnx/backend/test/case/node/gru.py
#	onnx/backend/test/case/node/lstm.py
#	onnx/backend/test/data/node/test_gru_defaults/model.onnx
#	onnx/backend/test/data/node/test_gru_with_initial_bias/model.onnx
#	onnx/backend/test/data/node/test_lstm_defaults/model.onnx
#	onnx/backend/test/data/node/test_lstm_with_initial_bias/model.onnx
#	onnx/backend/test/data/node/test_lstm_with_peepholes/model.onnx
#	onnx/backend/test/data/node/test_simple_rnn_defaults/model.onnx
#	onnx/backend/test/data/node/test_simple_rnn_with_initial_bias/model.onnx
@AppVeyorBot
Copy link

Build onnx 0.3.3536 failed (commit ec730aaec7 by @fumihwh)

@AppVeyorBot
Copy link

Build onnx 0.3.3538 failed (commit 8953279c84 by @fumihwh)

Copy link
Contributor

@pk-g pk-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me in general.

@linkerzhang linkerzhang merged commit d2a46da into onnx:master May 24, 2018
onnxbot added a commit to onnx/onnx-coreml that referenced this pull request May 24, 2018
onnxbot added a commit to pytorch/pytorch that referenced this pull request May 24, 2018
@fumihwh fumihwh deleted the fix-lstm-test-cases branch May 24, 2018 07:21
weiyangfb pushed a commit to weiyangfb/pytorch that referenced this pull request Jun 11, 2018
Ac2zoom pushed a commit to Ac2zoom/onnx that referenced this pull request Jun 21, 2018
… cases (onnx#920)

* fix lstm test cases to match the specification and add precomputed case

*  add rnn and update test cases

* add and update gru test cases

* update doc

* remove lstm precomputed test case

* update test cases

* update doc and bug fix

* fix mypy
jcwchen pushed a commit to jcwchen/onnx that referenced this pull request Sep 23, 2020
… cases (onnx#920)

* fix lstm test cases to match the specification and add precomputed case

*  add rnn and update test cases

* add and update gru test cases

* update doc

* remove lstm precomputed test case

* update test cases

* update doc and bug fix

* fix mypy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants