Adding xavier initiliazation in pytorch
I want to add Xavier initialization to the first layer of my Neural Network, but I am getting an error in this class:
class DemoNN(nn.Module):
    def __init__(self):
        super().__init__()
        torch.manual_seed(0)
        self.net = nn.Sequential(
            nn.Linear(2,2),
            torch.nn.init.xavier_uniform((nn.Linear(2,2)).weights),
            nn.Sigmoid(),

            nn.Linear(2,2),
            nn.Sigmoid(),

            nn.Linear(2,4),
            nn.Softmax()
            )
    
    def forward(self, X):
        self.net(X)


You seem to try and initialize the second linear layer within the constructor of an nn.Sequential object.
What you need to do is to first construct self.net and only then initialize the second linear layer as you wish.
Here is how you should do it:
import torch
import torch.nn as nn
class DemoNN(nn.Module):
    def __init__(self):
        super().__init__()
        torch.manual_seed(0)
        self.net = nn.Sequential(
            nn.Linear(2,2),
            nn.Linear(2,2),
            nn.Sigmoid(),

            nn.Linear(2,2),
            nn.Sigmoid(),

            nn.Linear(2,4),
            nn.Softmax()
        )
        torch.nn.init.xavier_uniform_(self.net[1].weight)
    
    def forward(self, X):
        self.net(X)

