How can I add to ML model together in Flux

Like I have two model now
M1=Chain(
Dense(2,10),
Dense(10,10,relu),
Dense(10,10,relu),
Dense(10,10,relu),
Dense(10,1)
)
M2=Chain(
Dense(2,10),
Dense(10,10,relu),
Dense(10,10,relu),
Dense(10,10,relu),
Dense(10,1)
)

and the model I want to train is model=M1+M2
but if I just add them Flux.params(M) shows nothing and I can not train it .

Are you trying to create an ensemble? I’m not sure of your use case but it seems like to independent models of identical structure. In this case you should run two training sessions and combine them after they’ve both been fitted to your data.

Actually, I want the M1 minimize a loss functiona(Loss1) and M=M1+M2 minimize another loss function(Loss2) at the same time. The finial Loss Funcition is something like Loss= Loss1[M1(x)] + \beta Loss2[M(x)].