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

Adds 'clip' alias for clamp #42770

Closed
wants to merge 5 commits into from
Closed

Adds 'clip' alias for clamp #42770

wants to merge 5 commits into from

Conversation

mruberry
Copy link
Collaborator

@mruberry mruberry commented Aug 8, 2020

Per title. Also updates our guidance for adding aliases to clarify interned_string and method_test requirements. The alias is tested by extending test_clamp to also test clip.

@mruberry mruberry requested a review from apaszke as a code owner August 8, 2020 01:21
@mruberry mruberry removed the request for review from apaszke August 8, 2020 01:21
@facebook-github-bot facebook-github-bot added the oncall: jit Add this issue/PR to JIT oncall triage queue label Aug 8, 2020
@dr-ci
Copy link

dr-ci bot commented Aug 8, 2020

💊 CI failures summary and remediations

As of commit 3747f18 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


1 failure confirmed as flaky and can be ignored:

  • pytorch_linux_xenial_cuda10_2_cudnn7_py3_gcc7_test

This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions on the GitHub issue tracker or post in the (internal) Dr. CI Users group.

See how this bot performed.

This comment has been revised 21 times.

min_val = -1
max_val = 1
m1[1] = min_val
m1[2] = max_val
Copy link
Collaborator

Choose a reason for hiding this comment

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

what are you trying to achieve here? Even if you are extremely lucky and your input tensor is bound by [min_val, max_val], these assignments are not going to change anything, and output will be equal to input.

res1 = m1.clone()
inplace_op(res1, min_val, max_val)
res2 = m1.clone()
for i in iter_indices(res2):
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe compare_with_numpy instead of this loop?

res1 = test_tens.clone()
inplace_op(res1, min_val, max_val)
res2 = test_tens.clone()
for i in iter_indices(res2):
Copy link
Collaborator

Choose a reason for hiding this comment

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

this loop not needed, just compare with expected [nan] here

res2[i] = max(min(res2[i], max_val), min_val)
self.assertEqual(torch.isnan(res1), torch.isnan(res2))

out = test_tens.clone()
Copy link
Collaborator

Choose a reason for hiding this comment

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

given that you expect out to be equal to test_tens, this is not the best way to initialize out


res1 = op(test_tens, min=min_val)
res2 = test_tens.clone()
for i in iter_indices(res2):
Copy link
Collaborator

Choose a reason for hiding this comment

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

loop is not needed


error_msg = 'At least one of \'min\' or \'max\' must not be None'
with self.assertRaisesRegex(RuntimeError, error_msg):
method_op(m1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see method_op tested anywhere other than here where it raises an error

with self.assertRaisesRegex(RuntimeError, error_msg):
method_op(m1)
with self.assertRaisesRegex(RuntimeError, error_msg):
inplace_op(m1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is nan propagation in clamp tested anywhere else? Vectorized and non-vectorized paths (could) propagate nan differently, so testing 1-element and 32-element tensors is needed to make sure that everything is ok.

@@ -1497,6 +1496,12 @@ def merge_dicts(*dicts):
tensor([ 0.5000, -0.4702, -0.4599, 0.5000])
""".format(**common_args))

add_docstr(torch.clip, r"""
clip(input, min, max, *, out=None) -> Tensor
Copy link
Collaborator

Choose a reason for hiding this comment

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

why is there "*" here but not in clamp declaration?

@@ -276,6 +276,8 @@ def method_tests():
('clamp', (), (None, 0.5), 'min_scalar', (True,)),
('clamp', (), (0.5, None), 'max_scalar', (True,)),
('clamp', (S, S), (), 'max_scalar_kwarg', (True,), (), (), ident, {'max': 1}),
('clip', (S, S, S), dont_convert((0, 1)), '', (False,)),
('clip_', (S, S, S), dont_convert((0, 1)), '', (False,)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

before your additions of absolute_ and clip_ looks like inplace versions weren't tested here, so maybe they shouldn't be?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The alias test requires an inplace entry.

@mruberry
Copy link
Collaborator Author

mruberry commented Aug 9, 2020

Note: per offline review, improvements to the existing clamp test will be separated and implemented when it's ported to the forthcoming test_unary_ufuncs.py.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@mruberry has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@mruberry merged this pull request in 87970b7.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Merged oncall: jit Add this issue/PR to JIT oncall triage queue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants