https://github.com/egiob/cfrx
cfrx is a collection of algorithms and tools for hardware-accelerated Counterfactual Regret Minimization (CFR) algorithms in Jax.
https://github.com/egiob/cfrx
counterfactual-regret-minimization games jax python reinforcement-learning
Last synced: 26 days ago
JSON representation
cfrx is a collection of algorithms and tools for hardware-accelerated Counterfactual Regret Minimization (CFR) algorithms in Jax.
- Host: GitHub
- URL: https://github.com/egiob/cfrx
- Owner: Egiob
- License: mit
- Created: 2023-04-14T20:02:32.000Z (over 2 years ago)
- Default Branch: develop
- Last Pushed: 2024-08-08T13:43:47.000Z (about 1 year ago)
- Last Synced: 2024-08-08T16:05:53.707Z (about 1 year ago)
- Topics: counterfactual-regret-minimization, games, jax, python, reinforcement-learning
- Language: Python
- Homepage:
- Size: 382 KB
- Stars: 25
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# cfrx: Counterfactual Regret Minimization in Jax.
cfrx is an open-source library designed for efficient implementation of counterfactual regret minimization (CFR) algorithms using JAX. It focuses on computational speed and easy parallelization on hardware accelerators like GPUs and TPUs.
Key Features:
- **JIT Compilation for Speed:** cfrx makes the most out of JAX's just-in-time (JIT) compilation to minimize runtime overhead and maximize computational speed.
- **Hardware Accelerator Support:** It supports parallelization on GPUs and TPUs, enabling efficient scaling of computations for large-scale problems.
- **Python/JAX Ease of Use:** cfrx provides a Pythonic interface built on JAX, offering simplicity and accessibility compared to traditional C++ implementations or prohibitively slow pure-Python code.
## Installation
pip install cfrx
## Getting started
An example notebook is available [here](examples/mccfr.ipynb).
Snippet for training a MCCFR-outcome sampling on the Kuhn Poker game.
```python3
import jaxfrom cfrx.envs.kuhn_poker.env import KuhnPoker
from cfrx.policy import TabularPolicy
from cfrx.trainers.mccfr import MCCFRTrainerenv = KuhnPoker()
policy = TabularPolicy(
n_actions=env.n_actions,
exploration_factor=0.6,
info_state_idx_fn=env.info_state_idx,
)random_key = jax.random.PRNGKey(0)
trainer = MCCFRTrainer(env=env, policy=policy)
training_state, metrics = trainer.train(
random_key=random_key, n_iterations=100_000, metrics_period=5_000
)
```## Implemented features and upcoming features
| Algorithms | |
|---|---|
| MCCFR (outcome-sampling) | :white_check_mark: |
| MCCFR (other variants) | :x: |
| Vanilla CFR | :white_check_mark: |
| Deep CFR | :x: || Metrics | |
|---|---|
| Exploitability | :white_check_mark: |
| Local Best Response | :x: || Environments | |
|---|---|
| Kuhn Poker | :white_check_mark: |
| Leduc Poker | :white_check_mark: |
| Larger games | :x: |## Performance
Below is a small benchmark against `open_spiel` for MCCFR-outcome-sampling on Kuhn Poker and Leduc Poker. Compared to the Python API of `open_spiel`, `cfrx` has faster runtime and demonstrates similar convergence.

## See also
cfrx is heavily inspired by the amazing [google-deepmind/open_spiel](https://github.com/google-deepmind/open_spiel) library as well as by many projects from the Jax ecosystem and especially [sotetsuk/pgx](https://github.com/sotetsuk/pgx) and [google-deepmind/mctx](https://github.com/google-deepmind/mctx).
## Contributing
Contributions are welcome, refer to the [contributions guidelines](CONTRIBUTING.md).