pytorch difference in 1.1.0 and 1.3.0 in Parameter
I am trying to learn PyTorch and have tried running some code that I got from the Kaggle website.

# Get all hidden layers' weights
for i in range(len(hidden_units)):
  fc_layers.extend([
    TrainNet.model.hidden_layers[i].weight.T.tolist(), # weights
    TrainNet.model.hidden_layers[i].bias.tolist() # bias
  ])


This gives the following error:



AttributeError                            Traceback (most recent call last)
&lt;ipython-input-12-65f871b6f0b7&gt; in &lt;module&gt;
  4 for i in range(len(hidden_units)):
  5     fc_layers.extend([
----&gt; 6         TrainNet.model.hidden_layers[i].weight.T.tolist(), # weights
  7         TrainNet.model.hidden_layers[i].bias.tolist() # bias
  8     ])

AttributeError: 'Parameter' object has no attribute 'T'


If I print out the type of 'TrainNet.model.hidden_layers[i].weight' it is indeed type Parameter.
This block of code works without error on the Kaggle website run in there notebook (Google colab I believe) where the version of Torch is 1.3.0.

On my home machine where the error occurs my Anaconda distribution which I have just updated is running Torch 1.1.0.

Is this the source of the error and how do I sort it?

Thanks

class Parameter is a subclass of Tensor hence has all the attributes of a torch.Tensor class  

Tensor.T was introduced in 1.2.0 and hence is not available in your 1.1.0

You can either update the pytorch version or use the permute method in it's place as below example

&gt;&gt;&gt; t = torch.Tensor(np.random.randint(0,100,size=(2,3,4))) # -&gt; random Tensor with t.shape = (2,3,4)
&gt;&gt;&gt; t.shape
torch.Size([2, 3, 4])
&gt;&gt;&gt; list(range(len(t.shape)))[::-1]
[2,1,0] # This is the sequence of dimensions t.T will return in 1.2.0 onwards
&gt;&gt;&gt; t = t.permute(list(range(len(t.shape)))[::-1])
&gt;&gt;&gt; t.shape
torch.Size([4, 3, 2])


It is equivalent to doing transpose of a matrix, i.e., reversing the sequence of dimensions but in N dimensional tensors
