Skip to content
Advertisement

Why tensor size was not changed?

I made the toy CNN model.

JavaScript

Then, I had checked model.summary via this code

JavaScript

And I was able to get the following results:

JavaScript

I want to reduce model size cuz i wanna increase the batch size.
So, I had changed torch.float32 -> torch.float16 via NVIDIA/apex

JavaScript
JavaScript

As a result, torch.dtype was changed torch.float16 from torch.float32.
But, Param size (MB): 35.19 was not changed.

Why happen this? plz tell me about this.
Thanks.

Advertisement

Answer

Mixed precision does not mean that your model becomes half original size. The parameters remain in float32 dtype by default and they are cast to float16 automatically during certain operations of the neural network training. This is applicable to input data as well.

The torch.cuda.amp provides the functionality to perform this automatic conversion from float32 to float16 during certain operations of training like Convolutions. Your model size will remain the same. Reducing model size is called quantization and it is different than mixed-precision training.

You can read to more about mixed-precision training at NVIDIA’s blog and Pytorch’s blog.

Advertisement