Hi @Akis_Linardos!
This should be possible. This following snippet is a good example:
from torch import nn
from collections import OrderedDict

class Net(nn.Module):
    
    def __init__(self, n_layers):
        
        super().__init__()
        
        layers = OrderedDict()
        for i in range(n_layers):
            layers[str(i)] = nn.Linear(5,5)
            
        self.layers = nn.Sequential(layers)
        print(self)
        
Net(n_layers=3)

The output will then be
Net(
  (layers): Sequential(
    (0): Linear(in_features=5, out_features=5)
    (1): Linear(in_features=5, out_features=5)
    (2): Linear(in_features=5, out_features=5)
  )
)

While this is just a crude example, you are able to add complexity to this with more logic.