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

Add reduce_min and reduce_max #942

Closed
wants to merge 1 commit into from

Conversation

aakhundov
Copy link
Contributor

@aakhundov aakhundov commented Oct 5, 2023

My understanding is that the max / min reduction are usually not used in the trained PT models due to their non-differentiability. Probably, that's the reason why we don't have them reflected as AIT ops. However, they may be useful in inference for a manually composed AIT model (or PT model translated by fx2ait) which was solicited in #941.

In this diff, we're adding the new reduce_max and reduce_min ops to AIT. The new ops are using the existing common back-end implementation used by reduce_sum with a small extension: the default (initial) accumulator value of 0 is not suitable for the min / max reductions, it is now made configurable in the codegen; lowest() and max() numeric limits for the ElementCompute are set by the reduce_max / reduce_min ops' codegen, respectively.

fx2ait wiring of the new ops to the torch.amax and torch.amin has also been added.

Differential Revision: D49978036

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 5, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49978036

aakhundov added a commit to aakhundov/AITemplate-1 that referenced this pull request Oct 5, 2023
Summary:

TBA

Differential Revision: D49978036
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49978036

aakhundov added a commit to aakhundov/AITemplate-1 that referenced this pull request Oct 6, 2023
Summary:

TBA

Differential Revision: D49978036
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49978036

aakhundov added a commit to aakhundov/AITemplate-1 that referenced this pull request Oct 6, 2023
Summary:

My understanding is that the max / min reduction are usually not used in the trained PT models due to their non-differentiability. Probably, that's the reason why we don't have them reflected as AIT ops. However, they may be useful in inference for a manually composed AIT model (or PT model translated by fx2ait) which was solicited in the issue [facebookincubator#941](facebookincubator#941).

In this diff, we're adding the new `reduce_max` and `reduce_min` ops to AIT. The new ops are using the existing common back-end implementation used by `reduce_sum` with a small extension: the default (initial) accumulator value of 0 is not suitable for the min / max reductions, it is now made configurable in the codegen; `lowest()` and `max()` numeric limits for the ElementCompute are set by the `reduce_max` / `reduce_min` ops' codegen, respectively.

fx2ait wiring of the new ops to the `torch.amax` and `torch.amin` has also been added.

Differential Revision: D49978036
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49978036

Summary:

My understanding is that the max / min reduction are usually not used in the trained PT models due to their non-differentiability. Probably, that's the reason why we don't have them reflected as AIT ops. However, they may be useful in inference for a manually composed AIT model (or PT model translated by fx2ait) which was solicited in the issue [facebookincubator#941](facebookincubator#941).

In this diff, we're adding the new `reduce_max` and `reduce_min` ops to AIT. The new ops are using the existing common back-end implementation used by `reduce_sum` with a small extension: the default (initial) accumulator value of 0 is not suitable for the min / max reductions, it is now made configurable in the codegen; `lowest()` and `max()` numeric limits for the ElementCompute are set by the `reduce_max` / `reduce_min` ops' codegen, respectively.

fx2ait wiring of the new ops to the `torch.amax` and `torch.amin` has also been added.

Differential Revision: D49978036
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D49978036

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 0a67de1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants