rllib-dev.rst 4.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. Contributing to RLlib
  2. =====================
  3. Development Install
  4. -------------------
  5. You can develop RLlib locally without needing to compile Ray by using the `setup-dev.py <https://github.com/ray-project/ray/blob/master/python/ray/setup-dev.py>`__ script. This sets up links between the ``rllib`` dir in your git repo and the one bundled with the ``ray`` package. However if you have installed ray from source using [these instructions](https://docs.ray.io/en/master/installation.html) then do not this as these steps should have already created this symlink. When using this script, make sure that your git branch is in sync with the installed Ray binaries (i.e., you are up-to-date on `master <https://github.com/ray-project/ray>`__ and have the latest `wheel <https://docs.ray.io/en/master/installation.html>`__ installed.)
  6. API Stability
  7. -------------
  8. Objects and methods annotated with ``@PublicAPI`` or ``@DeveloperAPI`` have the following API compatibility guarantees:
  9. .. autofunction:: ray.rllib.utils.annotations.PublicAPI
  10. .. autofunction:: ray.rllib.utils.annotations.DeveloperAPI
  11. Features
  12. --------
  13. Feature development, discussion, and upcoming priorities are tracked on the `GitHub issues page <https://github.com/ray-project/ray/issues>`__ (note that this may not include all development efforts).
  14. Benchmarks
  15. ----------
  16. A number of training run results are available in the `rl-experiments repo <https://github.com/ray-project/rl-experiments>`__, and there is also a list of working hyperparameter configurations in `tuned_examples <https://github.com/ray-project/ray/tree/master/rllib/tuned_examples>`__, sorted by algorithm. Benchmark results are extremely valuable to the community, so if you happen to have results that may be of interest, consider making a pull request to either repo.
  17. Contributing Algorithms
  18. -----------------------
  19. These are the guidelines for merging new algorithms into RLlib:
  20. * Contributed algorithms (`rllib/contrib <https://github.com/ray-project/ray/tree/master/rllib/contrib>`__):
  21. - must subclass Trainer and implement the ``step()`` method
  22. - must include a lightweight test (`example <https://github.com/ray-project/ray/blob/6bb110393008c9800177490688c6ed38b2da52a9/test/jenkins_tests/run_multi_node_tests.sh#L45>`__) to ensure the algorithm runs
  23. - should include tuned hyperparameter examples and documentation
  24. - should offer functionality not present in existing algorithms
  25. * Fully integrated algorithms (`rllib/agents <https://github.com/ray-project/ray/tree/master/rllib/agents>`__) have the following additional requirements:
  26. - must fully implement the Trainer API
  27. - must offer substantial new functionality not possible to add to other algorithms
  28. - should support custom models and preprocessors
  29. - should use RLlib abstractions and support distributed execution
  30. Both integrated and contributed algorithms ship with the ``ray`` PyPI package, and are tested as part of Ray's automated tests. The main difference between contributed and fully integrated algorithms is that the latter will be maintained by the Ray team to a much greater extent with respect to bugs and integration with RLlib features.
  31. How to add an algorithm to ``contrib``
  32. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. It takes just two changes to add an algorithm to `contrib <https://github.com/ray-project/ray/tree/master/rllib/contrib>`__. A minimal example can be found `here <https://github.com/ray-project/ray/tree/master/rllib/contrib/random_agent/random_agent.py>`__. First, subclass `Trainer <https://github.com/ray-project/ray/tree/master/rllib/agents/agent.py>`__ and implement the ``_init`` and ``step`` methods:
  34. .. literalinclude:: ../../rllib/contrib/random_agent/random_agent.py
  35. :language: python
  36. :start-after: __sphinx_doc_begin__
  37. :end-before: __sphinx_doc_end__
  38. Second, register the trainer with a name in `contrib/registry.py <https://github.com/ray-project/ray/blob/master/rllib/contrib/registry.py>`__.
  39. .. code-block:: python
  40. def _import_random_agent():
  41. from ray.rllib.contrib.random_agent.random_agent import RandomAgent
  42. return RandomAgent
  43. def _import_random_agent_2():
  44. from ray.rllib.contrib.random_agent_2.random_agent_2 import RandomAgent2
  45. return RandomAgent2
  46. CONTRIBUTED_ALGORITHMS = {
  47. "contrib/RandomAgent": _import_random_trainer,
  48. "contrib/RandomAgent2": _import_random_trainer_2,
  49. # ...
  50. }
  51. After registration, you can run and visualize training progress using ``rllib train``:
  52. .. code-block:: bash
  53. rllib train --run=contrib/RandomAgent --env=CartPole-v0
  54. tensorboard --logdir=~/ray_results