Skip to main content

Blackbox Gradient Sensing

Project description

Blackbox Gradient Sensing (wip)

Explorations into Blackbox Gradient Sensing (BGS), an evolutionary strategies approach proposed in a Google Deepmind paper for Table Tennis

Note: This paper is from 2022, and PPO is now being used for sim2real for humanoid robots (contradicting the author). However, this is the only work that I know of that successfully deployed a policy trained with ES, so worth putting out there, even if it is not quite there yet.

Will also incorporate the latent population variant successfully used in EPO. Of all the things going on in evolutionary field, I believe crossover may be one of the most important.

Install

$ pip install blackbox-gradient-sensing

Usage

# mock env

import numpy as np

class Sim:
    def reset(self, seed = None):
        return np.random.randn(5) # state

    def step(self, actions):
        return np.random.randn(5), np.random.randn(1), False, False # state, reward, terminated, truncated

sim = Sim()

# instantiate BlackboxGradientSensing with the Actor (with right number of actions), and then forward your environment for the actor to learn from it
# you can also supply your own Actor, which simply receives a state tensor and outputs action logits

from bgs import BlackboxGradientSensing, Actor

actor = Actor(
    dim_state = 5,
    num_actions = 2
)

bgs = BlackboxGradientSensing(
    actor,
    dim_state = 5,
    noise_pop_size = 10,
    num_rollout_repeats = 1
)

bgs(sim, 1000) # pass the simulation environment in - say for 1000 interactions with env

# after much training, save your learned policy for finetuning on real env

actor.save('./sim-trained-actor.pt')

Example

$ pip install -r requirements.txt  # or `uv pip install`, to keep up with the times

You may need to run the following if you see an error related to swig

$ apt install swig -y

Then

$ python train.py

Distributed using 🤗 accelerate

First

$ accelerate config

Then

$ accelerate launch train.py

Citations

@inproceedings{Abeyruwan2022iSim2RealRL,
    title   = {i-Sim2Real: Reinforcement Learning of Robotic Policies in Tight Human-Robot Interaction Loops},
    author  = {Saminda Abeyruwan and Laura Graesser and David B. D'Ambrosio and Avi Singh and Anish Shankar and Alex Bewley and Deepali Jain and Krzysztof Choromanski and Pannag R. Sanketi},
    booktitle = {Conference on Robot Learning},
    year    = {2022},
    url     = {https://api.semanticscholar.org/CorpusID:250526228}
}
@article{Lee2024SimBaSB,
    title   = {SimBa: Simplicity Bias for Scaling Up Parameters in Deep Reinforcement Learning},
    author  = {Hojoon Lee and Dongyoon Hwang and Donghu Kim and Hyunseung Kim and Jun Jet Tai and Kaushik Subramanian and Peter R. Wurman and Jaegul Choo and Peter Stone and Takuma Seno},
    journal = {ArXiv},
    year    = {2024},
    volume  = {abs/2410.09754},
    url     = {https://api.semanticscholar.org/CorpusID:273346233}
}
@article{Palenicek2025ScalingOR,
    title   = {Scaling Off-Policy Reinforcement Learning with Batch and Weight Normalization},
    author  = {Daniel Palenicek and Florian Vogt and Jan Peters},
    journal = {ArXiv},
    year    = {2025},
    volume  = {abs/2502.07523},
    url     = {https://api.semanticscholar.org/CorpusID:276258971}
}

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

blackbox_gradient_sensing-0.0.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

blackbox_gradient_sensing-0.0.3-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for blackbox_gradient_sensing-0.0.3.tar.gz
Algorithm Hash digest
SHA256 190c44265e80464a64d51c3c6e13a112d7e1a99045a742716fa8ef896f5177a1
MD5 c568275f54927157249efbfd4374927f
BLAKE2b-256 b73cb91f41910c3f006942c1a90105de7c85f28f354ea81ff6b409aad9d1e687

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for blackbox_gradient_sensing-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d0c9d6d54c04dfdb22ed69a7a4f4e1e8ec145a36b4332bbeb3054a4e2b121b92
MD5 4f22dc47da46f20aaeae168dc306f76e
BLAKE2b-256 db5dd8e56ae35d4927a0541115ea44fa61bac4911e4d8ac0c9a64efc2ef1aa69

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