Skip to main content

A lightweight, framework-agnostic abstraction for reinforcement learning policy inference.

Project description

PoliWrap

A lightweight, framework-agnostic wrapper for reinforcement learning policy inference.

Installation

pip install poliwrap            # core only (numpy)
pip install poliwrap[onnx]      # + ONNX Runtime backend (CPU)
pip install poliwrap[onnx-gpu]  # + ONNX Runtime backend (CUDA)
pip install poliwrap[torch]     # + PyTorch backend
pip install poliwrap[all]       # all backends (CPU ONNX)

Each wrapper is importable only when its backend is installed.

Usage

ONNX

from poliwrap import ONNXPolicyWrapper

policy = ONNXPolicyWrapper("policy.onnx")
actions = policy({"actor_obs": obs})  # obs: dict[str, np.ndarray]

PyTorch

from poliwrap import PytorchPolicyWrapper

policy = PytorchPolicyWrapper("policy.pt")
actions = policy({"actor_obs": obs})  # obs: dict[str, torch.Tensor]

Extending

All wrappers subclass PolicyWrapper. To support a new backend, implement _load_model and __call__:

from poliwrap import PolicyWrapper


class MyPolicyWrapper(PolicyWrapper):
    def _load_model(self) -> None:
        self.model = ...  # load from self.model_path

    def __call__(self, observations):
        return self.model(observations)

PolicyWrapper also has overridable preprocess_observations, postprocess_actions, and reset hooks for input/output transforms and stateful (e.g. RNN) policies.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

poliwrap-0.0.7.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

poliwrap-0.0.7-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file poliwrap-0.0.7.tar.gz.

File metadata

  • Download URL: poliwrap-0.0.7.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for poliwrap-0.0.7.tar.gz
Algorithm Hash digest
SHA256 349ca6e84ad3fac8cb29e5de1f4343c577df5aba2a6680e0caf759621e167205
MD5 14c4dd240f3432730cf37964ed03b009
BLAKE2b-256 0fb21b92e0905176e5ac0861d6925c6b908b1201483dee3fb9304f4cde65f3c6

See more details on using hashes here.

File details

Details for the file poliwrap-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: poliwrap-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for poliwrap-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 bdc984ceedb35d6918a3b61b75a3df504b612f7d73f618c3bc1f6937900ea673
MD5 63cabc216d4305381454fd4ae2da20f7
BLAKE2b-256 638d52fcfbea8b5deb26393f8516991bdc4e8cbdba614c62123925a1d0cc7fc3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page