Cast the parameters and buffers of Layer by the give device, dtype and blocking.
...
...
@@ -1619,6 +1671,8 @@ class Layer(object):
include_sublayers(bool|True, optional): If True, deal with self and all sublayers parameters and buffers, if not only deal with self parameters and buffers. Default: True.
floating_only(bool|False, optional): If True, only cast all floating point parameters and buffers of Layer by the give device, dtype and blocking.
Returns:
self
...
...
@@ -1646,54 +1700,9 @@ class Layer(object):
bool),"blocking value error, must be the True, False or None"
deftransform(t,device,dtype,blocking):
ifdeviceisNone:
device=t.place
ifdtypeisNone:
dtype=t.dtype
iftype(dtype)isnotVarDesc.VarType:
dtype=convert_np_dtype_to_dtype_(dtype)
# 1. gpu place need to determine whether the memory is sufficient for allocation:
ift.place.is_gpu_place():
# for gpu, minimum memory allocation unit is 256 bytes.
size_dtype=core.size_of_dtype(dtype)
# Note(zhangbo): Paddle GPU minimum memory allocation unit is 256 bytes, waiting_alloc_memory will comput ‘t’ occupied memory space.
# Coefficient 1.2 is used to avoid OOM that may occur in this critical state when the memory is just enough.