-
-
Notifications
You must be signed in to change notification settings - Fork 983
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
Avoid using legacy constructors Tensor.new_*() #1842
Conversation
@@ -34,7 +34,7 @@ def __init__(self, v, log_density=0.0, event_dim=0, validate_args=None): | |||
batch_shape = v.shape[:batch_dim] | |||
event_shape = v.shape[batch_dim:] | |||
if isinstance(log_density, numbers.Number): | |||
log_density = v.new_empty(batch_shape).fill_(log_density) | |||
log_density = torch.full(batch_shape, log_density, dtype=v.dtype, device=v.device) |
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.
Not relevant to the cases that I see here, but I just discovered that torch.full
doesn't generalize well in JIT when the fill value is scalar. Using empty_like
with fill_
seems to work fine in those cases.
e.g.
>>> a = torch.tensor([0, 0])
>>> def fn1(x):
return torch.full(a.size(), x, dtype=a.dtype, device=a.device)
>>> torch.jit.trace(fn1, torch.tensor(1.))(torch.tensor(2.))
tensor([1, 1])
>>> def fn2(x):
return torch.empty_like(a).fill_(x)
>>> torch.jit.trace(fn1, torch.tensor(1.))(torch.tensor(2.))
tensor([2, 2])
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.
Interesting, it would be good to have this example in tests/infer/test_jit.py
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.
Many thanks for updating the codebase! Looks great.
Will merge when tests pass. |
Yes yes, I'll do it. :D |
The following constructors are deprecated and are unsupported by the jit:
Tensor.new_tensor()
Tensor.new_empty()
Tensor.new_zeros()
Tensor.new_ones()
Tensor.new_full()
Updated
Triaged (not updated)
Tested
CUDA_TEST=1 pytest -vx tests/test_examples.py::test_cuda
against torch==1.0.1