optax


Nameoptax JSON
Version 0.2.2 PyPI version JSON
download
home_pageNone
SummaryA gradient processing and optimisation library in JAX.
upload_time2024-03-27 18:05:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords python machine learning reinforcement-learning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Optax

![CI status](https://github.com/google-deepmind/optax/actions/workflows/tests.yml/badge.svg?branch=main)
[![Documentation Status](https://readthedocs.org/projects/optax/badge/?version=latest)](http://optax.readthedocs.io)
![pypi](https://img.shields.io/pypi/v/optax)

## Introduction

Optax is a gradient processing and optimization library for JAX.

Optax is designed to facilitate research by providing building blocks
that can be easily recombined in custom ways.

Our goals are to

*   Provide simple, well-tested, efficient implementations of core components.
*   Improve research productivity by enabling to easily combine low-level
    ingredients into custom optimisers (or other gradient processing components).
*   Accelerate adoption of new ideas by making it easy for anyone to contribute.

We favour focusing on small composable building blocks that can be effectively
combined into custom solutions. Others may build upon these basic components
in more complicated abstractions. Whenever reasonable, implementations prioritise
readability and structuring code to match standard equations, over code reuse.

An initial prototype of this library was made available in JAX's experimental
folder as `jax.experimental.optix`. Given the wide adoption across DeepMind
of `optix`, and after a few iterations on the API, `optix` was eventually moved
out of `experimental` as a standalone open-source library, and renamed `optax`.

Documentation on Optax can be found at [optax.readthedocs.io](https://optax.readthedocs.io/).

## Installation

You can install the latest released version of Optax from PyPI via:

```sh
pip install optax
```

or you can install the latest development version from GitHub:

```sh
pip install git+https://github.com/google-deepmind/optax.git
```

## Quickstart

Optax contains implementations of [many popular optimizers](https://optax.readthedocs.io/en/latest/api/optimizers.html) and
[loss functions](https://optax.readthedocs.io/en/latest/api/losses.html).
For example, the following code snippet uses the Adam optimizer from `optax.adam`
and the mean squared error from `optax.l2_loss`. We initialize the optimizer
state using the `init` function and `params` of the model.

```python
optimizer = optax.adam(learning_rate)
# Obtain the `opt_state` that contains statistics for the optimizer.
params = {'w': jnp.ones((num_weights,))}
opt_state = optimizer.init(params)
```

To write the update loop we need a loss function that can be differentiated by
Jax (with `jax.grad` in this
example) to obtain the gradients.

```python
compute_loss = lambda params, x, y: optax.l2_loss(params['w'].dot(x), y)
grads = jax.grad(compute_loss)(params, xs, ys)
```

The gradients are then converted via `optimizer.update` to obtain the updates
that should be applied to the current parameters to obtain the new ones.
`optax.apply_updates` is a convenience utility to do this.

```python
updates, opt_state = optimizer.update(grads, opt_state)
params = optax.apply_updates(params, updates)
```

You can continue the quick start in [the Optax 101 notebook.](https://github.com/google-deepmind/optax/blob/main/docs/optax-101.ipynb)

## Development

We welcome new contributors.

### Source code

You can check the latest sources with the following command.

```sh
git clone https://github.com/google-deepmind/optax.git
```
### Testing

To run the tests, please execute the following script.

```sh
sh ./test.sh
```

### Documentation

To build the documentation, first ensure that all the dependencies are installed.
```sh
pip install -e ".[docs]"
```
Then, execute the following.
```sh
cd docs/
make html
```

## Benchmarks
If you feel lost in the crowd of available optimizers for deep learning, there
exist some extensive benchmarks:

[Benchmarking Neural Network Training Algorithms, Dahl G. et al, 2023](https://arxiv.org/pdf/2306.07179),

[Descending through a Crowded Valley — Benchmarking Deep Learning Optimizers, Schmidt R. et al, 2021](https://proceedings.mlr.press/v139/schmidt21a).

If you are interested in developing your own benchmark for some tasks,
consider the following framework

[Benchopt: Reproducible, efficient and collaborative optimization benchmarks, Moreau T. et al, 2022](https://arxiv.org/abs/2206.13424).

Finally, if you are searching for some recommendations on tuning optimizers,
consider taking a look at

[Deep Learning Tuning Playbook, Godbole V. et al, 2023](https://github.com/google-research/tuning_playbook).


## Citing Optax

This repository is part of the DeepMind JAX Ecosystem, to cite Optax
please use the citation:

```bibtex
@software{deepmind2020jax,
  title = {The {D}eep{M}ind {JAX} {E}cosystem},
  author = {DeepMind and Babuschkin, Igor and Baumli, Kate and Bell, Alison and Bhupatiraju, Surya and Bruce, Jake and Buchlovsky, Peter and Budden, David and Cai, Trevor and Clark, Aidan and Danihelka, Ivo and Dedieu, Antoine and Fantacci, Claudio and Godwin, Jonathan and Jones, Chris and Hemsley, Ross and Hennigan, Tom and Hessel, Matteo and Hou, Shaobo and Kapturowski, Steven and Keck, Thomas and Kemaev, Iurii and King, Michael and Kunesch, Markus and Martens, Lena and Merzic, Hamza and Mikulik, Vladimir and Norman, Tamara and Papamakarios, George and Quan, John and Ring, Roman and Ruiz, Francisco and Sanchez, Alvaro and Sartran, Laurent and Schneider, Rosalia and Sezener, Eren and Spencer, Stephen and Srinivasan, Srivatsan and Stanojevi\'{c}, Milo\v{s} and Stokowiec, Wojciech and Wang, Luyu and Zhou, Guangyao and Viola, Fabio},
  url = {http://github.com/google-deepmind},
  year = {2020},
}
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "optax",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "python, machine learning, reinforcement-learning",
    "author": null,
    "author_email": "Google DeepMind <optax-dev@google.com>",
    "download_url": "https://files.pythonhosted.org/packages/88/05/20c29c0a1d391d669098a49fee30325c12c92e16a3df607bb882a2c630cc/optax-0.2.2.tar.gz",
    "platform": null,
    "description": "# Optax\n\n![CI status](https://github.com/google-deepmind/optax/actions/workflows/tests.yml/badge.svg?branch=main)\n[![Documentation Status](https://readthedocs.org/projects/optax/badge/?version=latest)](http://optax.readthedocs.io)\n![pypi](https://img.shields.io/pypi/v/optax)\n\n## Introduction\n\nOptax is a gradient processing and optimization library for JAX.\n\nOptax is designed to facilitate research by providing building blocks\nthat can be easily recombined in custom ways.\n\nOur goals are to\n\n*   Provide simple, well-tested, efficient implementations of core components.\n*   Improve research productivity by enabling to easily combine low-level\n    ingredients into custom optimisers (or other gradient processing components).\n*   Accelerate adoption of new ideas by making it easy for anyone to contribute.\n\nWe favour focusing on small composable building blocks that can be effectively\ncombined into custom solutions. Others may build upon these basic components\nin more complicated abstractions. Whenever reasonable, implementations prioritise\nreadability and structuring code to match standard equations, over code reuse.\n\nAn initial prototype of this library was made available in JAX's experimental\nfolder as `jax.experimental.optix`. Given the wide adoption across DeepMind\nof `optix`, and after a few iterations on the API, `optix` was eventually moved\nout of `experimental` as a standalone open-source library, and renamed `optax`.\n\nDocumentation on Optax can be found at [optax.readthedocs.io](https://optax.readthedocs.io/).\n\n## Installation\n\nYou can install the latest released version of Optax from PyPI via:\n\n```sh\npip install optax\n```\n\nor you can install the latest development version from GitHub:\n\n```sh\npip install git+https://github.com/google-deepmind/optax.git\n```\n\n## Quickstart\n\nOptax contains implementations of [many popular optimizers](https://optax.readthedocs.io/en/latest/api/optimizers.html) and\n[loss functions](https://optax.readthedocs.io/en/latest/api/losses.html).\nFor example, the following code snippet uses the Adam optimizer from `optax.adam`\nand the mean squared error from `optax.l2_loss`. We initialize the optimizer\nstate using the `init` function and `params` of the model.\n\n```python\noptimizer = optax.adam(learning_rate)\n# Obtain the `opt_state` that contains statistics for the optimizer.\nparams = {'w': jnp.ones((num_weights,))}\nopt_state = optimizer.init(params)\n```\n\nTo write the update loop we need a loss function that can be differentiated by\nJax (with `jax.grad` in this\nexample) to obtain the gradients.\n\n```python\ncompute_loss = lambda params, x, y: optax.l2_loss(params['w'].dot(x), y)\ngrads = jax.grad(compute_loss)(params, xs, ys)\n```\n\nThe gradients are then converted via `optimizer.update` to obtain the updates\nthat should be applied to the current parameters to obtain the new ones.\n`optax.apply_updates` is a convenience utility to do this.\n\n```python\nupdates, opt_state = optimizer.update(grads, opt_state)\nparams = optax.apply_updates(params, updates)\n```\n\nYou can continue the quick start in [the Optax 101 notebook.](https://github.com/google-deepmind/optax/blob/main/docs/optax-101.ipynb)\n\n## Development\n\nWe welcome new contributors.\n\n### Source code\n\nYou can check the latest sources with the following command.\n\n```sh\ngit clone https://github.com/google-deepmind/optax.git\n```\n### Testing\n\nTo run the tests, please execute the following script.\n\n```sh\nsh ./test.sh\n```\n\n### Documentation\n\nTo build the documentation, first ensure that all the dependencies are installed.\n```sh\npip install -e \".[docs]\"\n```\nThen, execute the following.\n```sh\ncd docs/\nmake html\n```\n\n## Benchmarks\nIf you feel lost in the crowd of available optimizers for deep learning, there\nexist some extensive benchmarks:\n\n[Benchmarking Neural Network Training Algorithms, Dahl G. et al, 2023](https://arxiv.org/pdf/2306.07179),\n\n[Descending through a Crowded Valley \u2014 Benchmarking Deep Learning Optimizers, Schmidt R. et al, 2021](https://proceedings.mlr.press/v139/schmidt21a).\n\nIf you are interested in developing your own benchmark for some tasks,\nconsider the following framework\n\n[Benchopt: Reproducible, efficient and collaborative optimization benchmarks, Moreau T. et al, 2022](https://arxiv.org/abs/2206.13424).\n\nFinally, if you are searching for some recommendations on tuning optimizers,\nconsider taking a look at\n\n[Deep Learning Tuning Playbook, Godbole V. et al, 2023](https://github.com/google-research/tuning_playbook).\n\n\n## Citing Optax\n\nThis repository is part of the DeepMind JAX Ecosystem, to cite Optax\nplease use the citation:\n\n```bibtex\n@software{deepmind2020jax,\n  title = {The {D}eep{M}ind {JAX} {E}cosystem},\n  author = {DeepMind and Babuschkin, Igor and Baumli, Kate and Bell, Alison and Bhupatiraju, Surya and Bruce, Jake and Buchlovsky, Peter and Budden, David and Cai, Trevor and Clark, Aidan and Danihelka, Ivo and Dedieu, Antoine and Fantacci, Claudio and Godwin, Jonathan and Jones, Chris and Hemsley, Ross and Hennigan, Tom and Hessel, Matteo and Hou, Shaobo and Kapturowski, Steven and Keck, Thomas and Kemaev, Iurii and King, Michael and Kunesch, Markus and Martens, Lena and Merzic, Hamza and Mikulik, Vladimir and Norman, Tamara and Papamakarios, George and Quan, John and Ring, Roman and Ruiz, Francisco and Sanchez, Alvaro and Sartran, Laurent and Schneider, Rosalia and Sezener, Eren and Spencer, Stephen and Srinivasan, Srivatsan and Stanojevi\\'{c}, Milo\\v{s} and Stokowiec, Wojciech and Wang, Luyu and Zhou, Guangyao and Viola, Fabio},\n  url = {http://github.com/google-deepmind},\n  year = {2020},\n}\n```\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A gradient processing and optimisation library in JAX.",
    "version": "0.2.2",
    "project_urls": {
        "documentation": "https://optax.readthedocs.io/",
        "homepage": "https://github.com/google-deepmind/optax",
        "repository": "https://github.com/google-deepmind/optax"
    },
    "split_keywords": [
        "python",
        " machine learning",
        " reinforcement-learning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "160474ec9cf76c9e3d222251ac38de67404a41b3b673d9227611c9f5aecccb18",
                "md5": "711cf28deab970cce394dc9b976c51e1",
                "sha256": "411c414a76aae259f4191a60b712663968741a5163ca92fc250b5d5c7d36fb57"
            },
            "downloads": -1,
            "filename": "optax-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "711cf28deab970cce394dc9b976c51e1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 223674,
            "upload_time": "2024-03-27T18:05:53",
            "upload_time_iso_8601": "2024-03-27T18:05:53.199945Z",
            "url": "https://files.pythonhosted.org/packages/16/04/74ec9cf76c9e3d222251ac38de67404a41b3b673d9227611c9f5aecccb18/optax-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "880520c29c0a1d391d669098a49fee30325c12c92e16a3df607bb882a2c630cc",
                "md5": "87465ef021d24a1e5a9576b860dc140d",
                "sha256": "f09bf790ef4b09fb9c35f79a07594c6196a719919985f542dc84b0bf97812e0e"
            },
            "downloads": -1,
            "filename": "optax-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "87465ef021d24a1e5a9576b860dc140d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 160405,
            "upload_time": "2024-03-27T18:05:54",
            "upload_time_iso_8601": "2024-03-27T18:05:54.775664Z",
            "url": "https://files.pythonhosted.org/packages/88/05/20c29c0a1d391d669098a49fee30325c12c92e16a3df607bb882a2c630cc/optax-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-27 18:05:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "google-deepmind",
    "github_project": "optax",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "optax"
}
        
Elapsed time: 0.20648s