MCPcopy Create free account
hub / github.com/PaddlePaddle/Paddle / monkey_patch_value

Function monkey_patch_value

python/paddle/pir/math_op_patch.py:147–1732  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

145
146
147def monkey_patch_value():
148 def safe_get_dtype(var):
149 try:
150 dtype = var.dtype
151 except:
152 raise ValueError("Cannot get data type from var")
153 return dtype
154
155 def cpu(self):
156 """
157 In dy2static, Tensor also needs cpu() and cuda() interface.
158 But, the underneath operator has only forward op but not backward one.
159
160 Returns:
161 The tensor which has copied to cpu place.
162
163 Examples:
164 In Static Graph Mode:
165
166 .. code-block:: pycon
167
168 >>> import paddle
169 >>> paddle.enable_static()
170
171 >>> x = paddle.static.data(name="x", shape=[2, 2], dtype='float32')
172 >>> y = x.cpu()
173 """
174
175 # 0 means cpu place, see paddle/phi/kernels/memcpy_kernel.cc
176 return _C_ops.memcpy(self, 0)
177
178 def cuda(self, device_id=None, blocking=True):
179 """
180 In dy2static, Tensor also needs cpu() and cuda() interface.
181 But, the underneath operator has only forward op but not backward one.
182
183 Args:
184 self(Tensor): The variable itself.
185 device_id(int, optional): The destination GPU device id. Default: None, means current device.
186 We add this argument for dy2static translation, please do not use it.
187 blocking(bool, optional): Whether blocking or not, Default: True.
188 We add this argument for dy2static translation, please do not use it.
189
190 Returns:
191 The tensor which has copied to cuda place.
192
193 Examples:
194 In Static Graph Mode:
195
196 .. code-block:: pycon
197
198 >>> import paddle
199 >>> paddle.enable_static()
200
201 >>> x = paddle.static.data(name="x", shape=[2, 2], dtype='float32')
202 >>> y = x.cpu()
203 >>> z = y.cuda()
204 """

Callers 1

__init__.pyFile · 0.85

Calls 3

_binary_creator_Function · 0.70
extendMethod · 0.45

Tested by

no test coverage detected