Skip to main content

QPytorch+: Extending Qpytorch for Posit format and more

Author: minhhn2910@github, himeshi@github


Install

Install in developer mode:

git clone https://github.com/minhhn2910/QPyTorch.git
cd QPyTorch
pip install -e ./

Simple test if c-extension is working correctly :

python test.py

Important: if there are errors when running test.py, please export the environment variables indicating build directory and/or CUDA_HOME, otherwise we will have permission problem in multi-user-server.

export TORCH_EXTENSIONS_DIR=/[your-home-folder]/torch_extension
export CUDA_HOME=/[your cuda instalation directory e.g. /usr/local/cuda-10.2] 
python test.py

Functionality:

  • Support Posit Format with round to nearest mode.
  • Scaling of value before & after conversion to/from posit is supported (Exponent bias when the scale is a power of 2).
    For example: value x -> x*scale -> Posit(x*scale) -> x
  • Support Tanh approximation with Posit and correction of error:
    When x is in a posit format with es = 0 => Sigmoid(x) = (x XOR 0x8000) >> 2 => PositTanh(x) = 2 · Sigmoid(2x) − 1
  • More number formats (Table lookup, log2 system ..., and new rounding modes will be supported on new versions).

Currently under development and update to support more number formats and schemes.


Demo and tutorial:

  • Approximate Tanh Function with Posit is presented at examples/tutorial/test_posit_func.ipynb
  • Most functionalities can be tested by using the notebooks in posit tutorials: ./examples/tutorial/
  • Notebook demo training Cifar10 with vanilla Posit 8 bit: examples/tutorial/CIFAR10_Posit_Training_Example.ipynb
  • Demo of DCGAN Cifar10 training with Posit 8 bit: Google Colab Link
  • Demo of DCGAN Lsun inference using Posit 6 bit and Approximate Tanh : Google Colab Link
  • Demo of applying posit 6 bits & 8 bits to ALBERT for Question Answering Task: GoogleColab Demo

If you find this repo useful, please cite our paper(s) listed below. The below also explain the terms and usage of Posit's enhancements (exponent bias and tanh function).

@inproceedings{ho2021posit,
  title={Posit Arithmetic for the Training and Deployment of Generative Adversarial Networks},
  author={Ho, Nhut-Minh and Nguyen, Duy-Thanh and De Silva, Himeshi and Gustafson, John L and Wong, Weng-Fai and Chang, Ik Joon},
  booktitle={2021 Design, Automation \& Test in Europe Conference \& Exhibition (DATE)},
  pages={1350--1355},
  year={2021},
  organization={IEEE}
}


The original Qpytorch package which supports floating point and fixed point:

The original README file is in REAME.original.md

Credit to the Qpytorch team and their original publication

@misc{zhang2019qpytorch,
    title={QPyTorch: A Low-Precision Arithmetic Simulation Framework},
    author={Tianyi Zhang and Zhiqiu Lin and Guandao Yang and Christopher De Sa},
    year={2019},
    eprint={1910.04540},
    archivePrefix={arXiv},
    primaryClass={cs.LG}
}
Qpytorch Team

Metadata

Release files for qtorch-plus 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qtorch-plus 0.2.0
File Size Uploaded Provenance Actions
qtorch_plus-0.2.0.tar.gz 30.4 kB Without provenance Details for qtorch_plus-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qtorch-plus 0.2.0
File Interpreter ABI Platform Actions
qtorch_plus-0.2.0-py3-none-any.whl Python 3 none any Details for qtorch_plus-0.2.0-py3-none-any.whl

Total release size: 64.7 kB

Release files / qtorch_plus-0.2.0.tar.gz

Download URL qtorch_plus-0.2.0.tar.gz
Size 30.4 kB
Tags Source
SHA-256 checksum
How to use checksums
76496a8cb347fed7374dadf6ec4db86fa02290918e1ae06605508f4d835e309a
BLAKE2b-256 checksum
How to use checksums
8f65c516493c307e4468b44a33572ecb2a06ba030b95f7fdf0132ebdc795dd6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/3.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.7.11

Release files / qtorch_plus-0.2.0-py3-none-any.whl

Download URL qtorch_plus-0.2.0-py3-none-any.whl
Size 34.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba90c64119545a8be1351535c3ea6139222774fa278daed3fd22e86ecc805a66
BLAKE2b-256 checksum
How to use checksums
6c7543be25fdf4aae997074aa12d6965c79adee981aa3d69fe818e1df600616f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/3.10.1 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.7.11

Security for qtorch-plus 0.2.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page