This is not the safe way to do as showed in Saving ADVI results and reloading
A better solution is below:
The safe way to do is to save the parameters as a dictionary, and map it back to a vector whenever the new model is created.
...
# save inference
bij = inference.approx.groups[0].bij
saveparam = {param.name: bij.rmap(param.eval())
for param in inference.approx.params}
# new model
model2 = construct_neural_network(
X, Y, Yerr, neuronsPerHiddenlayer, ninputs, noutputs, ndata)
with model2:
inference2 = pm.ADVI()
# load inference
bij2 = inference2.approx.groups[0].bij
inference2.approx.params[0].set_value(bij2.map(saveparam['mu']))
inference2.approx.params[1].set_value(bij2.map(saveparam['rho']))