You could create a config file as e.g. a JSON file and read it in your script via pandas.
Once you have the right keys from your config, you could use nn.ModuleList or nn.Sequential to create the number of layers based on the current config.
The ModuleList docs give you an example:
class MyModule(nn.Module):
    def __init__(self):
        super(MyModule, self).__init__()
        self.linears = nn.ModuleList([nn.Linear(10, 10) for i in range(10)])

    def forward(self, x):
        # ModuleList can act as an iterable, or be indexed using ints
        for i, l in enumerate(self.linears):
            x = self.linears[i // 2](x) + l(x)
        return x

Instead of the fixed 10 you could use the value passed in your config file.