openpi icon indicating copy to clipboard operation
openpi copied to clipboard

[Question] why jax use float32 while torch use bfloat16?

Open Rhys-Q opened this issue 1 year ago • 7 comments

Hi, I'm currently running PI 0.5. I noticed that the default data type in JAX is float32, whereas it's bfloat16 in PyTorch. Could you explain the reason behind this difference?

Rhys-Q avatar Oct 22 '25 09:10 Rhys-Q

This is more of a JAX, and upstream NumPy question, than a PI question.

You may want to ask the devs of those projects for a better answer, but my guess is, NumPy is a general purpose numeric library, and so uses the more precise float16, while machine learning requires a wider dynamic range and so PyTorch uses bfloat16.

I hope this helps.

evelynmitchell avatar Oct 22 '25 18:10 evelynmitchell

This is more of a JAX, and upstream NumPy question, than a PI question.

You may want to ask the devs of those projects for a better answer, but my guess is, NumPy is a general purpose numeric library, and so uses the more precise float16, while machine learning requires a wider dynamic range and so PyTorch uses bfloat16.

I hope this helps.

Thanks. I have confirmed that the JAX model already adopts mixed precision. Additionally, I observed that the PyTorch model has lower inference latency than the JAX model in 4090 GPU, the speedup is about 140%. torch.compile is the main source of speedup.

Rhys-Q avatar Oct 23 '25 04:10 Rhys-Q

Hey, have you observe performance gap between models of jax and pytorch?

zwbx avatar Nov 26 '25 07:11 zwbx

Hi, I observed a significant performance gap between the JAX and PyTorch models. Under the same dataset and normalization settings, the JAX version performs very well, while the PyTorch version shows noticeably worse results.

JinmingM avatar Dec 08 '25 09:12 JinmingM

Hi, I observed a significant performance gap between the JAX and PyTorch models. Under the same dataset and normalization settings, the JAX version performs very well, while the PyTorch version shows noticeably worse results.

which model are you using acutually?

zwbx avatar Dec 10 '25 03:12 zwbx

Image

Image

Figure 2 shows the jax version's performance, while Figure 1 shows the pytorch version. It seems that pytorch is completely unable to work? Have you ever run into this situation?

zttiannnn avatar Dec 29 '25 02:12 zttiannnn

Hi, I observed a significant performance gap between the JAX and PyTorch models. Under the same dataset and normalization settings, the JAX version performs very well, while the PyTorch version shows noticeably worse results.

Did you solve this problem? Did you ultimately use the torch model or the jax model

hyn1426536274 avatar Apr 28 '26 03:04 hyn1426536274