Indicating if we stop gradient from current Variable **Notes: This Property has default value as** ``True`` **in** Dygraph **mode, while Parameter's default value is False. However, in Static Graph Mode all Variable's default stop_gradient value is** ``False`` Examples:
(self)
| 2299 | |
| 2300 | @property |
| 2301 | def stop_gradient(self): |
| 2302 | """ |
| 2303 | Indicating if we stop gradient from current Variable |
| 2304 | |
| 2305 | **Notes: This Property has default value as** ``True`` **in** Dygraph **mode, while Parameter's default value is False. However, in Static Graph Mode all Variable's default stop_gradient value is** ``False`` |
| 2306 | |
| 2307 | Examples: |
| 2308 | .. code-block:: pycon |
| 2309 | |
| 2310 | >>> import paddle |
| 2311 | >>> import paddle.base as base |
| 2312 | >>> import numpy as np |
| 2313 | |
| 2314 | >>> with base.dygraph.guard(): |
| 2315 | ... value0 = np.arange(26).reshape(2, 13).astype("float32") |
| 2316 | ... value1 = np.arange(6).reshape(2, 3).astype("float32") |
| 2317 | ... value2 = np.arange(10).reshape(2, 5).astype("float32") |
| 2318 | ... linear = paddle.nn.Linear(13, 5) |
| 2319 | ... linear2 = paddle.nn.Linear(3, 3) |
| 2320 | ... a = paddle.to_tensor(value0) |
| 2321 | ... b = paddle.to_tensor(value1) |
| 2322 | ... c = paddle.to_tensor(value2) |
| 2323 | ... out1 = linear(a) |
| 2324 | ... out2 = linear2(b) |
| 2325 | ... out1.stop_gradient = True |
| 2326 | ... out = paddle.concat(x=[out1, out2, c], axis=1) |
| 2327 | ... out.backward() |
| 2328 | ... assert linear.weight.gradient() is None |
| 2329 | ... assert out1.gradient() is None |
| 2330 | """ |
| 2331 | return self.desc.stop_gradient() |
| 2332 | |
| 2333 | @stop_gradient.setter |
| 2334 | def stop_gradient(self, s): |
no test coverage detected