# ERROR: UndefVarError: \`ADAM\` not defined in \`Main\` in flux

**URL:** https://discourse.julialang.org/t/error-undefvarerror-adam-not-defined-in-main-in-flux/121784
**Category:** New to Julia
**Tags:** question
**Created:** [October 26, 2024, 12:59pm UTC](https://discourse.julialang.org/t/error-undefvarerror-adam-not-defined-in-main-in-flux/121784 "2024-10-26T12:59:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Liuxiu1512](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/liuxiu1512/32/212925_2.png) [@Liuxiu1512](https://discourse.julialang.org/u/Liuxiu1512)
#### Post date: [October 26, 2024, 12:59pm UTC](https://discourse.julialang.org/t/error-undefvarerror-adam-not-defined-in-main-in-flux/121784/1 "2024-10-26T12:59:40Z")

</div>

Hi, i get this error when try to using flux  
julia\> using Pkg

julia\> Pkg.add(“Flux”)  
Resolving package versions…  
No Changes to `C:\Users\lbtvi\.julia\environments\v1.11\Project.toml`  
No Changes to `C:\Users\lbtvi\.julia\environments\v1.11\Manifest.toml`

julia\> Pkg.add(“Images”)  
Resolving package versions…  
No Changes to `C:\Users\lbtvi\.julia\environments\v1.11\Project.toml`  
No Changes to `C:\Users\lbtvi\.julia\environments\v1.11\Manifest.toml`

julia\> Pkg.add(“BSON”)  
Resolving package versions…  
No Changes to `C:\Users\lbtvi\.julia\environments\v1.11\Project.toml`  
No Changes to `C:\Users\lbtvi\.julia\environments\v1.11\Manifest.toml`

julia\> using Flux

julia\> using Flux.Optimise  
julia\> using BSON

julia\> using Images

julia\> # Khai báo biến cho tối ưu hóa

julia\> opt = ADAM(0.001) # Khai báo tối ưu hóa ADAM với learning rate là 0.001  
ERROR: UndefVarError: `ADAM` not defined in `Main`  
Suggestion: check for spelling errors or missing imports.  
Hint: a global variable of this name may be made accessible by importing Optimisers in the current active module Main  
Stacktrace:  
[1] top-level scope  
@ REPL[10]:1

julia\>

julia\> # Huấn luyện mô hình

julia\> @epochs 10 Flux.train!(loss, params(model), data, opt) # Huấn luyện mô hình  
ERROR: LoadError: UndefVarError: `@epochs` not defined in `Main`  
Suggestion: check for spelling errors or missing imports.  
in expression starting at REPL[12]:1

julia\> using Flux: @epochs # Nhập @epochs từ Flux  
WARNING: could not import Flux.@epochs into Main

julia\>  
How can i fix this, thanks alot

---

<div class="post-metadata">

### Author: ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)
#### Post date: [October 29, 2024, 2:45pm UTC](https://discourse.julialang.org/t/error-undefvarerror-adam-not-defined-in-main-in-flux/121784/2 "2024-10-29T14:45:36Z")

</div>

> [@Liuxiu1512](#):
>
> ADAM(0.001)

This means you are following a guide for a very old version of Flux. Can you provide a link?

The current version spells this `Adam`, but also no longer has `@epochs`, and strongly discourages `Flux.params(model)`. It should look more like [this](http://fluxml.ai/Flux.jl/stable/guide/models/quickstart/).

---

<div class="post-metadata">

### Author: ![Y1123929](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/y1123929/32/213711_2.png) [@Y1123929](https://discourse.julialang.org/u/Y1123929)
#### Post date: [November 27, 2024, 9:58am UTC](https://discourse.julialang.org/t/error-undefvarerror-adam-not-defined-in-main-in-flux/121784/3 "2024-11-27T09:58:46Z")

</div>

Hello, I’ve encountered the same issue. Have you resolved it?  
Here is my code.

```julia
opt = ADAM(learning_rate)

```

My Flux is up to date, and there are no missing packages when I check with status. I’m getting the following error. How should I handle it?

```julia
ERROR: UndefVarError: `ADAM` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: a global variable of this name may be made accessible by importing Optimisers in the current active module Main
Stacktrace:
 [1] top-level scope
   @ f:\file\Machine Learning\NeuralPDE.jl-master\ANN_study\study_ANN.jl:41

```

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [November 27, 2024, 10:30am UTC](https://discourse.julialang.org/t/error-undefvarerror-adam-not-defined-in-main-in-flux/121784/4 "2024-11-27T10:30:42Z")

</div>

> [@Y1123929](#):
>
> How should I handle it?

The answer was given in the message above:

> [@mcabbott](#):
>
> The current version spells this `Adam`

---

<div class="post-metadata">

### Author: ![Y1123929](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/y1123929/32/213711_2.png) [@Y1123929](https://discourse.julialang.org/u/Y1123929)
#### Post date: [November 28, 2024, 10:01am UTC](https://discourse.julialang.org/t/error-undefvarerror-adam-not-defined-in-main-in-flux/121784/5 "2024-11-28T10:01:16Z")

</div>

ok！thank you.
