# Loading Lux params and states in a new script

**URL:** <https://discourse.julialang.org/t/loading-lux-params-and-states-in-a-new-script/131370>\
**Category:** Machine Learning\
**Tags:** jld2, lux\
**Created:** [August 5, 2025, 11:14am UTC](https://discourse.julialang.org/t/loading-lux-params-and-states-in-a-new-script/131370 "2025-08-05T11:14:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![imantha](https://avatars.discourse-cdn.com/v4/letter/i/6a8cbe/32.png) [@imantha](https://discourse.julialang.org/u/imantha)\
**Post date:** [August 5, 2025, 11:14am UTC](https://discourse.julialang.org/t/loading-lux-params-and-states-in-a-new-script/131370/1 "2025-08-05T11:14:31Z")

</div>

To save a model the Training a Simple Lstm tutorial shows the following using JDL2 package

```julia-auto
# train.jl
using JLD2
@save "trained_model.jld2" ps_trained st_trained

@load "trained_model.jld2" ps_trained st_trained

```

But this works only when the same variable names are used (Which can only be done within the same script). In the general case you would be doing inference in a new script and using two new variables, but that lead to an error

```julia-auto
#test.jl
using JLD2
@load "trained_model.jld2" params states
>>>
KeyError: key "param" not found

# Alternatively trying this,
params, states = load("checkpoints/trained_model.jld2")
>>>
{
	"name": "ErrorException",
	"message": "cannot assign a value to imported variable Turing.params from module
...
}

```

I also tried the following, but that didnt work either

```julia-auto
vae = VAE(rng, h_dims, z_dims, imp_dims, out_dims)
params, states = Lux.setup(rng, vae)
@load "checkpoints/vae_params_states.jld2" params states
>>>
{
	"name": "ErrorException",
	"message": "cannot assign a value to imported variable Turing.params from module Main",
...

```

How would you do this ?

---

<div class="post-metadata">

**Author:** ![avikpal](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/avikpal/32/6550_2.png) [@avikpal](https://discourse.julialang.org/u/avikpal)\
**Post date:** [August 5, 2025, 11:49am UTC](https://discourse.julialang.org/t/loading-lux-params-and-states-in-a-new-script/131370/2 "2025-08-05T11:49:29Z")

</div>

> [@imantha](#):
>
> ```julia-auto
> @load "trained_model.jld2" params states
> 
> ```

You need to use the correct variable names `ps_trained`, `st_trained`.

`params, states = load("checkpoints/trained_model.jld2")` doesn’t work because you have Turing.jl imported and you cannot assign a variable with the saeme name as an exported function
