-
Notifications
You must be signed in to change notification settings - Fork 493
【KernelGen】Add index_copy_ operator #1743
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
Merged
tengqm
merged 22 commits into
flagos-ai:master
from
Schopenhauer-loves-Hegel:auto-gen/index_copy_
May 19, 2026
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
af10c71
feat: add index_copy_ operator with tests and benchmark
factnn 604aaa2
chore: add index_copy and index_copy_ to operators.yaml
factnn 5f63ca2
fix: address review comments - early return, try/except, remove unuse…
factnn 1036096
Merge branch 'master' into auto-gen/index_copy_
factnn e43da15
Merge branch 'master' into auto-gen/index_copy_
factnn cf0e82a
Merge branch 'master' into auto-gen/index_copy_
factnn a2f9a0a
ci: trigger CI rerun
factnn 57ad597
Merge branch 'master' into auto-gen/index_copy_
factnn a302ec8
Merge branch 'master' into auto-gen/index_copy_
factnn 6cdb75d
Merge branch 'master' into auto-gen/index_copy_
factnn cb449e7
fix: use IndexCopyBenchmark class consistently in benchmark
factnn 4949861
fix: use explicit shapes in IndexCopyBenchmark instead of REDUCTION_S…
factnn fb3397d
fix: use explicit INDEX_COPY_SHAPES instead of REDUCTION_SHAPES in tests
factnn 55ff81a
Merge branch 'master' into auto-gen/index_copy_
factnn 91dc702
Merge branch 'master' into auto-gen/index_copy_
factnn e363fbb
Merge branch 'master' into auto-gen/index_copy_
factnn 4146e9b
Merge branch 'master' into auto-gen/index_copy_
factnn dbe5926
Merge branch 'master' into auto-gen/index_copy_
factnn 1d1b874
Merge branch 'master' into auto-gen/index_copy_
factnn bfec166
Merge branch 'master' into auto-gen/index_copy_
factnn b8af1c7
Merge branch 'master' into auto-gen/index_copy_
factnn c627a80
Merge branch 'master' into auto-gen/index_copy_
factnn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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,50 @@ | ||
| import pytest | ||
| import torch | ||
|
|
||
| from . import base, consts, utils | ||
|
|
||
|
|
||
| class IndexCopyBenchmark(base.GenericBenchmark): | ||
| def set_more_shapes(self): | ||
| return [(1, 2), (4096, 256), (200, 40999, 3)] | ||
|
|
||
| def get_gbps(self, bench_fn_args, latency): | ||
| index = bench_fn_args[2] | ||
| src = bench_fn_args[3] | ||
| io_amount = sum([utils.size_in_bytes(item) for item in [index, src, src]]) | ||
| return io_amount * 1e-9 / (latency * 1e-3) | ||
|
|
||
|
|
||
| def _tensor_input_fn(shape, dtype, device): | ||
| inp = torch.randn(shape, dtype=dtype, device=device) | ||
| dim = 0 if len(shape) == 1 else 1 | ||
| src_shape = list(inp.shape) | ||
| index_max = src_shape[dim] | ||
| index_len = index_max // 2 if index_max >= 2 else 1 | ||
| index = torch.randperm(index_len, device=device) | ||
| src_shape[dim] = index_len | ||
| src = torch.randn(src_shape, dtype=dtype, device=device) | ||
| yield inp, dim, index, src | ||
|
|
||
|
|
||
| @pytest.mark.index_copy | ||
| def test_index_copy(): | ||
| bench = IndexCopyBenchmark( | ||
| input_fn=_tensor_input_fn, | ||
| op_name="index_copy", | ||
| torch_op=torch.index_copy, | ||
| dtypes=consts.FLOAT_DTYPES, | ||
| ) | ||
| bench.run() | ||
|
|
||
|
|
||
| @pytest.mark.index_copy_ | ||
| def test_index_copy_(): | ||
| bench = IndexCopyBenchmark( | ||
| input_fn=_tensor_input_fn, | ||
| op_name="index_copy_", | ||
| torch_op=torch.Tensor.index_copy_, | ||
| dtypes=consts.FLOAT_DTYPES, | ||
| inplace=True, | ||
| ) | ||
| bench.run() | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.