Blackbox Gradient Sensing
Project description
Blackbox Gradient Sensing
Implementation and 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 used in EPO. Of all the things going on in evolutionary field, I believe crossover may be one of the most important. This may be the ultimate bitter lesson.
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 # state, reward, done
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 torch import nn
from blackbox_gradient_sensing import BlackboxGradientSensing
actor = nn.Linear(5, 2) # contrived network from state of 5 dimension to two actions
bgs = BlackboxGradientSensing(
actor = actor,
noise_pop_size = 10, # number of noise perturbations
num_selected = 2, # topk noise selected for update
num_rollout_repeats = 1 # how many times to redo environment rollout, per noise
)
bgs(sim, 100) # pass the simulation environment in - say for 100 interactions with env
# after much training, save your learned policy (and optional state normalization) for finetuning on real env
bgs.save('./actor-and-state-norm.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}
}
@misc{Rubin2024,
author = {Ohad Rubin},
url = {https://medium.com/@ohadrubin/exploring-weight-decay-in-layer-normalization-challenges-and-a-reparameterization-solution-ad4d12c24950}
}
@inproceedings{Wang2025EvolutionaryPO,
title = {Evolutionary Policy Optimization},
author = {Jianren Wang and Yifan Su and Abhinav Gupta and Deepak Pathak},
year = {2025},
url = {https://api.semanticscholar.org/CorpusID:277313729}
}
Project details
Release history Release notifications | RSS feed
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 blackbox_gradient_sensing-0.2.19.tar.gz.
File metadata
- Download URL: blackbox_gradient_sensing-0.2.19.tar.gz
- Upload date:
- Size: 16.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84501a006d4167729713e2636fcb0723f8a6827eb6bc94e14b091608cb35c407
|
|
| MD5 |
393e39550f1a5d770defa233cd9758e2
|
|
| BLAKE2b-256 |
1f084e27255ca8ed349c1909630ba8c90609ae685ff082252c6fff45f6a7d9b0
|
File details
Details for the file blackbox_gradient_sensing-0.2.19-py3-none-any.whl.
File metadata
- Download URL: blackbox_gradient_sensing-0.2.19-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c2c633f5029679ad97681bac43f066440c4c7f7d5c13e052ddf3737d7115514
|
|
| MD5 |
26eadd6fb86135e291f26c9c416a0f75
|
|
| BLAKE2b-256 |
2b3c2ce65fa8d4933ca2fd83eeb46345b86957d06ad69f4d90753e096df28842
|