-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #232 from balanprasanth:automation
PiperOrigin-RevId: 698536260
- Loading branch information
Showing
11 changed files
with
271 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: auto-assignment | ||
on: | ||
issues: | ||
types: | ||
- opened | ||
|
||
permissions: | ||
contents: read | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
welcome: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const script = require('./\.github/workflows/scripts/auto-assignment.js') | ||
script({github, context}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
Automatically assign issues and PRs to users in the `assigneesList` | ||
* on a rotating basis. | ||
@param {!object} | ||
GitHub objects can call GitHub APIs using their built-in library functions. | ||
The context object contains issue and PR details. | ||
*/ | ||
|
||
module.exports = async ({github, context}) => { | ||
let issueNumber; | ||
let assigneesList; | ||
// Is this an issue? If so, assign the issue number. Otherwise, assign the PR | ||
// number. | ||
if (context.payload.issue) { | ||
assigneesList = ['pkgoogle', 'gaikwadrahul8']; // for issues | ||
issueNumber = context.payload.issue.number; | ||
} else { | ||
assigneesList = []; // for PRs | ||
issueNumber = context.payload.number; | ||
} | ||
console.log('assignee list', assigneesList); | ||
console.log('entered auto assignment for this issue: ', issueNumber); | ||
if (!assigneesList.length) { | ||
console.log('No assignees found for this repo.'); | ||
return; | ||
} | ||
let noOfAssignees = assigneesList.length; | ||
let selection = issueNumber % noOfAssignees; | ||
let assigneeForIssue = assigneesList[selection]; | ||
|
||
console.log( | ||
'issue Number = ', issueNumber + ' , assigning to: ', assigneeForIssue); | ||
return github.rest.issues.addAssignees({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
assignees: [assigneeForIssue], | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
# Copyright 2024 The AI Edge Torch Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
|
||
"""A suite of tests to validate the Dynamic Update Slice Custom Op.""" | ||
|
||
from ai_edge_torch.generative.layers import kv_cache as kv_utils | ||
import ai_edge_torch.generative.layers.model_config as cfg | ||
import torch | ||
from torch import nn | ||
|
||
from absl.testing import absltest as googletest, parameterized | ||
|
||
|
||
def updated_slice_matches(buffer, update, index): | ||
indexer = [slice(i, i + d) for i, d in zip(index, update.shape)] | ||
buf = buffer[indexer] | ||
return torch.allclose(buf, update) | ||
|
||
|
||
def intT(x): | ||
return torch.tensor(x).int() | ||
|
||
|
||
class DUSMod(nn.Module): | ||
|
||
def forward(self, buffer, update, index): | ||
out = dynamic_update_slice(buffer, update, index) | ||
out = out * 2 | ||
return out | ||
|
||
|
||
@googletest.skip('Enable this when odml_torch is default b/373387583') | ||
class TestCustomDUS(parameterized.TestCase): | ||
|
||
@parameterized.named_parameters( | ||
( | ||
'DUS_whole_buffer', | ||
torch.randn(1, 1280, 4, 64), | ||
torch.randn([1, 1024, 4, 64]), | ||
[intT(0), intT(0), intT(0), intT(0)], | ||
), | ||
( | ||
'DUS_kv_example', | ||
torch.randn(2, 1280, 4, 64), | ||
torch.randn([2, 1024, 4, 64]), | ||
[intT(0), intT(0), intT(0), intT(0)], | ||
), | ||
( | ||
'DUS_3d', | ||
torch.randn(2, 256, 4, 64), | ||
torch.randn([2, 256, 2, 64]), | ||
[intT(0), intT(0), intT(2), intT(0)], | ||
), | ||
( | ||
'DUS_3d_v2', | ||
torch.randn(2, 256, 4, 64), | ||
torch.randn([2, 256, 3, 64]), | ||
[intT(0), intT(0), intT(1), intT(0)], | ||
), | ||
( | ||
'DUS_3d_v3', | ||
torch.randn(6, 8, 32), | ||
torch.randn([6, 3, 32]), | ||
[intT(0), intT(5), intT(0)], | ||
), | ||
( | ||
'DUS_2d', | ||
torch.randn(8, 32), | ||
torch.randn([8, 12]), | ||
[intT(0), intT(20)], | ||
), | ||
) | ||
def test_opcheck_dynamic_update_slice(self, buffer, update, indices): | ||
torch.library.opcheck(dynamic_update_slice, (buffer, update, indices)) | ||
out = dynamic_update_slice(buffer, update, indices) | ||
self.assertTrue(updated_slice_matches(out, update, indices)) | ||
|
||
def test_exported_program(self): | ||
buffer = torch.randn(1, 1280, 4, 64) | ||
update = torch.randn([1, 1024, 4, 64]) | ||
index = [intT(0), intT(0), intT(0), intT(0)] | ||
dm = DUSMod() | ||
ep = torch.export.export(dm, (buffer, update, index)) | ||
dus_in_exported_program = False | ||
for node in ep.graph.nodes: | ||
if node.op == 'call_function': | ||
if node.target.__name__.startswith('dynamic_update_slice'): | ||
dus_in_exported_program = True | ||
break | ||
|
||
self.assertTrue(dus_in_exported_program) | ||
|
||
|
||
if __name__ == '__main__': | ||
googletest.main() |
56 changes: 56 additions & 0 deletions
56
ai_edge_torch/generative/utilities/dynamic_update_slice.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Copyright 2024 The AI Edge Torch Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ============================================================================== | ||
# Common utility functions for data loading etc. | ||
from dataclasses import dataclass | ||
import glob | ||
import os | ||
from typing import Sequence | ||
from ai_edge_torch.odml_torch import lowerings | ||
from jax._src.lib.mlir import ir | ||
from jax._src.lib.mlir.dialects import hlo as stablehlo | ||
import torch | ||
|
||
|
||
# Use torch.library.custom_op to define a new custom operator. | ||
# TODO: Update impl for multiple non-trivial start_indices | ||
@torch.library.custom_op("ai_edge_torch::dynamic_update_slice", mutates_args=()) | ||
def dynamic_update_slice( | ||
in_tensor: torch.Tensor, | ||
update: torch.Tensor, | ||
start_indices: Sequence[torch.Tensor], | ||
) -> torch.Tensor: | ||
compare_size = torch.tensor(in_tensor.size()) == torch.tensor(update.size()) | ||
mismatch = torch.nonzero(~compare_size, as_tuple=False) | ||
dim = mismatch[0].item() if len(mismatch) > 0 else 0 | ||
start = start_indices[dim].item() | ||
end = start + update.shape[dim] | ||
indices = torch.arange(start, end).to(torch.long) | ||
return in_tensor.index_copy(dim, indices, update) | ||
|
||
|
||
# Use register_fake to add a ``FakeTensor`` kernel for the operator | ||
@dynamic_update_slice.register_fake | ||
def _(in_tensor, update, start_indices): | ||
return in_tensor.clone().detach() | ||
|
||
|
||
@lowerings.lower(torch.ops.ai_edge_torch.dynamic_update_slice) | ||
def _dynamic_update_slice_lower( | ||
lctx, | ||
in_tensor: ir.Value, | ||
update: ir.Value, | ||
start_indices: Sequence[ir.Value], | ||
): | ||
return stablehlo.dynamic_update_slice(in_tensor, update, start_indices) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters