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

[Torch] : Implement lowering of torch.frac op #3847

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

milinkovicandrea
Copy link

@milinkovicandrea milinkovicandrea commented Nov 1, 2024

Implement lowering of torch.frac op.
Decompose op inside DecomposeComplexOps.cpp.
Add tests into elementwise.py.

@milinkovicandrea milinkovicandrea marked this pull request as draft November 1, 2024 10:50
@milinkovicandrea milinkovicandrea marked this pull request as ready for review November 1, 2024 10:51
@milinkovicandrea
Copy link
Author

milinkovicandrea commented Nov 1, 2024

Could you please review this pull request? @vivekkhandelwal1

Copy link
Collaborator

@vivekkhandelwal1 vivekkhandelwal1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@milinkovicandrea Please rebase your PR.

Comment on lines +2842 to +2860
class ElementwiseFracModule(torch.nn.Module):
def __init__(self):
super().__init__()

@export
@annotate_args(
[
None,
([1, 6], torch.float32, True),
]
)
def forward(self, a):
return torch.frac(a)


@register_test_case(module_factory=lambda: ElementwiseFracModule())
def ElementwiseFracModule_basic(module, tu: TestUtils):
module.forward(torch.tensor([[-torch.inf, torch.inf, torch.nan, -2.3, 0.0, 1.5]]))

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it take f64 input? If yes, can you please add a test for the same?

@@ -8012,6 +8012,34 @@ class DecomposeAtenTruncOp : public OpRewritePattern<AtenTruncOp> {
};
} // namespace

namespace {
// decompose `frac(x)` to `x - sign(x) * floor(abs(x))`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decomposition written below follows a different implementation. Better to either remove this comment or change it as per the decomposition.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants