Skip to content

Commit

Permalink
feature: add new website
Browse files Browse the repository at this point in the history
  • Loading branch information
Mistobaan committed Feb 4, 2023
1 parent 6427429 commit 9af30de
Show file tree
Hide file tree
Showing 60 changed files with 718 additions and 629 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: docs_pages_workflow

on: [pull_request]

permissions:
pull-requests: write

jobs:
build_docs_job:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.8

- name: Get pip cache dir
id: pip-cache
run: |
python -m pip install --upgrade pip
echo "dir={$(pip cache dir)}" >> $GITHUB_OUTPUT
- name: pip cache
uses: actions/cache@v3
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/setup.py', '**/requirements.txt', '**/docs/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install docs requirements
run: |
python -m pip install -r docs/requirements.txt
- name: make the sphinx docs
run: |
make -C docs clean
make -C docs html
- uses: readthedocs/actions/preview@v1
with:
project-slug: "trlx"
project-language: "en"
# see: https://github.com/readthedocs/actions/tree/main/preview
# message-template (optional): Text message to be injected by the action in the Pull Request description. It supports the following placeholders to be replaced:
# {docs-pr-index-url}: URL to the root of the documentation for the Pull Request preview.
# platform (optional): Read the Docs Community (community) or Read the Docs for Business (business). (default: community)
# single-version (optional): Set this to 'true' if your project is single version, so we can link to the correct URL. (default: 'false')
21 changes: 14 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-case-conflict
Expand All @@ -18,17 +18,24 @@ repos:
args: [--fix=lf]
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
- id: black
files: ^(trlx|examples|tests|setup.py)/
- repo: https://github.com/pycqa/isort
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
- id: isort
name: isort (python)
- repo: https://github.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
- id: flake8
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
hooks:
- id: codespell
args: [--ignore-words, dictionary.txt]
additional_dependencies:
- tomli
22 changes: 19 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
# .readthedocs.yml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

build:
os: "ubuntu-20.04"
tools:
python: "3.8"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/source/conf.py
configuration: docs/conf.py
fail_on_warning: false

# Optionally build your docs in additional formats such as PDF and ePub
formats:
- htmlzip

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.9
install:
- requirements: docs/requirements.txt
- requirements: docs/requirements.txt
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Change log

Best viewed on [trlx.readthedocs.io](https://trlx.readthedocs.io/en/latest/changelog.html).

<!--
Remember to align the itemized text with the first line of an item within a list.
-->

## trlx 0.4.0 (2022-12-05)

- python 3.8
65 changes: 56 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

Looking to improve `trlX`? Thanks for considering!

There are many ways to contribute, from writing tutorials in [Colab notebooks](https://colab.research.google.com) to improving the project's [documentation](https://trlx.readthedocs.io), submitting bug reports and feature requests, or even implementing new features themselves. See the outstanding [issues](https://github.com/CarperAI/trlx/issues) for ideas on where to begin.
There are many ways to contribute, from writing tutorials in [Colab notebooks](https://colab.research.google.com) to improving the project's [documentation](https://trlx.readthedocs.io), to submitting bug reports and feature requests, or even implementing new features themselves. See the outstanding [issues](https://github.com/CarperAI/trlx/issues) for ideas on where to begin.

- [Documentation Issues](https://github.com/CarperAI/trlx/issues?q=is%3Aissue+is%3Aopen+label%3Adocumentation)
- [Bug Fixes](https://github.com/CarperAI/trlx/issues?q=is%3Aissue+is%3Aopen+label%3Abug)
- [Feature Requests](https://github.com/CarperAI/trlx/issues?q=is%3Aissue+is%3Aopen+label%3A%22feature+request%22)

Here are some guidelines to help you get started 🚀.

Expand All @@ -16,40 +20,83 @@ To submit a bug report or a feature request, please open an [issue](https://gith
Follow these steps to start contributing code:

1. Setup your environment:

```bash
conda create -n trlx python=3.8 torch torch-cuda=11.7 -c pytorch -c nvidia
git clone https://github.com/CarperAI/trlx
cd trlx
pip install -e ".[dev]"
pre-commit install
```

1. Create your own [fork](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository) of the repository and clone it to your local machine.

```bash
git clone https://github.com/<YOUR-USERNAME>/trlx.git
cd trlx
git remote add upstream https://github.com/CarperAI/trlx.git
```
2. Create a new branch for your changes and give it a concise name that reflects your contribution.

1. Create a new branch for your changes and give it a concise name that reflects your contribution.

```bash
git checkout -b <BRANCH-NAME>
```
2. Install the development dependencies in a Python environment.

1. Install the development dependencies in a Python environment.

```bash
pip install -e ".[dev]"
pre-commit install
```
4. Implement your changes. Make small, independent, and well documented commits along the way (check out [these](https://cbea.ms/git-commit/) tips).
5. Add unit tests whenever appropriate and ensure that the tests pass. To run the entire test suite, use the following command from within the project root directory.

install pre-commit

```bash
pip install pre-commit
pre-commit install
```

bonus: force run pre-commit on all the files

```bash
pre-commit run --all-files
```

1. Implement your changes. Make small, independent, and well documented commits along the way (check out [these](https://cbea.ms/git-commit/) tips).

1. Add unit tests whenever appropriate and ensure that the tests pass. To run the entire test suite, use the following command from within the project root directory.

```bash
pytest
```

For changes with minimal project scope (e.g. a simple bug fix), you might want to run the unit tests for just a specific test file instead:

```bash
pytest -vv -k "<TEST-FILE-NAME>"
```
5. Commit your final changes. Our `pre-commit` hooks will automatically run before each commit and will prevent you from committing code that does not pass our style and linter checks. They'll also automatically format your code! To run these manually, use the following command:

1. Commit your final changes. Our `pre-commit` hooks will automatically run before each commit and will prevent you from committing code that does not pass our style and linter checks. They'll also automatically format your code! To run these manually, use the following command:
```bash
pre-commit run --all-files
```
6. Push the changes to your fork.
1. Push the changes to your fork.
Finally ... 🥁 ... Create a [pull request](https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request) to the `trlX` repository! Make sure to include a description of your changes and link to any relevant issues.
> __Tip__: If you're looking to introduce an experimental feature, we suggest testing the behavior of your proposed feature on some of the existing [examples](https://github.com/CarperAI/trlx/tree/master/examples), such as [random walks](https://github.com/CarperAI/trlx/blob/master/examples/randomwalks). This will help you get a better sense of how the feature would work in practice and will also help you identify any potential flaws in the implementation.
> **Tip**: If you're looking to introduce an experimental feature, we suggest testing the behavior of your proposed feature on some of the existing [examples](https://github.com/CarperAI/trlx/tree/master/examples), such as [random walks](https://github.com/CarperAI/trlx/blob/master/examples/randomwalks). This will help you get a better sense of how the feature would work in practice and will also help you identify any potential flaws in the implementation.

## Tips & Tricks

Set transformers verbosity level

```bash
TRANSFORMERS_VERBOSITY=error
```

## Asking questions

Expand All @@ -63,4 +110,4 @@ This project adheres to the [Contributor Covenant Code of Conduct](https://githu

By contributing, you agree that your contributions will be licensed under its MIT License.

# Thank you for your contribution 🐠!
## Thank you for your contribution! 🐠
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
gendoc:
docker build -t trlxgendocs -f docker/docs/Dockerfile .
run:
docker run --rm -it -v ${PWD}:/build \
--entrypoint /bin/bash \
trlxgendocs
54 changes: 14 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![TRLX](./docs/_static/apple-touch-icon-114x114.png)

[docs-image]: https://readthedocs.org/projects/trlX/badge/?version=latest
[docs-url]: https://trlX.readthedocs.io/en/latest/?badge=latest

Expand All @@ -12,6 +14,7 @@ You can read more about trlX in our [documentation](https://trlX.readthedocs.io)
Want to collect human annotations for your RL application? Check out [CHEESE!](https://github.com/carperai/cheese), our library for HiTL data collection.

## Installation

```bash
git clone https://github.com/CarperAI/trlx.git
cd trlx
Expand All @@ -28,23 +31,29 @@ For more usage see [examples](./examples). You can also try the colab notebooks


## How to Train

You can train a model using a reward function or a reward-labeled dataset.

#### Using a reward function
### Using a reward function

```python
trainer = trlx.train('gpt2', reward_fn=lambda samples, **kwargs: [sample.count('cats') for sample in samples])
```
#### Using a reward-labeled dataset

### Using a reward-labeled dataset

```python
trainer = trlx.train('EleutherAI/gpt-j-6B', dataset=[('dolphins', 'geese'), (1.0, 100.0)])
```

#### Trainers provide a wrapper over their underlying model
### Trainers provide a wrapper over their underlying model

```python
trainer.generate(**tokenizer('Q: Who rules the world? A:', return_tensors='pt'), do_sample=True)
```

#### Save the resulting model to a Hugging Face pretrained language model. (Ready to upload to the Hub!)
### Save the resulting model to a Hugging Face pretrained language model. (Ready to upload to the Hub!)

```python
trainer.save_pretrained('/path/to/output/folder/')
```
Expand All @@ -69,46 +78,11 @@ python examples/nemo_ilql_sentiments.py
For more usage see the [NeMo README](./trlx/trainer/nemo)

#### Use Ray Tune to launch hyperparameter sweep

```bash
python -m trlx.sweep --config configs/sweeps/ppo_sweep.yml examples/ppo_sentiments.py
```

## Logging

trlX uses the standard Python `logging` library to log training information to the console. The default logger is set to the `INFO` level, which means that `INFO`, `WARNING`, `ERROR`, and `CRITICAL` level messages will be printed to standard output.

To change the log level directly, you can use the verbosity setter. For example, to set the log level to `WARNING` use:

```python
import trlx

trlx.logging.set_verbosity(trlx.logging.WARNING)
```

This will suppress `INFO` level messages, but still print `WARNING`, `ERROR`, and `CRITICAL` level messages.

You can also control logging verbosity by setting the `TRLX_VERBOSITY` environment variable to one of the standard logging [level names](https://docs.python.org/3/library/logging.html#logging-levels):

* `CRITICAL` (`trlx.logging.CRITICAL`)
* `ERROR` (`trlx.logging.ERROR`)
* `WARNING` (`trlx.logging.WARNING`)
* `INFO` (`trlx.logging.INFO`)
* `DEBUG` (`trlx.logging.DEBUG`)

```sh
export TRLX_VERBOSITY=WARNING
```

By default, [`tqdm`](https://tqdm.github.io/docs/tqdm/) progress bars are used to display training progress. You can disable them by calling `trlx.logging.disable_progress_bar()`, otherwise `trlx.logging.enable_progress_bar()` to enable.

Messages can be formatted with greater detail by setting `trlx.logging.enable_explicit_format()`. This will inject call-site information into each log which may be helpful for debugging.

```sh
[2023-01-01 05:00:00,000] [INFO] [ppo_orchestrator.py:63:make_experience] [RANK 0] Message...
```

> 💡 Tip: To reduce the amount of logging output, you might find it helpful to change log levels of third-party libraries used by trlX. For example, try adding `transformers.logging.set_verbosity_error()` to the top of your trlX scripts to silence verbose messages from the `transformers` library (see their [logging docs](https://huggingface.co/docs/transformers/main_classes/logging#logging) for more details).
## Contributing

For development check out these [guidelines](./CONTRIBUTING.md)
Expand Down
1 change: 1 addition & 0 deletions dictionary.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rouge
13 changes: 13 additions & 0 deletions docker/docs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.8-slim

# pip install -r docs/requirements.txt
# sphinx-build -b html docs docs/build/html -j auto
# sphinx-build -b html -D nb_execution_mode=off docs docs/build/html -j auto

RUN python -m pip install --upgrade --no-cache-dir pip
ADD docs/requirements.txt /tmp/requirements.txt
RUN python -m pip install --exists-action=w --no-cache-dir -r /tmp/requirements.txt
RUN mkdir /build
WORKDIR /build/docs/
ENTRYPOINT /build/docs/build.sh
# RUN `which sphinx-build` -T -E -b html -d _build/doctrees-readthedocs -D language=en . _build/html
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
SOURCEDIR = .
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
Expand Down
5 changes: 5 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# How To build the documentation

```bash
make -c docs html
```
Binary file added docs/_static/apple-touch-icon-114x114.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-120x120.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-144x144.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-152x152.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-167x167.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-180x180.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-57x57.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-60x60.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-72x72.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/apple-touch-icon-76x76.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/favicon-128x128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/favicon-196x196.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/favicon-96x96.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9af30de

Please sign in to comment.