dwg:

Is it the case that gradient using sparse matrix is in general not available on cuda?


No, that’s not the case.
As the warning explains, you are trying to access the .grad attribute of a non-leaf tensor, which won’t work.
The reason you are seeing this warning only when using the GPU is because the to(device='cpu') operation will be a no-op on the CPU and a valid operation on the GPU.
You can check it additionally via print(a.is_leaf) and print(b.is_leaf), which will show True on the CPU and False on the GPU.
This code snippet should work:
device='cuda'
# sparse
a = torch.randint(0, 2, size=(2, 3)).float().to_sparse().to(device).requires_grad_(True)
a
# dense
b = torch.randn(3, 2, device=device, requires_grad=True)
b
y = torch.sparse.mm(a, b)
y
y.sum().backward()
a.grad
b.grad