Hi everyone,
Basically, I have a matrix computed from another program that I would like to use in my network, and update these weights.
In [1]: import torch
In [2]: import torch.nn as nn
In [4]: linear_trans = nn.Linear(3,2)
In [5]: my_weights = torch.tensor([[1,2],[3,4],[5,6]])
In [6]: linear_trans.weight
Out[6]: 
Parameter containing:
tensor([[ 0.4409, -0.2647,  0.3328],
        [ 0.1049, -0.1887, -0.2617]], requires_grad=True)

In [7]: linear_trans.weight.data = my_weights
In [8]: linear_trans.weight
Out[8]: 
Parameter containing:
tensor([[1, 2],
        [3, 4],
        [5, 6]], requires_grad=True)

Is this enough for :

Use these weights as parameters for nn.Linear (without changing the values of the bias vector)
Update these with .backwards automatically

In addition:


if I would like to move them to GPU, is it enough to do model.to(device) ? (if my model uses the nn.Linear with the weights loaded)


If I want to freeze the weights, is using linear_trans.weight.data.requires_grad = False enough ?


Thank you very much for your help, I just want to be sure as I’ve never done this kind of weight initialization