One way to do this is to subclass nn.Sequential 7 and change the forward method so that you can use a number to determine how many layers deep it goes. Then, you can build your models using your modified version of nn.Sequential to do this.