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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file poliwrap-0.0.6.tar.gz.
File metadata
- Download URL: poliwrap-0.0.6.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d064fca2d1e4ef3369daf6e7d73ae52f2c86fc787e850915bfa26d124436371f
|
|
| MD5 |
248648f406f4c246e5cc232052de82bd
|
|
| BLAKE2b-256 |
0a4ff17bf1821363a0ff871c16cd4eff00205473dd7ccc332c1b4075a92a00ce
|
File details
Details for the file poliwrap-0.0.6-py3-none-any.whl.
File metadata
- Download URL: poliwrap-0.0.6-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
118100210c0bd4648bb4c72789cff8e66d02ae5c9741155c5736be9a87aafaa8
|
|
| MD5 |
052ada6cb746a5475d66ae1ceb5915a2
|
|
| BLAKE2b-256 |
639715c51f54ed4490c922c447251a13dab3fa412594a156d782d50d2e00fd1d
|