Skip to content

Use the fallback method for GRU and LSTM on ROCm if padded I/O is needed#17111

Merged
copybara-service[bot] merged 2 commits intokeras-team:masterfrom
ekuznetsov139:rocm_rnn_fallback
Oct 28, 2022
Merged

Use the fallback method for GRU and LSTM on ROCm if padded I/O is needed#17111
copybara-service[bot] merged 2 commits intokeras-team:masterfrom
ekuznetsov139:rocm_rnn_fallback

Conversation

@ekuznetsov139
Copy link
Copy Markdown
Contributor

On ROCm, the low-end library that implements RNNs (MIOpen) does not support inputs with variable sequence lengths. At present, an attempt to pass such inputs to a RNN results in an exception. Because of this limitation, several Keras unit tests are disabled for ROCm and several others currently fail.

This change correctly switches from GPU-optimized RNNs (CudnnRNNV3) to the fallback implementation as needed.

@ekuznetsov139 ekuznetsov139 marked this pull request as draft October 4, 2022 16:36
@ekuznetsov139 ekuznetsov139 marked this pull request as ready for review October 5, 2022 01:02
Copy link
Copy Markdown
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! It makes sense.

# Under eager context, check the device placement and prefer
# the GPU implementation when GPU is available.
if can_use_gpu:
print("Accepted GPU version: ", mask, row_lengths)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remove debug line

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oops.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please push your changes

@gbaned
Copy link
Copy Markdown
Collaborator

gbaned commented Oct 14, 2022

@ekuznetsov139 Can you please check @fchollet's comments and keep us posted ? Thank you!

# Under eager context, check the device placement and prefer
# the GPU implementation when GPU is available.
if can_use_gpu:
print("Accepted GPU version: ", mask, row_lengths)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please remove debug line

Reformatting
Disabling a test that fails on fallback path
Copy link
Copy Markdown
Collaborator

@fchollet fchollet left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM!

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Oct 26, 2022
@copybara-service copybara-service bot merged commit add6c1d into keras-team:master Oct 28, 2022
copybara-service bot pushed a commit that referenced this pull request Feb 23, 2023
Imported from GitHub PR #17587

A previous PR #17111 added some logic to use fallback implementations of GRU and LSTM on ROCm in situations where padded i/o is needed (since ROCm does not support padded i/o).

That logic turns out to be too restrictive - it chooses the fallback path in cases where it is not really needed, which may result in significant performance degradations.

This PR resolves the problem.

Copybara import of the project:

--
e78b4ab by Eugene Kuznetsov <eugene.kuznetsov@amd.com>:

Less restrictive fallback logic

Merging this change closes #17587

FUTURE_COPYBARA_INTEGRATE_REVIEW=#17587 from ekuznetsov139:rocm_rnn_fallback_v2 e78b4ab
PiperOrigin-RevId: 511817599
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to pull Ready to be merged into the codebase size:M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants