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

Fix accuracy issue for double alias #950

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ColinPeppler
Copy link
Contributor

Summary:

Problem

Here's an edge case for AIT. Suppose we have two outputs, and both are view on the same tensor. Atm, AIT will not provide accurate results for output0.

some-tensor  <--view-- output0
         ^------view-- ouptut1

// in SetUpInputOutput()
input_x = static_cast<decltype(input_x)>(params_[0].ptr);
elementwise_0_0 = static_cast<decltype(elementwise_0_0)>(params_[2].ptr);
output_0 = elementwise_0_0;
output_1 = elementwise_0_0;

Why doesn't AIT provide accurate results for output0? Because notice how params_[1] isn't assigned to anything.

Solution

Use a D2D copy to pass data from params_[2] to params_[1]. We do this by checking to see if the view is aliased by another output.

  • If yes, then run a D2D copy.
  • If no, don't worry about this output.

Refactor

We refactor _codegen_output_tensor by combining the external_tensor case with the is_view case.

Differential Revision: D50202241

@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 12, 2023
@facebook-github-bot
Copy link
Contributor

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

@facebook-github-bot
Copy link
Contributor

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

ColinPeppler added a commit to ColinPeppler/AITemplate that referenced this pull request Oct 12, 2023
Summary:
Pull Request resolved: facebookincubator#950

## Problem

Here's an edge case for AIT. Suppose we have two outputs, and both are view on the same tensor. Atm, AIT will not provide accurate results for output0.

```
some-tensor  <--view-- output0
         ^------view-- ouptut1

void SetUpInputOutput() {
  input_x = static_cast<decltype(input_x)>(params_[0].ptr);
  elementwise_0_0 = static_cast<decltype(elementwise_0_0)>(params_[2].ptr);
  output_0 = elementwise_0_0;
  output_1 = elementwise_0_0;
}

void DeviceToDeviceCopies(stream) {
  // empty
}
```

Why doesn't AIT provide accurate results for output0? Because notice how `params_[1]` isn't assigned to anything.

## Solution
Use a D2D copy to pass data from `params_[2]` to `params_[1]`. We do this by checking to see if the view is aliased by another output.
* If yes, then run a D2D copy.
* If no, don't worry about this output.

## Refactor
We refactor `_codegen_output_tensor` by combining the `external_tensor` case with the `is_view` case.

Differential Revision: D50202241

fbshipit-source-id: 13c1eb2d4171992f6a391672a6291a7485c8df2b
@facebook-github-bot
Copy link
Contributor

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

ColinPeppler added a commit to ColinPeppler/AITemplate that referenced this pull request Oct 12, 2023
Summary:
Pull Request resolved: facebookincubator#950

## Problem

Here's an edge case for AIT. Suppose we have two outputs, and both are view on the same tensor. Atm, AIT will not provide accurate results for output0.

```
some-tensor  <--view-- output0
         ^------view-- ouptut1

void SetUpInputOutput() {
  input_x = static_cast<decltype(input_x)>(params_[0].ptr);
  elementwise_0_0 = static_cast<decltype(elementwise_0_0)>(params_[2].ptr);
  output_0 = elementwise_0_0;
  output_1 = elementwise_0_0;
}

void DeviceToDeviceCopies(stream) {
  // empty
}
```

Why doesn't AIT provide accurate results for output0? Because notice how `params_[1]` isn't assigned to anything.

## Solution
Use a D2D copy to pass data from `params_[2]` to `params_[1]`. We do this by checking to see if the view is aliased by another output.
* If yes, then run a D2D copy.
* If no, don't worry about this output.

## Refactor
We refactor `_codegen_output_tensor` by combining the `external_tensor` case with the `is_view` case.

Differential Revision: D50202241

fbshipit-source-id: 8d61bac9ed2be0b3ba8f9e017b1373e4b0473d34
ColinPeppler and others added 2 commits October 12, 2023 10:54
Differential Revision:
D49759512

test_codegen

fbshipit-source-id: c2d9f9ee4aeda516e56229b5369bf46cc313e256
Summary:
Pull Request resolved: facebookincubator#950

## Problem

Here's an edge case for AIT. Suppose we have two outputs, and both are view on the same tensor. Atm, AIT will not provide accurate results for output0.

```
some-tensor  <--view-- output0
         ^------view-- ouptut1

void SetUpInputOutput() {
  input_x = static_cast<decltype(input_x)>(params_[0].ptr);
  elementwise_0_0 = static_cast<decltype(elementwise_0_0)>(params_[2].ptr);
  output_0 = elementwise_0_0;
  output_1 = elementwise_0_0;
}

void DeviceToDeviceCopies(stream) {
  // empty
}
```

Why doesn't AIT provide accurate results for output0? Because notice how `params_[1]` isn't assigned to anything.

## Solution
Use a D2D copy to pass data from `params_[2]` to `params_[1]`. We do this by checking to see if the view is aliased by another output.
* If yes, then run a D2D copy.
* If no, don't worry about this output.

## Refactor
We refactor `_codegen_output_tensor` by combining the `external_tensor` case with the `is_view` case.

Differential Revision: D50202241

fbshipit-source-id: 599cc609dcb11f92e432479f2f3214236f6d68c5
@facebook-github-bot
Copy link
Contributor

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

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants