I’m trying to find a way to change the nn.Linear size dynamically.  For example lets say I have the following layers:
self.fc1 = nn.Linear(z_dim, h_dim)
self.fcmean = nn.Linear(h_dim, z_dim)


Now lets say for simplicity I want to change z_dim dynamically by increasing it’s size based on a coin flip.  In every epoch z_dim will increase in size by 1 or remain the same with probability .5.
I found this example:

  
    
    
    How can I implement a dynamic parameter in Linear Layer by using pytorch? 
  
  
    class LinearText(nn.Module): 
    def __init__(self):
        super(CNNText, self).__init__()
        self.encoder_tit = nn.Embedding(3281, 64)
        self.encoder_con = nn.Embedding(496037, 512)
        
        self.title_fc = nn.Linear(64, 32) # 1 * len(tit) * 32
        self.con_fc = nn.Linear(512, 256) # 1 * len(con) * 256
# t.cat((content_out_3,content_out_4,content_out_5),dim=1)
# input_size = len(tit) + len(con)
        self.fc = nn.Linear(input_size, 9)

    def forward(self, title, co…
  


But it is unclear how to exactly to use the Functional and nn.Parameter to incorporate a dynamic size of nn.linear