Code Monkey home page Code Monkey logo

rllib-fast-serve's Introduction

tests

rllib-fast-serve

Tools and examples to export policies trained with Ray RLlib for lightweight and fast inference.

Only tensorflow supported for now, but adding support for pytorch should be fairly easy.

Usage

python3 -m venv env
source env/bin/activate
pip install -r requirements.txt

Notes on dependencies:

  • ray, tensorflow and tf2onnx aren't desired for inference (only needed for phase 1). If you build an inference tool/server, make sure to pull them out!
  • ray and tensorflow versions depend on the ones you used for training.
  • numpy version must align with requirements of tensorflow and onnx. If you need to change it, check their respective compatibility matrix

Phase 1: transform

This will transform an input RLlib checkpoint to several artifacts needed for inference.

python3 src/rllib2onnx.py --alg PPO --checkpoint-file /tmp/my_training/checkpoint-1

rllib2onnx can also reload training config from .pkl, assuming that it's located in checkpoint directory. See code for usage.

Output listing:

  • a TF saved model (.pb).
  • an ONNX model (.onnx)
  • a json containing input and output nodes structure of the model graph.
  • a json containing observations filters definition (needed to standardize observations if you used MeanStdFilter during training).

Example output directory structure:

/tmp/model_export/
├── filters
│   └── filters.json
├── graph_io
│   └── graph_io.json
├── onnx
│   └── saved_model.onnx
└── tf
    ├── events.out.tfevents.1657097632.work
    ├── saved_model.pb
    └── variables
        ├── variables.data-00000-of-00001
        └── variables.index

Phase 2: serve

Run model inference using ONNX model

python3 src/infer.py \
  --onnx-model /tmp/model_export/onnx/saved_model.onnx \
  --filters /tmp/model_export/filters/filters.json \
  --graph-io /tmp/model_export/graph_io/graph_io.json \
  --obs "[1, 2, 3]"

Example output:

{'default_policy': [array([[14, 33]], dtype=int64)]}

rllib-fast-serve's People

Contributors

antoine-galataud avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.