MCPcopy Create free account
hub / github.com/OpenGVLab/HumanBench / _half_helper

Function _half_helper

PATH/core/fp16/amp.py:104–128  ·  view source on GitHub ↗
(verbose=False)

Source from the content-addressed store, hash-verified

102 return self._verbose
103
104def _half_helper(verbose=False):
105 def _half_wrapper(self):
106 for module in self.children():
107 module.half()
108
109 if self.__class__ in _USER_FLOAT_MODULE:
110 if verbose:
111 print('Skip half convert for {}'.format(self.__class__))
112 return self
113
114 fn = lambda t: t.half() if t.is_floating_point() else t
115 for param in self._parameters.values():
116 if param is not None:
117 # Tensors stored in modules are graph leaves, and we don't
118 # want to create copy nodes, so we have to unpack the data.
119 param.data = fn(param.data)
120 if param._grad is not None:
121 param._grad.data = fn(param._grad.data)
122
123 for key, buf in self._buffers.items():
124 if buf is not None:
125 self._buffers[key] = fn(buf)
126
127 return self
128 return _half_wrapper
129
130def init(enable_caching=True, verbose=False):
131 global _DECORATOR_HANDLE

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected