# mixed-precision

**URL:** https://discuss.pytorch.org/c/mixed-precision/27.md

[Latest](https://discuss.pytorch.org/latest.md) · [Categories](https://discuss.pytorch.org/categories.md)

---

## [About the mixed-precision category](https://discuss.pytorch.org/t/about-the-mixed-precision-category/93965)

<div class="topic-metadata">

**Author:** [@albanD](https://discuss.pytorch.org/u/albanD)\
**Replies:** 0

</div>

---

## [Can AMP mixed-precision training reduce accuracy drop after converting model to TensorRT FP16?](https://discuss.pytorch.org/t/can-amp-mixed-precision-training-reduce-accuracy-drop-after-converting-model-to-tensorrt-fp16/224453)

<div class="topic-metadata">

**Author:** [@zuko0219](https://discuss.pytorch.org/u/zuko0219)\
**Replies:** 0\
**Last updated:** [January 31, 2026, 7:37pm UTC](https://discuss.pytorch.org/t/can-amp-mixed-precision-training-reduce-accuracy-drop-after-converting-model-to-tensorrt-fp16/224453 "2026-01-31T19:37:10Z")

</div>

Hi I’m currently observing an accuracy drop when converting a PyTorch model to TensorRT with FP16 precision for inference. I’m wondering whether training the model using mixed precision (PyTorch AMP) can help the model…

---

## [Subnormal FP16 values detected when converting to TRT](https://discuss.pytorch.org/t/subnormal-fp16-values-detected-when-converting-to-trt/157663)

<div class="topic-metadata">

**Author:** [@Yao\_Xue](https://discuss.pytorch.org/u/Yao_Xue)\
**Replies:** 5\
**Last updated:** [January 6, 2026, 9:04am UTC](https://discuss.pytorch.org/t/subnormal-fp16-values-detected-when-converting-to-trt/157663 "2026-01-06T09:04:28Z")

</div>

When converting my model to ONNX and then TensorRT, I encountered this issue: \[07/27/2022-23:16:56\] \[W\] \[TRT\] Weights \[name=Conv\_13706.weight\] had the following issues when converted to FP16: \[07/27/2022-23:16:56\] \[W\] …

---

## [Bfloat16 training](https://discuss.pytorch.org/t/bfloat16-training/222382)

<div class="topic-metadata">

**Author:** [@nastya236](https://discuss.pytorch.org/u/nastya236)\
**Replies:** 2\
**Last updated:** [September 18, 2025, 9:31am UTC](https://discuss.pytorch.org/t/bfloat16-training/222382 "2025-09-18T09:31:26Z")

</div>

Hey! I was wondering about your experience with bf16 training, specifically the type of the gradients and the weights. From the repositories I’ve checked, it seems there are two main approaches (assuming a single GPU, …

---

## [Why is closure not supported in GradScaler ?](https://discuss.pytorch.org/t/why-is-closure-not-supported-in-gradscaler/136009)

<div class="topic-metadata">

**Author:** [@ar90n](https://discuss.pytorch.org/u/ar90n)\
**Replies:** 5\
**Last updated:** [September 17, 2025, 11:14am UTC](https://discuss.pytorch.org/t/why-is-closure-not-supported-in-gradscaler/136009 "2025-09-17T11:14:47Z")

</div>

In the step function of GradScaler, if a closure is given as a member of kwargs, RuntimeError occurs by the following codes. The error message says “not currently supported”. Are there any plans to support this featur…

---

## [How to do quantization for hybrid CNN+RNN(primarily GRU) pytorch model on Nvidia GPU?](https://discuss.pytorch.org/t/how-to-do-quantization-for-hybrid-cnn-rnn-primarily-gru-pytorch-model-on-nvidia-gpu/222457)

<div class="topic-metadata">

**Author:** [@Aman\_230](https://discuss.pytorch.org/u/Aman_230)\
**Replies:** 0\
**Last updated:** [August 18, 2025, 12:53pm UTC](https://discuss.pytorch.org/t/how-to-do-quantization-for-hybrid-cnn-rnn-primarily-gru-pytorch-model-on-nvidia-gpu/222457 "2025-08-18T12:53:29Z")

</div>

Currently my model has FP32 i want to convert it to INT8, i have trained the model. I explored and deep dived into the pytorch documentation but haven’t able to conclude? Anyone please help me.

---

## [How to convert MXFP4 -\> FP8 in pure pytorch?](https://discuss.pytorch.org/t/how-to-convert-mxfp4-fp8-in-pure-pytorch/222258)

<div class="topic-metadata">

**Author:** [@vgoklani](https://discuss.pytorch.org/u/vgoklani)\
**Replies:** 0\
**Last updated:** [August 11, 2025, 6:59pm UTC](https://discuss.pytorch.org/t/how-to-convert-mxfp4-fp8-in-pure-pytorch/222258 "2025-08-11T18:59:31Z")

</div>

We have four NVIDIA A6000 Ada cards which are all SM89 and don’t support MXFP4. We would like to run GPT-OSS 20B (or any model actually) in FP8 using tensor parallel for inference. How should we convert the FP4 tensors t…

---

## [Half Precision based training adaptations](https://discuss.pytorch.org/t/half-precision-based-training-adaptations/221996)

<div class="topic-metadata">

**Author:** [@nath-11743](https://discuss.pytorch.org/u/nath-11743)\
**Replies:** 3\
**Last updated:** [August 4, 2025, 2:54am UTC](https://discuss.pytorch.org/t/half-precision-based-training-adaptations/221996 "2025-08-04T02:54:52Z")

</div>

Hello, I Wanted to try a few training recipes in fixed precision looking for documentation on how different modules in a model should be converted correctly my current setup just uses model.half() or model.to(torch.f…

---

## [Conv2d bfloat16 slower than float16 on 4090](https://discuss.pytorch.org/t/conv2d-bfloat16-slower-than-float16-on-4090/220332)

<div class="topic-metadata">

**Author:** [@Victor\_Chen](https://discuss.pytorch.org/u/Victor_Chen)\
**Replies:** 0\
**Last updated:** [May 26, 2025, 3:00am UTC](https://discuss.pytorch.org/t/conv2d-bfloat16-slower-than-float16-on-4090/220332 "2025-05-26T03:00:33Z")

</div>

I found that on my nvidia 4090, Conv2d on bfloat16 is always slower than float16. is that an expected behaviour? as i did not find previous cases. this is my test script, run directly with copy-paste: import torch impo…

---

## [Autocast behaviour in different GPUs?](https://discuss.pytorch.org/t/autocast-behaviour-in-different-gpus/218209)

<div class="topic-metadata">

**Author:** [@strivn](https://discuss.pytorch.org/u/strivn)\
**Replies:** 1\
**Last updated:** [May 23, 2025, 11:23am UTC](https://discuss.pytorch.org/t/autocast-behaviour-in-different-gpus/218209 "2025-05-23T11:23:53Z")

</div>

Hi, I’m doing my deep learning assignment and I moved over my code from Kaggle with P100 to a computing cluster with V100. The code and config stays the same, but when I ran the training, the model can’t converge (loss …

---

## [PyTorch 2.x causes divergence during training with mixed precision](https://discuss.pytorch.org/t/pytorch-2-x-causes-divergence-during-training-with-mixed-precision/219775)

<div class="topic-metadata">

**Author:** [@TitusPullo](https://discuss.pytorch.org/u/TitusPullo)\
**Replies:** 1\
**Last updated:** [May 8, 2025, 1:10pm UTC](https://discuss.pytorch.org/t/pytorch-2-x-causes-divergence-during-training-with-mixed-precision/219775 "2025-05-08T13:10:55Z")

</div>

I was previously using PyTorch 1.13. I have a regular mixed precision setup where I use autocast. There are noticeable speed ups with mixed precision enabled, so everything works fine. However, I need to update my PyTor…

---

## [How to setup buffers and parameters for mixed precision training](https://discuss.pytorch.org/t/how-to-setup-buffers-and-parameters-for-mixed-precision-training/218845)

<div class="topic-metadata">

**Author:** [@pytorcher](https://discuss.pytorch.org/u/pytorcher)\
**Replies:** 0\
**Last updated:** [April 7, 2025, 10:23pm UTC](https://discuss.pytorch.org/t/how-to-setup-buffers-and-parameters-for-mixed-precision-training/218845 "2025-04-07T22:23:21Z")

</div>

I have a module which uses backwards hooks, buffers, and parameters, that works properly with either float of half tensors when specified. I am now using it with AMP mixed precision for the first time and it is causing t…

---

## [Is there a way to force some functions to be run with FP32 precision?](https://discuss.pytorch.org/t/is-there-a-way-to-force-some-functions-to-be-run-with-fp32-precision/150445)

<div class="topic-metadata">

**Author:** [@Dazitu616](https://discuss.pytorch.org/u/Dazitu616)\
**Replies:** 4\
**Last updated:** [February 2, 2025, 7:51pm UTC](https://discuss.pytorch.org/t/is-there-a-way-to-force-some-functions-to-be-run-with-fp32-precision/150445 "2025-02-02T19:51:44Z")

</div>

Currently I want to train my model using FP16. However, I have a model which utilizes some CUDA ops borrowed from others’ repo. Those ops only accept FP32 input. Since I’m not familiar with CUDA, I don’t want to modify t…

---

## [Do we need to do torch.cuda.amp.autocast(enabled=False) before a custom function?](https://discuss.pytorch.org/t/do-we-need-to-do-torch-cuda-amp-autocast-enabled-false-before-a-custom-function/113486)

<div class="topic-metadata">

**Author:** [@hughperkins](https://discuss.pytorch.org/u/hughperkins)\
**Replies:** 4\
**Last updated:** [February 2, 2025, 2:58pm UTC](https://discuss.pytorch.org/t/do-we-need-to-do-torch-cuda-amp-autocast-enabled-false-before-a-custom-function/113486 "2025-02-02T14:58:16Z")

</div>

We have some code that is designed to run in mixed-precision. It contains a custom CUDA kernel call. Currently we are placing a with torch.cuda.amp.autocast(enabled=False) guard around the custom CUDA kernel call, and th…

---

## [Can \`autocast\` handle networks with layers having different dtypes?](https://discuss.pytorch.org/t/can-autocast-handle-networks-with-layers-having-different-dtypes/212045)

<div class="topic-metadata">

**Author:** [@ronan.fruit](https://discuss.pytorch.org/u/ronan.fruit)\
**Replies:** 4\
**Last updated:** [January 10, 2025, 2:26pm UTC](https://discuss.pytorch.org/t/can-autocast-handle-networks-with-layers-having-different-dtypes/212045 "2025-01-10T14:26:38Z")

</div>

Hi, torch version = 2.5.0 I am wondering whether torch.autocast can handle neural networks with layers having different dtypes. The following code suggests it cannot: import torch net = torch.nn.Sequential( torch…

---

## [How to Use Custom fp8 to fp16 Datatype Represented in uint8 in PyTorch](https://discuss.pytorch.org/t/how-to-use-custom-fp8-to-fp16-datatype-represented-in-uint8-in-pytorch/215132)

<div class="topic-metadata">

**Author:** [@erfan\_mhi](https://discuss.pytorch.org/u/erfan_mhi)\
**Replies:** 1\
**Last updated:** [January 8, 2025, 7:55pm UTC](https://discuss.pytorch.org/t/how-to-use-custom-fp8-to-fp16-datatype-represented-in-uint8-in-pytorch/215132 "2025-01-08T19:55:11Z")

</div>

Hi everyone, I’ve been working on a project where I wrote a custom datatype conversion from fp16 to fp8 (E4M3 and E5M2), which is represented in uint8 in PyTorch. I’m a bit stuck on how to use this datatype properly in …

---

## [TF32 flags when using AMP](https://discuss.pytorch.org/t/tf32-flags-when-using-amp/200569)

<div class="topic-metadata">

**Author:** [@CDhere](https://discuss.pytorch.org/u/CDhere)\
**Replies:** 5\
**Last updated:** [December 26, 2024, 5:45pm UTC](https://discuss.pytorch.org/t/tf32-flags-when-using-amp/200569 "2024-12-26T17:45:50Z")

</div>

Hi! I’m trying out TF32 and mixed precision training. Can they be used at the same time? Namely, is setting the flags like this ok when I enable mixed precision training, or should I actually set them back to False? tor…

---

## [Does autocast create copies of tensors on the fly?](https://discuss.pytorch.org/t/does-autocast-create-copies-of-tensors-on-the-fly/214268)

<div class="topic-metadata">

**Author:** [@Aknw\_Fen](https://discuss.pytorch.org/u/Aknw_Fen)\
**Replies:** 2\
**Last updated:** [December 16, 2024, 5:30pm UTC](https://discuss.pytorch.org/t/does-autocast-create-copies-of-tensors-on-the-fly/214268 "2024-12-16T17:30:40Z")

</div>

From autocast docs, it appears that: Ops will autocast within an autocast block - if the Ops support it. But tensors don’t change type, see example below, so I assume a copy must be created. So, for example here: im…

---

## [Slow convolutions on CPU with autocast](https://discuss.pytorch.org/t/slow-convolutions-on-cpu-with-autocast/214226)

<div class="topic-metadata">

**Author:** [@Aknw\_Fen](https://discuss.pytorch.org/u/Aknw_Fen)\
**Replies:** 2\
**Last updated:** [December 14, 2024, 5:25pm UTC](https://discuss.pytorch.org/t/slow-convolutions-on-cpu-with-autocast/214226 "2024-12-14T17:25:11Z")

</div>

Context After observing slower training (by logging.) using autocast, a profiling was run to check for expensive operations. This shows CPU results, but using T4s (GPU) in Colab, bfloat16 takes very long (just like flo…

---

## [Dtype different for eval and train loop with mixed prescison](https://discuss.pytorch.org/t/dtype-different-for-eval-and-train-loop-with-mixed-prescison/214095)

<div class="topic-metadata">

**Author:** [@m.span](https://discuss.pytorch.org/u/m.span)\
**Replies:** 5\
**Last updated:** [December 12, 2024, 8:06am UTC](https://discuss.pytorch.org/t/dtype-different-for-eval-and-train-loop-with-mixed-prescison/214095 "2024-12-12T08:06:58Z")

</div>

I just came across a curious behaviour when using mixed-precision with HuggingFace (SFTTrainer and PEFT) when training Mistral-7b. The embeddings and layer norms are kept in full precision and therefore the hidden state…

---

## [The dtype of optimizer states in PyTorch AMP training](https://discuss.pytorch.org/t/the-dtype-of-optimizer-states-in-pytorch-amp-training/214067)

<div class="topic-metadata">

**Author:** [@Chaohao\_Yang](https://discuss.pytorch.org/u/Chaohao_Yang)\
**Replies:** 1\
**Last updated:** [December 10, 2024, 10:56pm UTC](https://discuss.pytorch.org/t/the-dtype-of-optimizer-states-in-pytorch-amp-training/214067 "2024-12-10T22:56:43Z")

</div>

Hello. I know that when using PyTorch AMP for training, the model weights are of type float32, while the gradients are 16 bits. I’m now wondering what the type of optimizer states is. For example, if I use Adam optimizer…

---

## [BFloat16 training - explicit cast vs autocast](https://discuss.pytorch.org/t/bfloat16-training-explicit-cast-vs-autocast/202618)

<div class="topic-metadata">

**Author:** [@victorx](https://discuss.pytorch.org/u/victorx)\
**Replies:** 9\
**Last updated:** [December 2, 2024, 2:17pm UTC](https://discuss.pytorch.org/t/bfloat16-training-explicit-cast-vs-autocast/202618 "2024-12-02T14:17:22Z")

</div>

In Pytorch, there seems to be two ways to train a model in bf16 dtype. One is to explicitly use input\_data=input\_data.to(torch.bfloat16) and model=model.to(torch.bloat16) to cast both input data and model to bfloat 16 f…

---

## [Autocast on cpu dramatically slow](https://discuss.pytorch.org/t/autocast-on-cpu-dramatically-slow/196203)

<div class="topic-metadata">

**Author:** [@Laurent1](https://discuss.pytorch.org/u/Laurent1)\
**Replies:** 4\
**Last updated:** [November 27, 2024, 12:35am UTC](https://discuss.pytorch.org/t/autocast-on-cpu-dramatically-slow/196203 "2024-11-27T00:35:05Z")

</div>

Hi, On a toy regression model with pytorch 2.1.2 on cpu, torch.autocast is really slow. Without with torch.autocast(device\_type="cpu", dtype=torch.bfloat16, cache\_enabled=True) in the code below, I get Epoch 0: Loss: …

---

## [FCN ResNet18 low precision on SUNRGBD dataset](https://discuss.pytorch.org/t/fcn-resnet18-low-precision-on-sunrgbd-dataset/213193)

<div class="topic-metadata">

**Author:** [@Cupa\_cups](https://discuss.pytorch.org/u/Cupa_cups)\
**Replies:** 0\
**Last updated:** [November 20, 2024, 9:38am UTC](https://discuss.pytorch.org/t/fcn-resnet18-low-precision-on-sunrgbd-dataset/213193 "2024-11-20T09:38:34Z")

</div>

I am conducting an experiment, for the purposes of this experiment it is necessary for the resnet18 network to be accurate. The idea is to implement the network on the Jatson Nano microcontroller located on my mobile rob…

---

## [Why tensor.to convert fp32 to fp8\_e4m3=Nan if overflow](https://discuss.pytorch.org/t/why-tensor-to-convert-fp32-to-fp8-e4m3-nan-if-overflow/212648)

<div class="topic-metadata">

**Author:** [@symbolics](https://discuss.pytorch.org/u/symbolics)\
**Replies:** 2\
**Last updated:** [November 7, 2024, 11:14am UTC](https://discuss.pytorch.org/t/why-tensor-to-convert-fp32-to-fp8-e4m3-nan-if-overflow/212648 "2024-11-07T11:14:48Z")

</div>

1、source code: bit\_tensor = torch.tensor(\[0x7f7fffff, 0x7f800000, 0x7f800001\], dtype = torch.uint32) src\_tensor = bit\_tensor.view(torch.float32).clone().to(device) dst\_tensor = src\_tensor.to(torch.float8\_e4m3fn) 2、th…

---

## [Any operator is supported on fp8 tensor?](https://discuss.pytorch.org/t/any-operator-is-supported-on-fp8-tensor/212371)

<div class="topic-metadata">

**Author:** [@cokespace2](https://discuss.pytorch.org/u/cokespace2)\
**Replies:** 7\
**Last updated:** [November 5, 2024, 4:48pm UTC](https://discuss.pytorch.org/t/any-operator-is-supported-on-fp8-tensor/212371 "2024-11-05T16:48:48Z")

</div>

Since torch now supports fp8\_e5m2 and fp8\_e4m4fnz data type, we could convert our fp16 tensor to fp8 like: a = torch.randn(8, 16, dtype=torch.bfloat16, device='cuda') a\_f8 = a.to(torch.float8\_e5m2) but it seems like to…

---

## [Increased memory usage with AMP](https://discuss.pytorch.org/t/increased-memory-usage-with-amp/125486)

<div class="topic-metadata">

**Author:** [@serkansulun](https://discuss.pytorch.org/u/serkansulun)\
**Replies:** 6\
**Last updated:** [November 5, 2024, 9:10am UTC](https://discuss.pytorch.org/t/increased-memory-usage-with-amp/125486 "2024-11-05T09:10:28Z")

</div>

Hi. I’m benchmarking automatic mixed precision vs. default mode (float32). I’m getting a speed-up but, the memory usage is the same, if not higher. I’m running Pytorch’s tutorial with minimal change: import torch, time,…

---

## [Reseting loss value](https://discuss.pytorch.org/t/reseting-loss-value/211939)

<div class="topic-metadata">

**Author:** [@orben](https://discuss.pytorch.org/u/orben)\
**Replies:** 0\
**Last updated:** [October 22, 2024, 3:34pm UTC](https://discuss.pytorch.org/t/reseting-loss-value/211939 "2024-10-22T15:34:33Z")

</div>

Hey everyone, I’m experiencing some problems training a module and I’m not sure what’s causing it. It looks like whenever an epoch ends, the average loss resets to when the training began, almost like the module doesn’t …

---

## [FSDP MixedPrecision vs AMP autocast?](https://discuss.pytorch.org/t/fsdp-mixedprecision-vs-amp-autocast/211435)

<div class="topic-metadata">

**Author:** [@anonymous\_user\_83259](https://discuss.pytorch.org/u/anonymous_user_83259)\
**Replies:** 0\
**Last updated:** [October 11, 2024, 2:46pm UTC](https://discuss.pytorch.org/t/fsdp-mixedprecision-vs-amp-autocast/211435 "2024-10-11T14:46:53Z")

</div>

Given an arbitrary fp32 nn.Module that fits on a single GPU, is there a full enumeration of the differences between MixedPrecision(torch.bfloat16, torch.float32) torch.autocast(“cuda”, dtype=torch.bfloat16) in computa…

---

## [Custom CUDA kernels with AMP](https://discuss.pytorch.org/t/custom-cuda-kernels-with-amp/209979)

<div class="topic-metadata">

**Author:** [@Skylar\_Wurster](https://discuss.pytorch.org/u/Skylar_Wurster)\
**Replies:** 0\
**Last updated:** [September 23, 2024, 11:39pm UTC](https://discuss.pytorch.org/t/custom-cuda-kernels-with-amp/209979 "2024-09-23T23:39:12Z")

</div>

To speed up throughput of my NeRF-like model for 3D scientific data, I wrote some custom CUDA kernels for the encoding step (the decoding step is just a small MLP). This worked fine and dandy, improving my encoding thro…

[Next page](https://discuss.pytorch.org/c/mixed-precision/27.md?page=1)
