mirror of
https://github.com/wassname/ray.git
synced 2026-10-30 13:40:26 +08:00
Torch sequence_mask now works for tensors on different devices (#7980)
This commit is contained in:
1 parent
c17404918c
commit
8e439688fc
1 file changed
+2
-2
@@ -51,8 +51,8 @@ def sequence_mask(lengths, maxlen, dtype=None):
|
||||
if maxlen is None:
|
||||
maxlen = lengths.max()
|
||||
|
||||
mask = ~(torch.ones((len(lengths), maxlen)).cumsum(dim=1).t() > lengths). \
|
||||
t()
|
||||
mask = ~(torch.ones((len(lengths), maxlen)).to(
|
||||
lengths.device).cumsum(dim=1).t() > lengths).t()
|
||||
mask.type(dtype or torch.bool)
|
||||
|
||||
return mask
|
||||
|
||||
Reference in new issue
Block a user