Skip to main content

Multi-Agent RL memory buffer which supports Numpy array and PyTorch Tensor formats

Project description

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 continious_action_dimension: int Number of continuous action dimensions (Note: suppose a network outputs a distribution for each continuous dimension like [mean,std], then the continious_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

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

flexibuff-0.0.3.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

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

flexibuff-0.0.3-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file flexibuff-0.0.3.tar.gz.

File metadata

  • Download URL: flexibuff-0.0.3.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for flexibuff-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ec2a5c01ca5a6c89a66a985ab84b1f8fa9e846bd7bc5254b0315732a2a54e29f
MD5 4817f977ec5765a60743da14546ffff5
BLAKE2b-256 7218dca9f04a7447987fe54aa589278d86803029cc357a6df1ded23e7598d1da

See more details on using hashes here.

File details

Details for the file flexibuff-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: flexibuff-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for flexibuff-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 42b8cab929b4b00b40932bc7b52629046da55ed7709b75fd7cab54418abf6640
MD5 f34eee51236f7a6801c7bf854e3673c9
BLAKE2b-256 14a6b534c68d1ec0f974c4edaeabbfd0a94cc7da85c37d627602b90eab25bde9

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