# SGD in Flux.jl

**URL:** <https://discourse.julialang.org/t/sgd-in-flux-jl/63130>\
**Category:** Machine Learning\
**Tags:** question, api\
**Created:** [June 18, 2021, 8:21am UTC](https://discourse.julialang.org/t/sgd-in-flux-jl/63130 "2021-06-18T08:21:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wujinq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wujinq/32/22221_2.png) [@wujinq](https://discourse.julialang.org/u/wujinq)\
**Post date:** [June 18, 2021, 8:21am UTC](https://discourse.julialang.org/t/sgd-in-flux-jl/63130/1 "2021-06-18T08:21:42Z")

</div>

I’m new to Flux.jl, and I’m kind of confused by the fact that there is no stochastic gradient descent algorithm. I checked the source code, and it seemed to me that `Descent` is just GD instead of SGD.

Of course we can just introduce some random factors into the training data. Anyway, what is the best practice to perform SGD in Flux.jl?

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [June 18, 2021, 10:30am UTC](https://discourse.julialang.org/t/sgd-in-flux-jl/63130/2 "2021-06-18T10:30:48Z")

</div>

Not getting what you saying.

The S in SGD doesn’t come from choosing a random direction. It still moves in the direction that minimizes the loss. The SGD comes from passing in partial data batches e.g. if your data is 1\_000\_000 records you only pass it 32 records at a time. These 32 are randomly re-assigned each epoch, so your GD is stochastic by the randomness of where you are in the loss function and the randomness in the batch.

Hope that makes sense.
