Invalid syntax error when passing a list of modules in Pytorch
I have two blocks in my deep models which are defined as follows:

def make_conv_bn_relu(in_channels, out_channels, kernel_size=3, stride=1, padding=1):
    return [
        nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, stride=stride, padding=padding, bias=False),
        nn.BatchNorm2d(out_channels),
        nn.ReLU(inplace=True),
    ]

def make_conv_relu(in_channels, out_channels, kernel_size=3, stride=1, padding=1):
    return [
        nn.Conv2d(in_channels, out_channels, kernel_size=kernel_size, stride=stride, padding=padding, bias=True),
        nn.ReLU(inplace=True),
    ]


Now, I want to pass it in nn.Sequential.

self.down1 = nn.Sequential(*make_conv_bn_relu(in_channels, 16, kernel_size=3, stride=1, padding=1 ), *make_conv_bn_relu(16, 32, kernel_size=3, stride=2, padding=1 ),)


But I am getting the following error:

Traceback (most recent call last):
  File "train_unet.py", line 17, in &lt;module&gt;
    from net.model.unet1 import UNet256_3x3 as Net
  File "/home/avijit.d/Kaggle/Pytorch/source/dummy-01/net/model/unet1.py", line 40
    self.down1 = nn.Sequential(*make_conv_bn_relu(in_channels, 16, kernel_size=3, stride=1, padding=1 ), *make_conv_bn_relu(16, 32, kernel_size=3, stride=2, padding=1 ),)
                                                                                                         ^
SyntaxError: invalid syntax


How to get rid of this? I am using Python 2.7

You can't use multiple unpacks in python2. But if you really want to use it then just concatenate lists:

nn.Squential(*(make_foo() + make_bar()))

