# Flux How to convert model weights to Float16

**URL:** https://discourse.julialang.org/t/flux-how-to-convert-model-weights-to-float16/93630
**Category:** Machine Learning
**Created:** [January 27, 2023, 12:26pm UTC](https://discourse.julialang.org/t/flux-how-to-convert-model-weights-to-float16/93630 "2023-01-27T12:26:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![reachtarunhere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/reachtarunhere/32/38358_2.png) [@reachtarunhere](https://discourse.julialang.org/u/reachtarunhere)
#### Post date: [January 27, 2023, 12:26pm UTC](https://discourse.julialang.org/t/flux-how-to-convert-model-weights-to-float16/93630/1 "2023-01-27T12:26:03Z")

</div>

```julia
m = Dense(10, 2)
# now the initialized weights are Float32 type.
m2 = Dense(rand(Float16, 2, 10)) # works

```

When I init the weights it is fine but I have an existing complex model with many layers and I would like Float16 version of it.

Thanks!

---

<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: [January 27, 2023, 1:31pm UTC](https://discourse.julialang.org/t/flux-how-to-convert-model-weights-to-float16/93630/2 "2023-01-27T13:31:57Z")

</div>

Looking at `@less f32([1.0])` shows that this ought to work:

```julia
f16(m) = Flux.paramtype(Float16, m)

```

Probably this should be built-in, if someone wants to make a PR.

---

<div class="post-metadata">

### Author: ![reachtarunhere](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/reachtarunhere/32/38358_2.png) [@reachtarunhere](https://discourse.julialang.org/u/reachtarunhere)
#### Post date: [January 27, 2023, 2:01pm UTC](https://discourse.julialang.org/t/flux-how-to-convert-model-weights-to-float16/93630/3 "2023-01-27T14:01:54Z")

</div>

Thanks that does exactly what I need. Can you say more about what you mean by this should be built in?

We can also have something like CUDA.jl’s device! ?
