# Inplace implementation for neural networks in Lux.jl

**URL:** <https://discourse.julialang.org/t/inplace-implementation-for-neural-networks-in-lux-jl/126749>\
**Category:** General Usage\
**Tags:** machine-learning, lux\
**Created:** [March 10, 2025, 7:50am UTC](https://discourse.julialang.org/t/inplace-implementation-for-neural-networks-in-lux-jl/126749 "2025-03-10T07:50:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yang-yang](https://avatars.discourse-cdn.com/v4/letter/y/b2d939/32.png) [@Yang-yang](https://discourse.julialang.org/u/Yang-yang)\
**Post date:** [March 10, 2025, 7:50am UTC](https://discourse.julialang.org/t/inplace-implementation-for-neural-networks-in-lux-jl/126749/1 "2025-03-10T07:50:20Z")

</div>

Hi everyone,  
I want to know if using an in-place version of the Lux layers is better. I noticed a related pull request [https://github.com/LuxDL/Lux.jl/pull/463](https://github.com/LuxDL/Lux.jl/pull/463), but I don’t know why this pull request was canceled.

Since the memory usage(GPU memory) keeps increasing when I train a Lux model, I think the in-place layer will reduce the memory allocation.

---

<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:** [March 12, 2025, 1:26am UTC](https://discourse.julialang.org/t/inplace-implementation-for-neural-networks-in-lux-jl/126749/2 "2025-03-12T01:26:26Z")

</div>

Inplace versions would require a massive rewrite and won’t really be that advantageous without other optimizations. Instead checkout Reactant + Lux ([Compiling Lux Models using Reactant.jl | Lux.jl Docs](https://lux.csail.mit.edu/stable/manual/compiling_lux_models)), that will be significantly faster and will pre-allocate required vram memory once compiled
