RuntimeError: Could not run 'aten::gt.Scalar' with arguments from the 'SparseCPUTensorId' backend. 'aten::gt.Scalar' is only available for these backends: [CPUTensorId, QuantizedCPUTensorId, VariableTensorId]

qiuli380: <p>I have the following problems when using the Graph attention Networks(GAT) framework.<br>
RuntimeError: Could not run ‘aten::gt.Scalar’ with arguments from the ‘SparseCPUTensorId’ backend. ‘aten::gt.Scalar’ is only available for these backends: [CPUTensorId, QuantizedCPUTensorId, VariableTensorId].</p>
<p>This is the code.<br>
def forward(self, input, adj):<br>
h = torch.mm(input, self.W)<br>
N = h.size()[0]<br>
a_input = torch.cat([h.repeat(1, N).view(N * N, -1), h.repeat(N, 1)], dim=1).view(N, -1, 2 * self.out_features)<br>
e = self.leakyrelu(torch.matmul(a_input, self.a).squeeze(2)<br>
zero_vec = -9e15*torch.ones_like(e)<br>
attention = torch.where(adj &gt; 0, e, zero_vec)</p>
<p>This is a pychar error   :<br>
attention = torch.where(adj &gt; 0, e, zero_vec)<br>
File “/home/Scse09064/anaconda3/envs/pytorch/lib/python3.6/site-packages/torch/tensor.py”, line 28, in wrapped<br>
return f(*args, **kwargs)<br>
RuntimeError: Could not run ‘aten::gt.Scalar’ with arguments from the ‘SparseCPUTensorId’ backend. ‘aten::gt.Scalar’ is only available for these backends: [CPUTensorId, QuantizedCPUTensorId, VariableTensorId].</p>
<p>Hope to have a friend to help me solve this problem, I will be very grateful!</p>

albanD: <p>Hi,</p>
<p>As mentioned in your other post, you cannot do <code>adj &gt; 0</code> as this is not implemented I’m afraid <img src="https://discuss.pytorch.org/images/emoji/apple/confused.png?v=9" title=":confused:" class="emoji" alt=":confused:"></p>

qiuli380: <p>Hi，thank you. It’s really about adj。<br>
There are what i need：<br>
adj=tensor([[0.1667, 0.0000, 0.0000,  …, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.5000, 0.0000,  …, 0.0000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.2000,  …, 0.0000, 0.0000, 0.0000],<br>
…,<br>
[0.0000, 0.0000, 0.0000,  …, 0.2000, 0.0000, 0.0000],<br>
[0.0000, 0.0000, 0.0000,  …, 0.0000, 0.2000, 0.0000],<br>
[0.0000, 0.0000, 0.0000,  …, 0.0000, 0.0000, 0.2500]])</p>
<p>There are at present：<br>
adj=tensor(indices=tensor([[   0,    8,   20,  …, 2983, 2991, 3024],<br>
[   0,    0,    0,  …, 3024, 3024, 3024]]),<br>
values=tensor([0.0556, 0.0500, 0.0556,  …, 0.0588, 0.1250, 0.1111]),<br>
size=(3025, 3025), nnz=29281, layout=torch.sparse_coo)</p>
<p>Now I’m trying to figure out how to convert these</p>

albanD: <p>You can call <code>.to_dense()</code> on the sparse Tensor to convert it into a full dense Tensor.</p>

qiuli380: <p>it’s the  problem  with   sparse  tensor，and  after  i  use  .to_dense(),the problem  is  solved，thank  you  very  much！ <img src="https://discuss.pytorch.org/images/emoji/apple/stuck_out_tongue.png?v=9" title=":stuck_out_tongue:" class="emoji" alt=":stuck_out_tongue:"></p>

max2: <p>Where is .to_dense() added? I have the same problem as you <img src="https://discuss.pytorch.org/images/emoji/apple/sob.png?v=9" title=":sob:" class="emoji" alt=":sob:"></p>

ptrblck: <p>PyTorch <code>1.0.0</code> seems to have already supported the <code>to_dense</code> operation as seen in the <a href="https://pytorch.org/docs/1.0.0/sparse.html">docs</a>.</p>

sad_robot: <p>What if you need the sparse tensor for memory constraints? Isn’t that the whole point in sparse Tensors?</p>

Sahar_Shayegan: <p>I got the same problem. Facing a memory constraint when using dense.</p>