WestronglyencouragemovingtothenewAmpAPI,becauseit's more versatile, easier to use, and future proof. The original :class:`FP16_Optimizer` and the old "Amp" API are deprecated, and subject to removal at at any time.
WestronglyencouragemovingtothenewAmpAPI,becauseit's more versatile, easier to use, and future proof. The original :class:`FP16_Optimizer` and the old "Amp" API are deprecated, and subject to removal at at any time.
...
@@ -77,6 +95,7 @@ The functions formerly exposed through ``amp_handle`` are now free
...
@@ -77,6 +95,7 @@ The functions formerly exposed through ``amp_handle`` are now free
functions accessible through the ``amp`` module.
functions accessible through the ``amp`` module.
The backward context manager must be changed accordingly::
The backward context manager must be changed accordingly::
# old API
# old API
with amp_handle.scale_loss(loss, optimizer) as scaled_loss:
with amp_handle.scale_loss(loss, optimizer) as scaled_loss:
scaled_loss.backward()
scaled_loss.backward()
...
@@ -96,6 +115,7 @@ with a particular precision are still honored by the new API.
...
@@ -96,6 +115,7 @@ with a particular precision are still honored by the new API.
``opt-level O2`` is equivalent to :class:`FP16_Optimizer` with ``dynamic_loss_scale=True``.
``opt-level O2`` is equivalent to :class:`FP16_Optimizer` with ``dynamic_loss_scale=True``.
Once again, the backward pass must be changed to the unified version::
Once again, the backward pass must be changed to the unified version::
optimizer.backward(loss)
optimizer.backward(loss)
->
->
with amp.scale_loss(loss, optimizer) as scaled_loss:
with amp.scale_loss(loss, optimizer) as scaled_loss:
...
@@ -108,11 +128,11 @@ necessary in the new API. No matter what --opt-level
...
@@ -108,11 +128,11 @@ necessary in the new API. No matter what --opt-level
you choose, you can and should simply build your model in the default FP32 format.** The new Amp
you choose, you can and should simply build your model in the default FP32 format.** The new Amp
API will perform the right conversions during
API will perform the right conversions during
``model, optimizer = amp.initialize(model, optimizer, opt_level=....)`` based on the ``--opt-level``
``model, optimizer = amp.initialize(model, optimizer, opt_level=....)`` based on the ``--opt-level``
and any overridden flags. Floating point input data may be float or half, but you may as well just
and any overridden flags. Floating point input data may be FP32 or FP16, but you may as well just
let it be float, because the ``model`` returned by ``amp.initialize`` will have its ``forward``
let it be FP16, because the ``model`` returned by ``amp.initialize`` will have its ``forward``
method patched to cast the input data appropriately.
method patched to cast the input data appropriately.
.. note::
.. note::
Aside from the call to ``amp.initialize`` itself, it'snevernecessarytomanuallycast
Aside from the call to ``amp.initialize`` itself, it'snevernecessarytomanuallycast