RuntimeError: addmm(): argument 'mat1' (position 1) must be Variable, not torch.FloatTensor

I have the following model:

    model = torch.nn.Sequential(
        torch.nn.Linear(D_in, H),
        torch.nn.ReLU(),
        torch.nn.Linear(H, D_out),
    )

The inputs are sparse:

        ids_torch = torch.LongTensor([rows, cols])
        values_torch = torch.FloatTensor(vals)
        shape = [len(x_python), max_input_dim]
        x_tensor = torch.sparse.FloatTensor(ids_torch, values_torch, torch.Size(shape))

When the code gets to here:

print("x_batches[i].size(): ", x_batches[i].size())
print("y_batches[i].size(): ", y_batches[i].size())
y_pred = model(x_batches[i])

it gives the following error:

x_batches[i].size():  torch.Size([5, 4476850])
y_batches[i].size():  torch.Size([5, 1])
Traceback (most recent call last):
  File "mlp_classifier.py", line 186, in <module>
    experiment()
  File "mlp_classifier.py", line 183, in experiment
    train(x_batches, y_batches)
  File "mlp_classifier.py", line 101, in train
    y_pred = model(x_batches[i].to_dense())
  File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/container.py", line 67, in forward
    input = module(input)
  File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 325, in __call__
    result = self.forward(*input, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/torch/nn/modules/linear.py", line 55, in forward
    return F.linear(input, self.weight, self.bias)
  File "/usr/local/lib/python3.6/site-packages/torch/nn/functional.py", line 835, in linear
    return torch.addmm(bias, input, weight.t())
RuntimeError: addmm(): argument 'mat1' (position 1) must be Variable, not torch.FloatTensor

Any thoughts?

Which PyTorch version are you using? Variables are deprecated since version 0.4.0.
You can check your version using print(torch.__version__).
You can find the install instructions here.

I’m using the most recent version:

torch==0.4.1