Combining Parameterlist in PyTorch

I am trying to combine two ParameterLists in Pytorch. I’ve implemented the following snippet:

import torch

list = nn.ParameterList()
for i in sub_list_1:
for i in sub_list_2:

Is there any functions that takes care of this without a need to loop over each list?

You could unwrap the sub lists and pass their content to nn.ParameterList as seen here:

sub_list_1 = nn.ParameterList([nn.Parameter(torch.ones(1))])
sub_list_2 = nn.ParameterList([nn.Parameter(torch.ones(1) * 2)])
param_list = nn.ParameterList([*sub_list_1, *sub_list_2])

sub_list_1 = [nn.Parameter(torch.ones(1))]
sub_list_2 = [nn.Parameter(torch.ones(1) * 2)]
param_list = nn.ParameterList([*sub_list_1, *sub_list_2])
1 Like