We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
当maximum其中一个参数是标量的时候会有assert错误,用例如下: attn_weights = torch.max(attn_weights, torch.tensor(torch.finfo(attn_weights.dtype).min))
attn_weights = torch.max(attn_weights, torch.tensor(torch.finfo(attn_weights.dtype).min))
The text was updated successfully, but these errors were encountered:
了解了。我们分析一下原因。因为 native_functions.yaml 中 maximum 和 minimum 没有 tensor-scalar, scalar-tensor 的 overload, 所以此前没有实现这样的版本。
Sorry, something went wrong.
确实如此,但 torch 的 maximum 和 minimum 本就不支持 self 或 other 是标量。用如下的例子可以测试
import torch x = torch.randn(10, device="cuda") y = torch.maximum(0.0, x) print(y) # TypeError: maximum(): argument 'input' (position 1) must be Tensor, not float
import torch x = torch.randn(10, device="cuda") y = torch.maximum(x, 0.0) print(y) # TypeError: maximum(): argument 'other' (position 2) must be Tensor, not float
不过在测试的时候我也发现了我们的实现还没有处理好一点。当输入是在 cpu 上的 0d tensor 的时候,torch 是允许不同设备上的 tensor 的。比如
import torch x = torch.tensor([0.1], device="cuda") y = torch.tensor(0.2, device="cpu") out = torch.maximum(x, y) print(y)
这不会报错,而
import torch x = torch.tensor(0.1, device="cuda") y = torch.tensor([0.2], device="cpu") out = torch.maximum(x, y) print(y)
会报错,但是我们目前的实现还没有准确实现这样的行为。 正在修复。可能和 #311 相似。
iclementine
No branches or pull requests
Describe the bug
当maximum其中一个参数是标量的时候会有assert错误,用例如下:
attn_weights = torch.max(attn_weights, torch.tensor(torch.finfo(attn_weights.dtype).min))
The text was updated successfully, but these errors were encountered: