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

Introduce reduce operator #326

Merged
merged 10 commits into from
Apr 26, 2022
Merged

Introduce reduce operator #326

merged 10 commits into from
Apr 26, 2022

Conversation

muellerzr
Copy link
Collaborator

@muellerzr muellerzr commented Apr 26, 2022

Introduce a reduce Op to Accelerator

What does this add?

This PR introduces a reduce operator, based on catalyst's implementation + some nuonces for TPU's.

Who is it for?

Users who want to have something akin to .reduce() for calculating their metrics

Why is it needed?

Was requested in #215

What parts of the API does this impact?

User-facing:

Introduces Accelerator.reduce

Internal structure:

Adds a reduce function in operations.py

Basic Usage Example(s):

accelerator = Accelerator()
loss = F.binary_cross_entropy(input, target, reduction="none")
loss = accelerator.reduce(loss, "sum")

@muellerzr muellerzr added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 26, 2022
@muellerzr muellerzr requested a review from sgugger April 26, 2022 17:16
@muellerzr muellerzr linked an issue Apr 26, 2022 that may be closed by this pull request
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Apr 26, 2022

The documentation is not available anymore as the PR was closed or merged.

@muellerzr muellerzr changed the title Introduce reduce operator, refactor utils Introduce reduce operator Apr 26, 2022
Copy link
Collaborator

@sgugger sgugger 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 adding this. Should we support nested structures of Tensors instead of just Tensors?

src/accelerate/utils.py Outdated Show resolved Hide resolved
src/accelerate/utils.py Outdated Show resolved Hide resolved
@muellerzr muellerzr requested a review from sgugger April 26, 2022 18:41
@muellerzr muellerzr merged commit 5f43367 into main Apr 26, 2022
@muellerzr muellerzr deleted the ops branch April 26, 2022 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: sum/mean reduce, sequential_ddp_run
3 participants