# GPU gradient calculation with Zygote failling with an RTX 4060

**URL:** <https://discourse.julialang.org/t/gpu-gradient-calculation-with-zygote-failling-with-an-rtx-4060/107746>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 17, 2023, 9:27pm UTC](https://discourse.julialang.org/t/gpu-gradient-calculation-with-zygote-failling-with-an-rtx-4060/107746 "2023-12-17T21:27:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [December 17, 2023, 9:27pm UTC](https://discourse.julialang.org/t/gpu-gradient-calculation-with-zygote-failling-with-an-rtx-4060/107746/1 "2023-12-17T21:27:00Z")

</div>

Hello all, I’m having an issue with gradient calculation on gpu. The minimal code exemple is very minimal,

```julia
using Flux,CUDA,cuDNN

x = rand(Float32,1,1000) |> gpu

y = rand(Float32,1,1000) |> gpu

model = Flux.Chain(
    Flux.Dense(1,10,tanh),
    Flux.Dense(10,10,tanh),
    Flux.Dense(10,1)
) |> gpu

loss(model,x,y) = Flux.mse(model(x),y)

loss(model,x,y)

gradient(loss,model,x,y)

```

I can allocate fine, even the model, calculate the loss but when it comes to gradient, I get,

```julia
ERROR: CUDA error: an illegal memory access was encountered (code 700, ERROR_ILLEGAL_ADDRESS)
ERROR: WARNING: Error while freeing DeviceBuffer(3.906 KiB at 0x000000020502c800):
CUDA.CuError(code=CUDA.cudaError_enum(0x000002bc), details=CUDA.Optional{String}(data=nothing))

```

Afterwards, I can’t do anything gpu related.

julia version : 1.9.4

```julia
  [052768ef] CUDA v5.1.1
  [587475ba] Flux v0.14.7
  [02a925ec] cuDNN v1.2.1

```

---

<div class="post-metadata">

**Author:** ![yolhan\_mannes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yolhan_mannes/32/220485_2.png) [@yolhan\_mannes](https://discourse.julialang.org/u/yolhan_mannes)\
**Post date:** [December 17, 2023, 9:43pm UTC](https://discourse.julialang.org/t/gpu-gradient-calculation-with-zygote-failling-with-an-rtx-4060/107746/2 "2023-12-17T21:43:57Z")

</div>

update : loss(model,x,y) = norm(model(x).-y) works perfectly well, an issue for Flux.jl should be the way to go
