A with guard to set :code:`Optimization` :code:`OpRole` and :code:`OpRoleVar` automatically. Notes: This is a very low level API. Users should not use it directly. Args: param_and_grads(list): The variables (names) to be optimized. Examples:
(self, param_and_grads)
| 6340 | |
| 6341 | @signature_safe_contextmanager |
| 6342 | def _optimized_guard(self, param_and_grads): |
| 6343 | """ |
| 6344 | A with guard to set :code:`Optimization` :code:`OpRole` and |
| 6345 | :code:`OpRoleVar` automatically. |
| 6346 | |
| 6347 | Notes: This is a very low level API. Users should not use it directly. |
| 6348 | |
| 6349 | Args: |
| 6350 | param_and_grads(list): The variables (names) to be optimized. |
| 6351 | |
| 6352 | Examples: |
| 6353 | .. code-block:: pycon |
| 6354 | |
| 6355 | >>> import paddle.base as base |
| 6356 | >>> p, g = backward(...) |
| 6357 | >>> with program._optimized_guard([p,g]): |
| 6358 | >>> p = p - 0.001 * g |
| 6359 | """ |
| 6360 | tmp_role = self._current_role |
| 6361 | tmp_var = self.__op_role_var |
| 6362 | |
| 6363 | OpRole = core.op_proto_and_checker_maker.OpRole |
| 6364 | self._current_role = OpRole.Optimize |
| 6365 | self.__op_role_var = [ |
| 6366 | var.name if isinstance(var, Variable) else var |
| 6367 | for var in param_and_grads |
| 6368 | ] |
| 6369 | try: |
| 6370 | yield |
| 6371 | finally: |
| 6372 | self.__op_role_var = tmp_var |
| 6373 | self._current_role = tmp_role |
| 6374 | |
| 6375 | @signature_safe_contextmanager |
| 6376 | def _lr_schedule_guard(self, is_with_opt=False): |
no outgoing calls
no test coverage detected