Closed as not planned
Description
There is a significant difference in the time it takes to perform inference using the reconstruct method below versus defining the function model i.e. the neural network using a function feedforward() as below. For a very simple and small problem like the IRIS dataset, the difference in efficiency when using the function method the inference happens in under one minute, and when using the reconstruct method then it takes 30 minutes. Any ideas why this happens and how to make the reconstruct method comparable?
@model function bayesnnMVG(x, y, μ_prior, σ_prior, reconstruct)
θ ~ MvNormal(μ_prior, σ_prior)
nn = reconstruct(θ)
ŷ = nn(x)
for i = 1:lastindex(y)
y[i] ~ Categorical(ŷ[:, i])
end
end
where parameters_initial, reconstruct = Flux.destructure(nn_initial)
As compared to the below
@model function bayesnnMVG(x, y, μ_prior, σ_prior)
θ ~ MvNormal(μ_prior, σ_prior)
nn = feedforward(θ)
ŷ = nn(x)
for i = 1:lastindex(y)
y[i] ~ Categorical(ŷ[:, i])
end
end
where
function feedforward(θ::AbstractVector)
W0 = reshape(θ[1:20], 5, 4)
...
model = Chain(
Dense(W0, b0, relu),
...
return model
end
Metadata
Metadata
Assignees
Labels
No labels