# How to train a combination of models in Flux?

I have two models m1 and m2. Here is my code:

``````using Flux

s1, s2 = size(x)
end

s1, s2 = size(x)
end

function even_duplicate(x)
s1, s2 = size(x)
x_ = zeros(s1, s2)
x_[1:2:s1,:] = x[1:2:s1,:]
x_[2:2:s1,:] = x[1:2:s1,:]
return x_
end

function odd_duplicate(x)
s1, s2 = size(x)
x_ = zeros(s1, s2)
x_[1:2:s1,:] = x[2:2:s1,:]
x_[2:2:s1,:] = x[2:2:s1,:]
return x_
end

function Even(m)
end

function InvEven(m)
end

function Odd(m)
end

function InvOdd(m)
end

m1 = Chain(Dense(4,6,relu), Dense(6,5,relu), Dense(5,4))
m2 = Chain(Dense(4,7,relu), Dense(7,4))

forward = Chain(Even(m1), Odd(m2))
inverse = Chain(InvOdd(m2), InvEven(m1))

function loss(x)
z = forward(x)
return 0.5*sum(z.*z)
end

x = rand(4,100)

for i=1:100
Flux.train!(loss, Flux.params(forward), x, opt)
println(loss(x))
end
``````

The forward model is a combination of m1 and m2. I need to optimize m1 and m2 so I could optimize both forward and inverse models. But it seems that params(forward) is empty. How could I train my model?

try with passing `Flux.params(m1, m2)` to train!.
I see you are doing array mutations, that wonâ€™t work with zygote

What is array mutation?