PokerRL Documentation

repository·master·Indexed 19 days ago

https://github.com/ericsteinberger/pokerrl

A framework for Multi-Agent Deep Reinforcement Learning applied to poker games. PokerRL supports sampling-based approaches such as Deep CFR and NFSP, and provides distributed computing capabilities via Ray. It includes tools for agent evaluation using metrics like Best Response (BR), Local Best Response (LBR), RL Best Response (RL-BR), and Head-To-Head (H2H), as well as support for vanilla CFR, CFR+, and Linear CFR in small games.

Tokens
1.3K
Snippets
2
Records
7
Agent score
18%

What's inside PokerRL

  1. Evaluate algorithms using PokerRL metrics

    master

    PokerRL provides four primary metrics for evaluating the performance of poker algorithms:

    1. Best Response (BR): Computes the exact exploitability (intended for small games).
    2. Local Best Response (LBR): Approximates a lower bound of BR; optimized for distributed computing in large games.
    3. RL Best Response (RL-BR): Approximates BR by training a DDQN against the AI.
    4. Head-To-Head (H2H): Measures performance by letting two modes of an agent play against each other.

    For small games, unoptimized implementations of vanilla CFR, CFR+, and Linear CFR are also available and can be run like Deep RL agents, with results plotted to TensorBoard.

  2. Configure Distributed and Cluster modes

    master

    PokerRL uses ray to support scaling from local execution to distributed clusters. You can switch between these modes by changing a boolean flag in your TrainingProfile.

    • Distributed Mode: Runs many worker processes on a single machine with many cores.
    • Cluster Mode: Runs many workers across many different machines.

    To use Cluster mode, you must provide a Ray cluster specification file (.yaml) and have your AWS account configured.

  3. How the PokerRL framework components work together

    master

    PokerRL is a framework for Multi-Agent Deep Reinforcement Learning in poker games. The architecture is built around several key abstractions:

    • Workers: Agents that interact with each other to perform training.
    • TrainingProfile: An instance (found in .../rl/base_cls/TrainingProfileBase) used to pass arguments for a training run.
    • EvalAgent: A wrapper for a trained agent (found in .../rl/base_cls/EvalAgentBase).
    • AgentTournament: A component used to have multiple EvalAgent instances battle each other.
    • InteractiveGame: A component used to play against humans (found in .../game/InteractiveGame).

    While the game engine and agent modules support $N > 1$ players, some specific parts of the framework are optimized for 2-player games. Local workers can be wrapped with approximately 4 lines of code to function as independent distributed workers.

  4. Verify PokerRL installation

    master

    You can verify your installation by running the built-in unit tests or by running the provided examples.

    Run Unit Tests:

    python -m unittest discover PokerRL/test

    Run Interactive/Training Examples:

    • Play poker against yourself: examples/interactive_user_v_user.py
    • Train a CFR+ agent in a small game: examples/run_cfrp_example.py
  5. Install PokerRL locally

    master

    To install PokerRL on your local machine, ensure you have Anaconda/Miniconda and Docker installed.

    Note: For distributed runs, you must use Linux and install the distributed extra: pip install PokerRL[distributed]. This is not required for local-only usage.

    Follow these steps to set up a Python 3.6 environment with PyTorch:

    # Create and activate environment
    conda create -n CHOOSE_A_NAME python=3.6 -y
    source activate THE_NAME_YOU_CHOSE
    
    # Install dependencies
    pip install requests
    conda install pytorch=0.4.1 -c pytorch
    pip install PokerRL
  6. Set up PyCrayon for TensorBoard visualization

    master

    PokerRL uses PyCrayon (a wrapper around Tensorboard) for logging. To set up the log server, use Docker to run the alband/crayon image:

    ```bash
    docker run -d -p 8888:8888 -p 8889:8889 --name crayon alband/crayon
    docker start crayon

    After running these commands, you can access Tensorboard in your browser at localhost:8888.

  7. Deploy PokerRL on an AWS instance

    master

    To deploy on AWS (specifically Amazon Linux 2), follow these steps:

    1. Security Group: Add a custom TCP rule for port 8888 to allow access to Tensorboard from your IP.
    2. Environment Setup: Run the following commands on the instance to install system dependencies, Docker, Miniconda, and PokerRL with distributed support:
    sudo yum update -y
    sudo yum install git gcc g++ polkit -y
    sudo amazon-linux-extras install docker -y
    sudo service docker start
    sudo docker pull alband/crayon 
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    bash Miniconda3-latest-Linux-x86_64.sh -b -p /home/ec2-user/miniconda
    export PATH=/home/ec2-user/miniconda/bin:$PATH
    conda create -n PokerAI python=3.6 -y
    source activate PokerAI
    pip install requests
    conda install pytorch=0.4.1 -c pytorch -y
    pip install PokerRL[distributed]
    1. Running the Application: When starting a new instance from an AMI, ensure you set OMP_NUM_THREADS=1 to avoid a PyTorch 0.4.1 bug, and start the Crayon container:
    sudo service docker start
    sudo docker inspect -f {{.State.Running}} crayon || sudo docker run -d -p 8888:8888 -p 8889:8889 --name crayon alband/crayon
    sudo docker start crayon
    
    screen
    export OMP_NUM_THREADS=1
    export PATH=/home/ec2-user/miniconda/bin:$PATH
    source activate PokerAI
    1. Accessing Logs: View results in your browser at AWS_INSTANCE_PUBLIC_IP:8888.