attacks-on-drl
Framework for existing attacks on trained StableBaselines3 DRL policies.
Example Usage
from attacks_on_drl.attacker import FGSMAttacker
from attacks_on_drl.runner import AttackRunner
from attacks_on_drl.victim import DQNVictim
# Defined environment (env) and SB3 policy (policy)
# SB3 policy must be wrapped in a Victim class
victim = DQNVictim(policy)
attacker = FGSMAttacker(victim)
runner = AttackRunner(env, attacker, victim, episode_max_frames=10_000)
runner.run(n_episodes=10)
Implemented Attacks
- FGSM $\ell_\infty$ Attacker [1]
- Value Function Attack [2]
- FGSM Every N Steps Attacker [2]
- Strategically Timed Attack [3]
- Critical Point Attack [4]
Adding A Custom Attack
Any attack must implement the BaseAttacker class, implementing the abstract step method. For example, suppose we introduce an attacker which attacks using FGSM every other step:
from attacks_on_drl.attacker.common import BaseAttacker
class EveryOtherStepAttacker(BaseAttacker):
def __init__(self, victim: BaseVictim) -> None:
super().__init__(victim=victim)
wrapped_victim = VictimModuleWrapper(self.victim)
self._perturbation_method = FGSM(wrapped_victim, eps=eps)
self.attack = True
def step(self, obs: VecEnvObs) -> tuple[VecEnvObs, bool]:
if self.attack:
actions = torch.tensor(self.victim.choose_action(obs, deterministic=True))
obs = self._perturbation_method(torch.from_numpy(obs)).numpy()
self.attack = not self.attack
return obs, not self.attack
References
[1] Huang, S., Papernot, N., Goodfellow, I., Duan, Y. and Abbeel, P., 2017. Adversarial attacks on neural network policies. arXiv preprint arXiv:1702.02284.
[2] Kos, J. and Song, D., 2017. Delving into adversarial attacks on deep policies. arXiv preprint arXiv:1705.06452.
[3] Lin, Y.C., Hong, Z.W., Liao, Y.H., Shih, M.L., Liu, M.Y. and Sun, M., 2017. Tactics of adversarial attack on deep reinforcement learning agents. arXiv preprint arXiv:1703.06748.
[4] Sun, J., Zhang, T., Xie, X., Ma, L., Zheng, Y., Chen, K. and Liu, Y., 2020, April. Stealthy and efficient adversarial attacks against deep reinforcement learning. In Proceedings of the AAAI conference on artificial intelligence (Vol. 34, No. 04, pp. 5883-5891).
Metadata
Release files for attacks-on-drl 0.2.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| attacks_on_drl-0.2.5.tar.gz | 10.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| attacks_on_drl-0.2.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.2 kB
Release files / attacks_on_drl-0.2.5.tar.gz
| Download URL | attacks_on_drl-0.2.5.tar.gz |
|---|---|
| Size | 10.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1fcb22ef81e393f132b14446c46bb2fc67eff060581c45ecc1999546e206e10
|
|
BLAKE2b-256 checksum How to use checksums |
f51d449b1b545c9775eaf130a39dfc9171468ce757d42ffbb4dc66321dba461b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / attacks_on_drl-0.2.5-py3-none-any.whl
| Download URL | attacks_on_drl-0.2.5-py3-none-any.whl |
|---|---|
| Size | 16.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4b5c0d3fcd0c60f5170392654e79bc473a38a5c860fbbf30aef899970b570f04
|
|
BLAKE2b-256 checksum How to use checksums |
faf24e48a8a03d828c142b05e700a04227136e24c20b626aeb64e3391bad634c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|