Skip to main content

Flexibuff is a minimalistic library designed to store replay buffers and episode rollouts for multi agent RL, but it works just as well for single agent RL.

Motivation

Flexibuff came to be due to frustrations with integrating many kinds of RL models on the same environment for benchmark purposes. Some models like DeepQ learning only require [state,state_,action,reward,terminated] where transitions can be sampled in any order off policy. Other algorithms like vanilla policy gradient require memory rollouts in chronilogical order to calculate the discounted rewards G. Other algorithms still such as QMIX and other CTDE methods require many agent buffers to be sampled synchronously, meaning that the same timestep is needed for each agent to perform mixing. More exotic still, some RL algorithms such as TAMER maintain a second reward signal which comes from human preference. Some models also have mixed action spaces or multiple outputs at the same time such as a search and rescue robot which must operate a radio and navigate itself at the same time. Lastly, some policy gradient algorithms require log probabilities to be stored where DeepQ does not, but any of the algorithms above might use memory weighting to bias transition sampling or other effects.

Comparing these methods to each other and programming memory buffers for each kind of agent takes a lot of time and code and it introduces yet another step of the process where there could be errors and precious debugging time. Flexibuff claims to fit every one of these use cases at one time with optional storage for human rewards, log probabilities, memory weights, and more. Additionally, Flexibuff can sample either transitions or entire chronologically ordered episodes synchronized to all agents with samples returned as either numpy arrays or torch tensors.

Bare bones documentation (WIP)

Flexible Buffer supports numpy and torch tensor outputs formats, but all memories are held internally as numpy buffers because Torch.from_numpy() will share the same memory either way in RAM

Flexible Buffer stores the memories of multiple 'n_agents' agents in their own separate memory blocks where each agent has 'num_steps' storage capacity. Setting 'n_agents' to 1 will remove a dimension from the returned buffer results for single agent tasks.

cardinal supports both continuous and discrete actions at the same time along and it can sample episodes for use in recurrent training or policy gradient methods using recorded discounted episodic rewards, 'G'. cardinal can also store action masks for environments with illegal actions and a second reward signal called 'global_auxiliary_reward' for simultaneous human and MDP rewards for RLHF + RL.

For Mixed discrete and continuous actions, actions will be saved and returned in the format

    discrete_actions
        [   # Discrete action tensor
            [d0_s0,d1_s0,d2_s0,...,dN-1_s0],
            [d0_s1,d1_s1,d2_s1,...,dN-1_s1],
                        ...,
            [d0_sB,d1_sB,d2_sB,...,dN-1_sB],
        ],
    continuous_actions
        [   # Continuous Action Tensor
            [c0_s0,c1_s0,c2_s0,...,cM-1_s0],
            [c0_s1,c1_s1,c2_s1,...,cM-1_s1],
                        ...,
            [c0_sB,c1_sB,c2_sB,...,cM-1_sB]
        ],

where d0_s0 refers to discrete dimension 0 out of 'N' dimensions sample 0 out of 'B' batch size timesteps. c2_s1 would refer to continuous dimension 2 our of 'M' sample timestep 1 our of 'B' batch size.

init variables: num_steps: int Number of timesteps per agent to be saved in the buffer. obs_size: int Number of dimensions in the flattened 1 dimensional observation for a particular agent global_auxiliary_reward=False: bool Whether to record a second reward signal for human feedback. action_mask: [bool] List for whether to mask each dimension of the discrete portion of the actions. discrete_action_cardinalities: [int] List of integers to denote the number of discrete action choices for each discrete action output continuous_action_dimension: int Number of continuous action dimensions (Note: suppose a network outputs a distribution for each continuous dimension like [mean,std], then the continuous_action_dimension should be set to 2*n_action_dimensions because flexibuff will save exactly as many numbers as specified here) path: String the path to where flexibuff will be saved if a path is not passed at save time if no such path exists it will be made. default is './default_dir/' name: the name which will be appended onto the path to save these numpy arrays. default is 'flexibuff_test' n_agents: int The number of agents to save buffers for. state_size: int The number of dimensions for a global state for use in centralized training. None by default assuming observations are local global_reward: bool reward given to a group of agents global_auxiliary_reward: bool a second global reward such as human feedback individual_reward: bool reward given to an individual agent individual_auxiliary_reward: bool second reward given to individual such as with human feedback log_prob_discrete: bool whether to track log probabilities for discrete action space log_prob_continuous: int = 0 the dimension of probabilities to track for continuous action spaces for instance if there is one continuous action parameterized by a normal distribution with mean mu and std sigma, then continuous_action_dimension = 2, but log_prob_continuous would only be storing a single probability so it would be 1. memory_weights: bool whether or not to store weights along with each timestep for memory weighting or another purpose

Methods of Interest:

save_transition: Takes the actions / observations / states, etc from a step and saves it. sample_transitions: Samples unordered transitions

Metadata

Release files for flexibuff 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flexibuff 0.3.1
File Size Uploaded Provenance
flexibuff-0.3.1.tar.gz 22.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for flexibuff 0.3.1
File Interpreter ABI Platform
flexibuff-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 40.7 kB

Release files / flexibuff-0.3.1.tar.gz

Download URL flexibuff-0.3.1.tar.gz
Size 22.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7a28cd5215315e061b225a7a1ab249fb02b7c879496972f4671890e721d561c7
BLAKE2b-256 checksum
How to use checksums
0bffecb02491fb1967fc3b95bc4a53ae96826636e94ad843c1d0333305016ff2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.4

Release files / flexibuff-0.3.1-py3-none-any.whl

Download URL flexibuff-0.3.1-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47b8ce762a09324663cafaa6285eccf21d64bf060f69181123a2f60873ea2b81
BLAKE2b-256 checksum
How to use checksums
7b3ea6892ae66936415786646caab751fa36d613df63e6edaf0151ac1134fea8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.4

Security for flexibuff 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page