# How to enable AMP

**URL:** <https://forums.developer.nvidia.com/t/how-to-enable-amp/183466>\
**Category:** Technical Support (PhysicsNeMo Only)\
**Tags:** tensorflow\
**Created:** [July 13, 2021, 3:49am UTC](https://forums.developer.nvidia.com/t/how-to-enable-amp/183466 "2021-07-13T03:49:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yokoi.toshiaki](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@yokoi.toshiaki](https://forums.developer.nvidia.com/u/yokoi.toshiaki)\
**Post date:** [July 13, 2021, 3:49am UTC](https://forums.developer.nvidia.com/t/how-to-enable-amp/183466/1 "2021-07-13T03:49:09Z")

</div>

Hello,

I would like to enable AMP to reduce the used memory and time in training simnet model.  
However it looks like not to work.  
Could you show me how to enable AMP?

Our Environment  
HW ; AWS EC2 g4dn.xlarge  
[Amazon EC2 G4 Instances — Amazon Web Services (AWS)](https://aws.amazon.com/ec2/instance-types/g4/?nc1=h_ls)  
SimNet Version 21.06(docker container)  
Example : helmholtz

Result(2 cases)

Case 1. without modifying code  
%python ./helmholtz.py --amp AMP  
…  
[0m: AdamOptimizer, /usr/local/lib/python3.8/dist-packages/simnet-21.6-py3.8.egg/simnet/optimizer.py  
beta1: 0.9  
beta2: 0.999  
epsilon: 1e-08  
amp: False  
…

- AMP is inactivate.

Case 2. with modify /simnet/build/lib/simnet/optimizer.py  
fix the default value of AMP True  
%vi /simnet/build/lib/simnet/optimizer.py  
…  
group.add\_argument(‘–amp’,  
help=‘use Automatic Mixed Precision (AMP)? (0/1)’,  
type=str2bool,  
default=True)  
#default=False)  
…  
%python ./helmholtz.py --amp AMP  
result was same as Case.1

Also in the both of case1 and 2 the training time was almost same as the case without --amp AMP option.

Thanks,  
Toshiaki Yokoi

---

<div class="post-metadata">

**Author:** ![mnabian](https://sea2.discourse-cdn.com/nvidia/user_avatar/forums.developer.nvidia.com/mnabian/32/14047_2.png) [@mnabian](https://forums.developer.nvidia.com/u/mnabian)\
**Post date:** [July 13, 2021, 4:31pm UTC](https://forums.developer.nvidia.com/t/how-to-enable-amp/183466/3 "2021-07-13T16:31:15Z")

</div>

Thanks for reporting this. This is a bug and will be fixed in the next release. For now you can activate AMP by changing the environment variable:

> export TF\_ENABLE\_AUTO\_MIXED\_PRECISION=1

Please note that there are known issues with AMP when used for second and higher-order derivatives, and with AMP your training loss may go to NaN/Inf. We are working on fixing this issue.

---

<div class="post-metadata">

**Author:** ![yokoi.toshiaki](https://developer.download.nvidia.com/images/forums/profile-default-devtalk-84.png) [@yokoi.toshiaki](https://forums.developer.nvidia.com/u/yokoi.toshiaki)\
**Post date:** [July 14, 2021, 12:23am UTC](https://forums.developer.nvidia.com/t/how-to-enable-amp/183466/4 "2021-07-14T00:23:25Z")

</div>

Hi,

Thank you for your reply.  
I’m trying that.

Thanks a lot,  
Toshiaki Yokoi
