Files
pytorch/test/custom_operator/my_custom_ops.py
Xuehai Pan 26f4f10ac8 [5/N][Easy] fix typo for usort config in pyproject.toml (kown -> known): sort torch (#127126)
The `usort` config in `pyproject.toml` has no effect due to a typo. Fixing the typo make `usort` do more and generate the changes in the PR. Except `pyproject.toml`, all changes are generated by `lintrunner -a --take UFMT --all-files`.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/127126
Approved by: https://github.com/kit1980
2024-05-27 14:49:57 +00:00

15 lines
346 B
Python

from model import get_custom_op_library_path
import torch
torch.ops.load_library(get_custom_op_library_path())
@torch.library.impl_abstract("custom::nonzero")
def nonzero_abstract(x):
n = x.dim()
ctx = torch.library.get_ctx()
nnz = ctx.create_unbacked_symint()
shape = [nnz, n]
return x.new_empty(shape, dtype=torch.long)