Skip to content

Rewrite scan-based GRU based on nn.GRU#8914

Merged
tengyifei merged 2 commits intopytorch:masterfrom
iwknow:gru
Apr 4, 2025
Merged

Rewrite scan-based GRU based on nn.GRU#8914
tengyifei merged 2 commits intopytorch:masterfrom
iwknow:gru

Conversation

@iwknow
Copy link
Copy Markdown
Collaborator

@iwknow iwknow commented Apr 1, 2025

This is a preparation step for #8860. specifically, this PR modified scan-based GRU implementation to derive from standard pytorch GRU implementation. It reuses all the components of the standard pytorch GRU implementation except the forward function. Reusing the standard GRU implementation makes the scan-based GRU weight key-compatible, enabling it to load checkpoints of the standard GRU.

The standard pytorch GRU implementation is similar to the scan-based GRU implementation except that it directly add parameters to module instead of using a ParameterList. It also uses the common performance optimization that concatenates the gate matrices into one matrix. For details on how it arranges and initialize the parameters, see: https://github.com/pytorch/pytorch/blob/340beb7f7cfe9c3c248819d2aae4170b8def3a8c/torch/nn/modules/rnn.py#L158-L201

Currently, setting batch_first, bidirectional, and proj_size are disabled. i will either make them work or allow them to fallback to the standard implementation in the following PRs.

@iwknow
Copy link
Copy Markdown
Collaborator Author

iwknow commented Apr 2, 2025

@tengyifei

@iwknow
Copy link
Copy Markdown
Collaborator Author

iwknow commented Apr 3, 2025

@tengyifei please run the test workflows and take a look. thanks!

@tengyifei
Copy link
Copy Markdown
Collaborator

Hi yes, just did. Thank you for the great work. I'll try to review it later today.

@iwknow
Copy link
Copy Markdown
Collaborator Author

iwknow commented Apr 4, 2025

it seems that the failed test is not related to this change. should i pull the latest commits and run the tests again?

@tengyifei tengyifei self-requested a review April 4, 2025 02:55
@tengyifei
Copy link
Copy Markdown
Collaborator

it seems that the failed test is not related to this change. should i pull the latest commits and run the tests again?

Sorry about that. Our GPU checks are just being turned back on and they have a lot of flakes. You may ignore unrelated errors.

@tengyifei tengyifei merged commit 145c33a into pytorch:master Apr 4, 2025
22 of 23 checks passed
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.

2 participants