Skip to main content

A programming framework based on PyTorch for hybrid neural networks with automatic quantization

Project description

Hybrid Programming Framework

简介

HNN编程框架基于PyTorch进行开发,提供了编写ANN、SNN、HNN模型的编程接口,同时可以支持通过此编程框架描述的ANN、SNN模型的自动化量化(HNN的自动化量化仍在开发中),可以支持后训练静态量化和量化感知训练。下面对SNN和HNN编程进行简要说明:

  • SNN编程由一系列基本SNN操作组成,通过这些基本操作可以组成灵活的、功能丰富的扩展LIF神经元模型,用户也可以基于这些基本操作实现自定义的神经元模型。
  • HNN编程中的HNN主要指[1]中以Hybrid Unit (HU)为转换单元来连接ANN和SNN网络的混合网络,编程框架中实现了可扩展的HU,用户可使用编程框架中提供的各种HU或自定义HU。

此框架的开发过程中考虑了与BiMap的融合,通过此编程框架描述的网络可以进一步被BiMap中的编译系统编译部署到支持的类脑计算芯片上。

HNN编程框架的详细开发及使用文档请见工程文档。

基本使用

安装相关依赖:

pip install -r requirement.txt

注:目前因为ONNX版本兼容问题,Pytorch需要使用1.11.0版本

examples文件夹下为通过此编程框架写出的一些ANN、SNN、HNN模型,以需要量化的SNN为例,SNN模型需要继承src.snn中的QModel类,并通过QConv2d, QLinear, QLIF等算子来搭建网络:

from src.snn import QModel, QLinear, QLIF


class SNN(QModel):
    def __init__(self, in_channels, T, num_classes=10):
        super(SNN, self).__init__(time_window_size=T)
        self.linear = QLinear(
            in_features=in_channels, out_features=num_classes)
        self.lif = QLIF(v_th=1, v_leaky_alpha=0.9,
                        v_leaky_beta=0, v_reset=0)

参考引用

如果使用到本编程框架的HNN部分,请引用[1]:

@article{Zhao2022,
doi = {10.1038/s41467-022-30964-7},
url = {https://doi.org/10.1038/s41467-022-30964-7},
year = {2022},
month = jun,
publisher = {Springer Science and Business Media {LLC}},
volume = {13},
number = {1},
author = {Rong Zhao and Zheyu Yang and Hao Zheng and Yujie Wu and Faqiang Liu and Zhenzhi Wu and Lukai Li and Feng Chen and Seng Song and Jun Zhu and Wenli Zhang and Haoyu Huang and Mingkun Xu and Kaifeng Sheng and Qianbo Yin and Jing Pei and Guoqi Li and Youhui Zhang and Mingguo Zhao and Luping Shi},
title = {A framework for the general design and computation of hybrid neural networks},
journal = {Nature Communications}
}

本工程的SNN和HNN编程部分参考或复用了部分SpikingJelly的代码:

@misc{SpikingJelly,
    title = {SpikingJelly},
    author = {Fang, Wei and Chen, Yanqi and Ding, Jianhao and Chen, Ding and Yu, Zhaofei and Zhou, Huihui and Timothée Masquelier and Tian, Yonghong and other contributors},
    year = {2020},
    howpublished = {\url{https://github.com/fangwei123456/spikingjelly}},
    note = {Accessed: YYYY-MM-DD},
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hnn-0.0.3.1.tar.gz (32.5 kB view details)

Uploaded Source

File details

Details for the file hnn-0.0.3.1.tar.gz.

File metadata

  • Download URL: hnn-0.0.3.1.tar.gz
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.7

File hashes

Hashes for hnn-0.0.3.1.tar.gz
Algorithm Hash digest
SHA256 29e27799a095dc70c2dc4835befe6cd93f5a9b8b273d0bd1deb5a14d2bf46ffb
MD5 b3e93d6641ae735dbfbd0dd3596f0184
BLAKE2b-256 35f76cb8ec6aa135c483ce4e08653f03f560f574e75c01d4341636c30ceaafb2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page