HL Gauss - Pytorch
The Gaussian Histogram Loss (HL-Gauss) proposed by Imani et al. with a few convenient wrappers, in Pytorch.
A team at Deepmind wrote a paper with a lot of positive findings for its use in value-based RL.
Put into action here, seems to work well
Install
$ pip install hl-gauss-pytorch
Usage
The HLGaussLoss module as defined in Appendix A. of the Stop Regressing paper
import torch
from hl_gauss_pytorch import HLGaussLoss
hl_gauss = HLGaussLoss(
min_value = 0.,
max_value = 5.,
num_bins = 32,
sigma = 0.5,
clamp_to_range = True # this was added because if any values fall outside of the bins, the loss is 0 with the current logic
)
logits = torch.randn(3, 16, 32).requires_grad_()
targets = torch.randint(0, 5, (3, 16)).float()
loss = hl_gauss(logits, targets)
loss.backward()
# after much training
pred_target = hl_gauss(logits) # (3, 16)
For a convenient layer that predicts from embedding to logits, import HLGaussLayer
import torch
from hl_gauss_pytorch import HLGaussLayer
hl_gauss_layer = HLGaussLayer(
dim = 256, # input embedding dimension
hl_gauss_loss = dict(
min_value = 0.,
max_value = 5.,
num_bins = 32,
sigma = 0.5,
)
)
embed = torch.randn(7, 256)
targets = torch.randint(0, 5, (7,)).float()
loss = hl_gauss_layer(embed, targets)
loss.backward()
# after much training
pred_target = hl_gauss_layer(embed) # (7,)
For ablating the proposal, you can make the HLGaussLayer fall back to regular regression by setting use_regression = True, keeping the code above unchanged
HLGaussLayer(..., use_regression = True)
Citations
@article{Imani2024InvestigatingTH,
title = {Investigating the Histogram Loss in Regression},
author = {Ehsan Imani and Kai Luedemann and Sam Scholnick-Hughes and Esraa Elelimy and Martha White},
journal = {ArXiv},
year = {2024},
volume = {abs/2402.13425},
url = {https://api.semanticscholar.org/CorpusID:267770096}
}
@inproceedings{Imani2018ImprovingRP,
title = {Improving Regression Performance with Distributional Losses},
author = {Ehsan Imani and Martha White},
booktitle = {International Conference on Machine Learning},
year = {2018},
url = {https://api.semanticscholar.org/CorpusID:48365278}
}
@article{Farebrother2024StopRT,
title = {Stop Regressing: Training Value Functions via Classification for Scalable Deep RL},
author = {Jesse Farebrother and Jordi Orbay and Quan Ho Vuong and Adrien Ali Taiga and Yevgen Chebotar and Ted Xiao and Alex Irpan and Sergey Levine and Pablo Samuel Castro and Aleksandra Faust and Aviral Kumar and Rishabh Agarwal},
journal = {ArXiv},
year = {2024},
volume = {abs/2403.03950},
url = {https://api.semanticscholar.org/CorpusID:268253088}
}
Metadata
Release files for hl-gauss-pytorch 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hl_gauss_pytorch-0.3.0.tar.gz | 9.2 kB | Without provenance | Details for hl_gauss_pytorch-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hl_gauss_pytorch-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for hl_gauss_pytorch-0.3.0-py3-none-any.whl |
Total release size: 19.4 kB
Release files / hl_gauss_pytorch-0.3.0.tar.gz
| Download URL | hl_gauss_pytorch-0.3.0.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b750724f72cd9932340ff0eb2a3df634c415ed688b99718725daeb4784151175
|
|
BLAKE2b-256 checksum How to use checksums |
7af783e84d91320aa0c8fa123387221659add62ff7dd7bd48dfd3e39aa3f3f6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Release files / hl_gauss_pytorch-0.3.0-py3-none-any.whl
| Download URL | hl_gauss_pytorch-0.3.0-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d0829cde029130bb308c332cd912f5cb05b791fb334a204e6b0330321f8341a1
|
|
BLAKE2b-256 checksum How to use checksums |
f53901ee52f2ade8088d8d329a7d20f9d9adf375fdb08b70b1ab6be217545ad4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.17
|
Security for hl-gauss-pytorch 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.