# GPU memory in Julia

**URL:** <https://discourse.julialang.org/t/gpu-memory-in-julia/109216>\
**Category:** Machine Learning\
**Tags:** question\
**Created:** [January 24, 2024, 9:07pm UTC](https://discourse.julialang.org/t/gpu-memory-in-julia/109216 "2024-01-24T21:07:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wenbo\_Li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wenbo_li/32/203744_2.png) [@Wenbo\_Li](https://discourse.julialang.org/u/Wenbo_Li)\
**Post date:** [January 24, 2024, 9:07pm UTC](https://discourse.julialang.org/t/gpu-memory-in-julia/109216/1 "2024-01-24T21:07:04Z")

</div>

I am training unet with 3d input size 512_512_128. However, with the same model, same loss function, same size of input and label in float32, python indeed can fit and train while julia not. Also, julia need much longer time to prepare for the training. Are there some problems or it’s just the nature of juliia?

 ![Screenshot from 2024-01-24 12-50-27](https://global.discourse-cdn.com/julialang/original/3X/f/e/fe25fc816b9cb573b05672998d4dc7862ca6d612.png)

---

<div class="post-metadata">

**Author:** ![Wenbo\_Li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wenbo_li/32/203744_2.png) [@Wenbo\_Li](https://discourse.julialang.org/u/Wenbo_Li)\
**Post date:** [January 24, 2024, 9:07pm UTC](https://discourse.julialang.org/t/gpu-memory-in-julia/109216/2 "2024-01-24T21:07:59Z")

</div>

![Screenshot from 2024-01-24 13-00-24](https://global.discourse-cdn.com/julialang/original/3X/2/7/270ab24175cdc3461ccf8b55bb991030ab3d0e27.png)

---

<div class="post-metadata">

**Author:** ![roflmaostc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/roflmaostc/32/30123_2.png) [@roflmaostc](https://discourse.julialang.org/u/roflmaostc)\
**Post date:** [January 24, 2024, 9:26pm UTC](https://discourse.julialang.org/t/gpu-memory-in-julia/109216/3 "2024-01-24T21:26:31Z")

</div>

I’m not quite familiar with Lux but `rand(512,512,128,1,1)` creates a Float64 array.

Does `dev` convert it to Float32 in case of the GPU? Did you check?

Did you also close the Python process before such that Julia and Python don’t have to share memory?

---

<div class="post-metadata">

**Author:** ![Dale\_James\_Black](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dale_james_black/32/11595_2.png) [@Dale\_James\_Black](https://discourse.julialang.org/u/Dale_James_Black)\
**Post date:** [January 25, 2024, 12:39am UTC](https://discourse.julialang.org/t/gpu-memory-in-julia/109216/4 "2024-01-25T00:39:27Z")

</div>

It would be helpful to share the code for the PyTorch model and the Julia model

PyTorch:

```python
class UNet(nn.Module)
....

```

Julia:

```julia
function UNet()
    return Chain(...)
end

```

---

<div class="post-metadata">

**Author:** ![Wenbo\_Li](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/wenbo_li/32/203744_2.png) [@Wenbo\_Li](https://discourse.julialang.org/u/Wenbo_Li)\
**Post date:** [January 25, 2024, 1:13am UTC](https://discourse.julialang.org/t/gpu-memory-in-julia/109216/5 "2024-01-25T01:13:40Z")

</div>

I converted all the arrays to Float32 and then |\> dev and tried again. Still no luck. And yes, I made sure the python process was closed before running Julia. I’m watching nvdia-smi every 2 seconds.

---

<div class="post-metadata">

**Author:** ![Dale\_James\_Black](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dale_james_black/32/11595_2.png) [@Dale\_James\_Black](https://discourse.julialang.org/u/Dale_James_Black)\
**Post date:** [January 25, 2024, 6:02pm UTC](https://discourse.julialang.org/t/gpu-memory-in-julia/109216/6 "2024-01-25T18:02:03Z")

</div>

Please share a MWE so that others can help debug better. Without both models and the full training loops it’s hard to know where to start
