Thanks for your reply! In fact, I want to use a tensor with values in {0, 1}, which acts like being quantized to binary. For example:
device = 'cuda:0'
x = torch.as_tensor([0., 0., 1., 1.], device=device)
x.requires_grad_(True)
y = torch.as_tensor([0., 1., 0., 1.], device=device)
y.requires_grad_(True)
z = x * y  # z = x AND y
print(z)
z.sum().backward()
print(x.grad)
print(y.grad)

For the moment, I use float tensor to implement such a kind of tensor. But when values in tensors are binary, sotring them in float is not necessary. Sotring binary values in bool can reduce memory cost. So, I want to store values in bool, and store gradient in float.