DeepTrackAI / deeplay

Other
4 stars 5 forks source link

.configure unexpected behavior #121

Closed JesusPinedaC closed 1 month ago

JesusPinedaC commented 1 month ago

Consider a sequential model composed of a CNN and an MLP:

from deeplay import ConvolutionalNeuralNetwork, MultiLayerPerceptron, Sequential

cnn = ConvolutionalNeuralNetwork(
    in_channels=1, 
    hidden_channels=[32, 64], 
    out_channels=96, 
    out_activation=nn.ReLU
)

mlp = MultiLayerPerceptron(
    in_features=None, 
    hidden_features=[64], 
    out_features=96, 
    out_activation=nn.ReLU
)

model = Sequential(cnn, mlp)

This default model works correctly. The problem arises when configuring the MLP.

For example, when expanding the number of hidden features:

model[1].configure(hidden_features=[32, 64])

Until this point, everything works correctly:

MultiLayerPerceptron(
  (blocks): LayerList(
    (0): LinearBlock(
      (layer): Layer[LazyLinear](out_features=32, bias=True)
      (activation): Layer[ReLU]()
    )
    (1): LinearBlock(
      (layer): Layer[Linear](in_features=32, out_features=64, bias=True)
      (activation): Layer[ReLU]()
    )
    (2): LinearBlock(
      (layer): Layer[Linear](in_features=64, out_features=96, bias=True)
      (activation): Layer[ReLU]()
    )
  )
)

But when creating (or building) the model, it breaks:

(1): MultiLayerPerceptron(
    (blocks): LayerList(
      (0): LinearBlock(
        (layer): LazyLinear(in_features=0, out_features=32, bias=True)
        (activation): ReLU()
      )
      (1): LinearBlock(
        (layer): Linear(in_features=32, out_features=64, bias=True)
        (activation): ReLU()
      )
      (2): LinearBlock(
        (layer): Linear(in_features=64, out_features=96, bias=True)
        (activation): ReLU()
      )
      (3): LinearBlock(
        (layer): Linear(in_features=32, out_features=64, bias=True)
        (activation): ReLU()
      )
      (4): LinearBlock(
        (layer): Linear(in_features=64, out_features=96, bias=True)
        (activation): ReLU()
      )
    )
  )

This issue was tested on a brand-new Linux machine with a fresh installation of deeplay

giovannivolpe commented 1 month ago

Closed with PR #122