-
Notifications
You must be signed in to change notification settings - Fork 145
acosh process #942
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
Open
hucheng-star
wants to merge
2
commits into
FlagOpen:master
Choose a base branch
from
hucheng-star:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
acosh process #942
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import logging | ||
import triton | ||
import triton.language as tl | ||
import torch | ||
|
||
from flag_gems.utils import pointwise_dynamic | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
@pointwise_dynamic( | ||
promotion_method=[(0, "DEFAULT")], | ||
) | ||
@triton.jit | ||
def acosh_forward_kernel(x) | ||
return tl.log(x + tl.sqrt(x * x - 1.0)) | ||
|
||
def acosh(input: torch.Tensor, *, out: torch.Tensor = None): | ||
""" | ||
Returns a new tensor with the inverse hyperbolic cosine of the elements of input. | ||
Args: | ||
input (Tensor): the input tensor | ||
out (Tensor, optional): the output tensor | ||
Returns: | ||
Tensor: the output tensor with the inverse hyperbolic cosine values | ||
""" | ||
result = acosh_forward_kernel(input) | ||
|
||
if out is not None: | ||
out.copy_(result) | ||
return out | ||
|
||
return output |
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 |
---|---|---|
|
@@ -33,6 +33,20 @@ def test_accuracy_abs(shape, dtype): | |
gems_assert_equal(res_out, ref_out) | ||
|
||
|
||
@pytest.mark.acosh | ||
@pytest.mark.parametrize("shape", POINTWISE_SHAPES) | ||
@pytest.mark.parametrize("dtype", FLOAT_DTYPES) | ||
def test_accuracy_acosh(shape, dtype): | ||
inp = torch.randn(shape, dtype=dtype, device=flag_gems.device).exp() + 0.5 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if the value of inp tensor is invalid? will torch check it? |
||
|
||
ref_inp = to_reference(inp, True) | ||
ref_out = torch.acosh(ref_inp) | ||
with flag_gems.use_gems(): | ||
res_out = torch.acosh(inp) | ||
|
||
gems_assert_close(res_out, ref_out, dtype, equal_nan=True) | ||
|
||
|
||
@pytest.mark.inplace | ||
@pytest.mark.abs_ | ||
@pytest.mark.parametrize("shape", POINTWISE_SHAPES) | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest referring the implementation in https://github.com/FlagOpen/FlagGems/blob/master/src/flag_gems/ops/add.py#L48.
copy_
calls another kernel.