This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
[v2.0] RNN: use rnn_params #20384
Merged
Merged
[v2.0] RNN: use rnn_params #20384
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
393a234
use rnn_params
barry-jin b8bff77
add split rnn parameter in gluon.utils
barry-jin 1512a6f
update
barry-jin 26fa633
update
barry-jin fef6380
use zero weight
barry-jin 1cd0ce0
add rnn fused parameter initializer
barry-jin 296628e
fix lint
barry-jin 3947da9
fix tests
barry-jin 68e18fa
update RNNFused initializer
barry-jin a770352
fix
barry-jin 481bd94
fix
barry-jin e7a959a
fix leak
barry-jin 5a49899
fix
barry-jin cc217ce
Merge remote-tracking branch 'upstream/master' into fix-rnn
barry-jin 9ce8ae1
fix
barry-jin fb7cc5d
fix
barry-jin 7eb3ef5
update
barry-jin 24527ca
update centos cu102 to use cudnn8
barry-jin 8e1d8e9
Merge remote-tracking branch 'upstream/master' into fix-rnn
barry-jin 476fe1e
fix
barry-jin b28bb7d
add docstring
barry-jin 340e774
fix conflict
barry-jin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -504,3 +504,54 @@ def _check_block_input_np_ndarrays(inputs): | |
for i in inputs: | ||
_check_block_input_np_ndarrays(i) | ||
# pylint: enable=no-else-raise | ||
|
||
|
||
# pylint: disable=too-many-nested-blocks | ||
def split_rnn_params(param, mode, num_layers, input_size, hidden_size, bidirectional, projection_size=None): | ||
"""Split rnn layer parameter into weight and bias in different layer.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add docstring |
||
gates = {'rnn_relu': 1, 'rnn_tanh': 1, 'lstm': 4, 'gru': 3}[mode] | ||
dir = 2 if bidirectional else 1 | ||
param_dict = {} | ||
begin = 0 | ||
if not projection_size: | ||
for p in ['weight', 'bias']: | ||
for l in range(num_layers): | ||
for d in ['l', 'r'][:dir]: | ||
for g in ['i2h', 'h2h']: | ||
ni = input_size | ||
if l != 0: | ||
ni = hidden_size * dir | ||
if g == 'h2h': | ||
ni = hidden_size | ||
shape0 = gates * hidden_size | ||
if p == 'weight': | ||
cur_len = shape0 * ni | ||
param_dict['{}{}_{}_{}'.format(d, l, g, p)] = \ | ||
param[begin:begin+cur_len].reshape(shape0, ni) | ||
else: | ||
cur_len = shape0 | ||
param_dict['{}{}_{}_{}'.format(d, l, g, p)] = \ | ||
param[begin:begin+cur_len].reshape(shape0,) | ||
begin += cur_len | ||
else: | ||
for p in ['weight', 'bias']: | ||
for l in range(num_layers): | ||
for d in ['l', 'r'][:dir]: | ||
for g in ['i2h', 'h2h', 'h2r']: | ||
if g != 'h2r' or p != 'bias': | ||
ni = input_size | ||
if l != 0: | ||
ni = projection_size * dir | ||
if g == 'h2h': | ||
ni = projection_size | ||
shape0 = gates * hidden_size | ||
if p == 'weight': | ||
cur_len = shape0 * ni | ||
param_dict['{}{}_{}_{}'.format(d, l, g, p)] = \ | ||
param[begin:begin+cur_len].reshape(shape0, ni) | ||
else: | ||
cur_len = shape0 | ||
param_dict['{}{}_{}_{}'.format(d, l, g, p)] = \ | ||
param[begin:begin+cur_len].reshape(shape0,) | ||
begin += cur_len | ||
return param_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will need an initializer for the fused parameter and use it as default. With this default initializer for RNN layers, the bias terms should be initialized as 0s.