custom_policies.rst 1.2 KB

123456789101112131415161718192021222324252627
  1. Building Custom Policy Classes
  2. ------------------------------
  3. .. currentmodule:: ray.rllib
  4. .. warning::
  5. As of Ray >= 1.9, it is no longer recommended to use the ``build_policy_class()`` or
  6. ``build_tf_policy()`` utility functions for creating custom Policy sub-classes.
  7. Instead, follow the simple guidelines here for directly sub-classing from
  8. either one of the built-in types:
  9. :py:class:`~policy.eager_tf_policy_v2.EagerTFPolicyV2`
  10. or
  11. :py:class:`~policy.torch_policy_v2.TorchPolicyV2`
  12. In order to create a custom Policy, sub-class :py:class:`~policy.policy.Policy` (for a generic,
  13. framework-agnostic policy),
  14. :py:class:`~policy.torch_policy_v2.TorchPolicyV2`
  15. (for a PyTorch specific policy), or
  16. :py:class:`~policy.eager_tf_policy_v2.EagerTFPolicyV2`
  17. (for a TensorFlow specific policy) and override one or more of their methods. Those are in particular:
  18. * :py:meth:`~policy.policy.Policy.compute_actions_from_input_dict`
  19. * :py:meth:`~policy.policy.Policy.postprocess_trajectory`
  20. * :py:meth:`~policy.policy.Policy.loss`
  21. `See here for an example on how to override TorchPolicy <https://github.com/ray-project/ray/blob/master/rllib/algorithms/ppo/ppo_torch_policy.py>`_.