BinaryBrain Version 4
--binary neural networks platform for LUT-networks
詳现ãªããã¥ã¡ã³ãã¯ãã¡ã ã§ãã
æŠèŠ
BinaryBrain ã¯äž»ã«åœãµã€ããç 究äžã® LUT(Look-up Table)-Networkãå®éšããããšãç®çã«äœæãããã£ãŒãã©ãŒãã³ã°çšã®ãã©ãããã©ãŒã ã§ãã
FPGAã®LUTãStochasticèšç®ç±æ¥ã®åŸ®åå¯èœåè·¯èšè¿°(differentiable circuit description)ã«ãŠçŽæ¥çã«åŠç¿ãããããšã§é«ãå¯åºŠã§ã®FPGAåŠç¿ãç®æããŠããŸãã
LUT-Networkã®è©äŸ¡ãç®çã«äœæããŠãããŸããããã以å€ã®çšéã«ãå©çšå¯èœã§ãã
以äžã®ç¹åŸŽããããŸã
- FPGAåè·¯ã®DeepLearningåŠç¿ãã¡ã€ã³ã¿ãŒã²ããã«ããŠãã
- 埮åå¯èœLUTã¢ãã«ãçšããŠFPGAã®åè·¯çŽ åã§ããLUTãçŽæ¥åŠç¿ã§ãã
- 極ããŠè»œéã§äœé 延ã®FPGAçšãœãŒã¹(Verilog)ãåºåããããšãã§ãã
- ãã€ããªãããã§ãããé¢ãããStochasticèšç®ã«ããååž°åæãå¯èœ
- Python ãŸã㯠C++ ã§ãããã®èšè¿°ãšåŠç¿ãã§ãã
- GPU(CUDA)ã«å¯Ÿå¿ããŠããé«éã«åŠç¿ã§ãã
埮åå¯èœåè·¯èšè¿°(differentiable circuit description)
ããžã¿ã«åè·¯ã¯éåžžã§ã¯0ã1ã®å€ãããšããªããããéåžžã§ããã°åŸ®åããããšã¯ã§ããŸããã
äžæ¹ã§ãå ¥åºåã0ã1ã§ã¯ãªãã1ã«ãªã確çããšããŠã¢ããã°çã«æ±ãææ³ããããStochasticèšç®ãšåŒã°ããŸãã 幞ããªäºã« Neural Network ã¯ãåŠç¿ã«ãããŠå€ãã®å¯Ÿè±¡ã®å°€åºŠãåãæ±ãçºãã®èãæ¹ã¯çžæ§ã®ããèãæ¹ã§ãã
Stochasticèšç®ãçšãããšãäŸãã°ANDã²ãŒãã¯äºã€ã®å ¥åã®äž¡æ¹ãåæã«1ã«ãªã確çãããªãã¡ç¢ºçã®ä¹ç®åšãšããŠæ¯èããŸãããã®ããã«ãã¹ãŠã®ããžã¿ã«åè·¯ãStochasticèšç®ã«çœ®ãæããããšãå¯èœã§ãã
FPGAãšããããã€ã¹ã¯ãLUTãšåŒã°ããå°ããªã¡ã¢ãªãšãã®ã¡ã¢ãªãéžæããéåäœã§ãã¡ã¢ãªãæžãæããããšã§ããã°ã©ããã«ãªåè·¯èšè¿°ãå®çŸããŸãããã®LUTåè·¯ã埮åå¯èœåè·¯èšè¿°ã«çœ®ãæããã®ã¡ã«ã¡ã¢ãªã«çžåœããéšåã«åŠç¿å¯Ÿè±¡ã®éã¿ä¿æ°ã眮ããŠåŠç¿ãè¡ããããã¯ãŒã¯ã LUT-Network ã§ãã
BinaryBrain 㯠LUT-Network ã®åŠç¿å¯èœæ§ãå®èšŒããããã«äœããããã©ãããã©ãŒã ã§ãã
æ§èœçŽ¹ä»
ãã«ãã€ããªãããã¯ãŒã¯ã§ãé 延æ°ããªç§(1000fps)ã§ã®ç»åèªèã®äŸã§ãã
äžèšã®ãããªåŸ®å°ãªãœãŒã¹éã§åäœå¯èœã§ãã
ããŒã»ãããã³ãšã¯ç°ãªãäžèšã®ãããã¯ãŒã¯ã¢ãã«ãå©çšå¯èœã§ãã (ãã¡ããåŸæ¥ã®ããŒã»ãããã³ã¢ãã«ã§ã®)
äžèšã®ãããªãªã¢ã«ã¿ã€ã ãªã»ãã³ãã£ãã¯ã»ã°ã¡ã³ããŒã·ã§ã³ãå®çŸã§ããŠããŸãã
MNISTãµã³ãã«ã®åããæ¹(C++)
AXV2以éã®åœä»€ã䜿ããCPUãšãWindows7以éã®ç°å¢ãæ³å®ããŠãããŸãã CUDA(Kepler以é)ã«ã察å¿ããŠããŸãã
MNISTã®ãµã³ãã«ã®äœ¿ãæ¹ã¯ samples/mnist/readme.txt ãåç §ãã ããã 以äžã¯ All ãªãã·ã§ã³ã§å èµãããµã³ãã«ãã¹ãŠãå®è¡ãããã®ã§ãã
windows
- install VisualStudio 2022 + CUDA 11.8
- git clone --recursive https://github.com/ryuz/BinaryBrain.git
- download MNIST from http://yann.lecun.com/exdb/mnist/
- decompress MNIST for "\samples\mnist"
- open VC++ solution "samples\mnist\sample_mnist.sln"
- build "x64 Release"
- run
Linux(Ubuntu)
-
install CUDA 11.8
-
build and run
% git clone --recursive https://github.com/ryuz/BinaryBrain.git
% cd BinaryBrain/samples/cpp/mnist
% make
% make dl_data
% ./sample-mnist All
GPUã䜿ããªãå Žå㯠make WITH_CUDA=No ãšããŠäžããã
Google Colaboratory
nvcc ãå©çšå¯èœãª Google Colaboratory ã§ãåäœå¯èœãªããã§ãã 以äžãããŸã§åèã§ãããã©ã³ã¿ã€ã ã®ã¿ã€ããGPUã«èšå®ããäžã§
!git clone --recursive https://github.com/ryuz/BinaryBrain.git
%cd BinaryBrain/cpp/samples/mnist
!make all
!make run
ã®ãããªæäœã§ããã«ãããŠåäœãããããšãã§ããŸãã
MNISTãµã³ãã«ã®åããæ¹(Python)
äœè ã¯çŸåš Python 3.6/3.7 ã«ãŠéçºããŠããŸãã
äºåæºå
å¿ èŠãªããã±ãŒãžãäºåã«ã€ã³ã¹ããŒã«ãã ãã
% pip install setuptools
% pip install pybind11
% pip install numpy
% pip install tqdm
æ¬ãµã³ãã«ã§ã¯ PyTorch ã䜿ããŸãã®ã§ãç°å¢ã«åãã㊠ãã¡ã ããã€ã³ã¹ããŒã«ããŠãããŠãã ããã
Windowsç°å¢ã®å Žåãnvccã®ã»ãã«ã VisualStudio ã® 64bit çãã³ãã³ãã©ã€ã³ããå©çšã§ããããã«ããŠããå¿ èŠããããŸãã äŸãã°ä»¥äžã®ããã«å®è¡ããŠãããŸãã x64 ã®æå®ãéèŠã§ãã
> "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64
ã€ã³ã¹ããŒã«(pipã䜿ãå Žå)
äžèšã®ã³ãã³ããªã©ã§ã€ã³ã¹ããŒã«å¯èœã§ãã
% pip install binarybrain
ã€ã³ã¹ããŒã«(setup.pyã䜿ãå Žå)
äžèšã®ã³ãã³ããªã©ã§ã€ã³ã¹ããŒã«å¯èœã§ãã
% # install
% cd python
% python setup.py install --user
ãµã³ãã«ã®å®è¡
% cd samples/python/mnist
% # Simple DNN sample
% python3 MnistDifferentiableLutSimple.py
% # CNN sample
% python3 MnistDifferentiableLutCnn.py
Google Colaboratory
Google Colaboratory ã§å©çšããå Žåã¯ãã©ã³ã¿ã€ã ã®ã¿ã€ãããGPUãã«ããŠãäžèšãå®è¡ããåŸã«ã©ã³ã¿ã€ã ã®åèµ·åãè¡ãã°å©çšã§ããããã«ãªãã¯ãã§ãã
!pip install pybind11
!git clone --recursive https://github.com/ryuz/BinaryBrain.git
%cd BinaryBrain
!python setup.py install --user
githubããã®ååŸ
çŸåš version4 ã¯äžèšã® branch ã§ç®¡çããŠããŸã
- ver4_develop èè ã®éçºçšãèšé²ã®ããã«ãã«ãäžèœãªãã®ãå ¥ããããšããããŸãã
- ver4_release ãªãªãŒã¹çšãåºæ¬çãªåäœç¢ºèªã¯ããŠããããã«ããŒãžããŠããŸãã
- master çŸåšã¯ ver3 ã®ãªãªãŒã¹çãåæ ã
åºæ¬çãªäœ¿ãæ¹
CPUçã«é¢ããŠã¯ããããªã³ãªãŒã©ã€ãã©ãªãšãªã£ãŠãããããinclude 以äžã«ããããããã¡ã€ã«ãã€ã³ã¯ã«ãŒãããã ãã§ãå©çšããã ããŸãã
GPUã䜿ãå Žåã¯ããããèªã¿èŸŒã¿ã®éã« BB_WITH_CUDA ãã¯ããå®çŸ©ããäžã§ãcuda 以äžã«ããã©ã€ãã©ãªããã«ãããäžã§ãªã³ã¯ããå¿ èŠããããŸãã
ãŸããBB_WITH_CEREAL ãã¯ããå®çŸ©ãããšãéäžçµéã json çµç±ã§ä¿åå¯èœãšãªããŸãã
LUT-Networkãšã¯?
LUT-Networã«ã€ããŠèª¬æããŸãã
ãã¶ã€ã³ãããŒ
FPGAåè·¯ã¯LUTã«ãã£ãŠæ§æãããŠããŸãã ãã®ãã©ãããã©ãŒã ã¯LUTãçŽæ¥åŠç¿ãããŸãã
ç¹åŸŽ
ãœãããŠã§ã¢ã®æé©åã®ææ³ã§å ¥åã®çµã¿åããå šãŠã«å¯ŸããŠãèšç®æžã¿ã®çµæãè¡šã«ããŠãæãããŠããŸããã¯ããã¯ãšããŠããããŒãã«åããšåŒã°ãããã®ããããŸãã ãŸãããã€ããªãããã¯ãŒã¯ã¯åã¬ã€ã€ãŒã®å ¥åºåãïŒå€åãããŠããŸããïŒå€åããŒã¿ã¯äŸãã°0ãš1ã®ïŒçš®ã§è¡šããã®ã§ãäŸãã°32åã®å ¥åãæã¡ã32åã®åºåãæã€ã¬ã€ã€ãŒã®å Žåã32bitã§è¡šçŸå¯èœãª4Gbitã®ããŒãã«ã32åæãŠã°ããã®éãã©ããªèšç®ã§ããããšããŒãã«åå¯èœã§ãã 4Gbitã§ã¯å€§ããããŸãããããŒãã«ãµã€ãºã¯å ¥åãµã€ãºã®2ã®ã¹ãä¹ãšãªãã®ã§ãäŸãã°ããã6å ¥åçšåºŠã®å°ããªãã®ã§ããã°ãããŒãã«ãµã€ãºã¯äžæ°ã«å°ãããªãããã£ã64bitã®ããŒãã«ã«åããããšãå¯èœã§ãã ããã§ãå°ãªãå ¥åæ°ã®åäœã«ãããã¯ãŒã¯ã现ååããŠãå°ããããŒãã«ã沢山çšæããŠãããã¯ãŒã¯ãèšè¿°ããããšèšãè©Šã¿ãLUTãããã¯ãŒã¯ã§ããLUTã¯ã«ãã¯ã¢ããããŒãã«ã®ç¥ã§ãã FPGAã§ã¯ããŒããŠã§ã¢ã®çŽ åãšããŠLUTã倧éã«ä¿æããŠããããã®ããŒãã«ãæžãæããããšã§ããããåè·¯ãå®çŸããŠããŸããç¹ã«Deep Learningã«å©çšããã倧èŠæš¡FPGAã¯ãçŸåš4ïœ6å ¥åã®LUTãäž»æµã§ãã
ããã§ãããŒãã«ãåŒãããšããæŠå¿µã埮åããŠéäŒæ¬ã§åŠç¿ããããšãããšäžæè°ã«æãæ¹ããããããããããŸããã
ããããªããããŒãã«ãåŒããšããè¡çºã¯åè·¯çã«ã¯ã¡ã¢ãªããã«ããã¬ã¯ãµã§éžæããŠããã®ã¿ã§ãã
ããžã¿ã«å路㯠AND ã OR ãªã©ã®è«çåè·¯ã§ãããããã㯠StochasticæŒç®ã«åœãŠã¯ãããšä¹ç®ãªã©ã®äžè¬çãªèšç®ã«åž°çå¯èœã§ãã
StochasticæŒç®ãè¡ãçºã«ã¯æŒç®å¯Ÿè±¡ã確ççãªãã®ã§ãªããã°ãªããŸããããDeepLearningã§æ±ã£ãŠããå€ã¯ ããããããã£ãšãããã(尀床)ãã§ãã£ãŠããã€ããªåãããããšèšã£ãŠå€±ããããã®ã§ã¯ãããŸããã
BinaryBrain ã§ã¯ å ¥å4ïœ6åã®LUT ã䜿ã£ã Network ãéäŒæ¬ã«ãã£ãŠçŽæ¥åŠç¿ãããããšã§ãGPUåãã®ãããã¯ãŒã¯ãFPGAã«ç§»æ€ãããããé¥ãã«é«ãå¹çã§å®è¡ã§ãããããã¯ãŒã¯ãå®çŸå¯èœãšãªããŸããLUTã¯åç¬ã§XORãè¡šçŸã§ãããªã©ãããŒã»ãããã³ãã¢ãã«ãããé«å¯åºŠãªæŒç®ãå¯èœã§ãã ãŸã2å ¥åã®LUTãå®çŸ©ããå Žåãããã¯åãªãããžã¿ã«LSIã®åºæ¬ã²ãŒãçŽ åãã®ãã®ãªã®ã§ãASICèšèšã«å¿çšã§ããå¯èœæ§ããããŸãã
çµåæ°ãLUTã®ããŒãã«ãµã€ãºã§åŸéãããçºãççµåãšãªããŸãããä»ã®ç¹ã«ãããŠã¯ãåŸæ¥çžåœã®åŠç¿èœåãæã£ãäžã§ãæšè«ã«é¢ããŠã¯ç¹ã«FPGAåã«ãããŠã¯é«ãããã©ãŒãã³ã¹ãçºæ®ããŸãã
ãã€ããªå€èª¿ã¢ãã«
BinaryBrainã§ã¯ãã€ããªå€èª¿ããããžã¿ã«å€ãæ±ãããšãåºæ¥ãŸããå€èª¿ãæããã«æ®éã®ãã€ããªãããã¯ãŒã¯ã®åŠç¿ã«BinaryBrainã䜿ãããšã¯ãã¡ããå¯èœã§ããããã®å Žåã¯ïŒå€ããæ±ããªããããååž°åæãªã©ã®å€å€ã®ãã£ããã£ã³ã°ãå°é£ã«ãªããŸãã ãã€ããªå€èª¿ã¢ãã«ã¯äžèšã®ãšããã§ãã
ç¹ã«é£ãã話ã§ã¯ãªãDçŽã¢ã³ã(ããžã¿ã«ã¢ã³ã)ãã1bit-ADC ãªã©ãåºã䜿ãããŠãããã€ããªå€èª¿ã®å¿çšã«éããŸããã æšä»ã®ããžã¿ã«ã¢ã³ãã¯å éšã§ã¯2å€ãæ±ã£ãŠããã®ã«ã人éã®è³ã«å±ããšãã«ã¯ã¢ããã°ã®çŸããé³ãšããŠèãããŸãã
ãã€ããªå€èª¿ã¯ãéååãè¡ãéã«ããé«ãåšæ³¢æ°ã§ãªãŒããŒãµã³ããªã³ã°ããããšã§ããã€ããªä¿¡å·ã®äžã«å ã®æ å ±ãå£åãããã«éååãè©Šã¿ãŸãããã€ããªãããã¯ãŒã¯èªäœã¯ãã®ãããªãã€ããªãåæã«åŠç¿ãè¡ããŸããã極ããŠå°ããªåè·¯èŠæš¡ã§å€§ããªæ§èœãçºæ®ããŸãã ããã¯ãå ã®å€å€ã«åŸã£ã確çã§0ãš1ãåã確çå€æ°ã«å€æããŠæ±ããšããæŠå¿µã§ãããStochasticæ§ãäžããŠãããšç解ããã ããã°ããããšæããŸãã
ã©ã€ã»ã³ã¹
çŸåšMITã©ã€ã»ã³ã¹ãæ¡çšããŠããŸããlisense.txtãåç §ãã ããã
fpgax #11 ïŒ TFUG ããŒãéšïŒDNNå°çšããŒãã«ã€ããŠèªãäŒ(2019/02/02) ã«ãŠçºè¡šãããŠé ããŸãã
https://fpgax.connpass.com/event/115446/
ICCE2019(Berlin)ã«ãŠçºè¡šãããŠé ããŸãã
@FIssikiæ§ã®å€å€§ãªããååã®ããšãICCE2019(Berlin)ã«ãŠçºè¡šããŠãããŸãã
2019 IEEE 9th International Conference on Consumer Electronics (ICCE-Berlin) <slide> <pdf>
https://ieeexplore.ieee.org/document/8966187
äœè æ å ±
æžäž ç«åž(Ryuji Fuchikami)
- e-mail : [email protected]
- github : https://github.com/ryuz
- web-site : http://ryuz.my.coocan.jp/
- tech-blog : https://ryuz.hatenablog.com/
- blog : http://ryuz.txt-nifty.com
- twitter : https://twitter.com/ryuz88
- facebook : https://www.facebook.com/ryuji.fuchikami
åèã«ãããŠé ããæ å ±
-
ããã€ããªãã¥ãŒã©ã«ããããšããŒãããŠã§ã¢ã®é¢ä¿
https://www.slideshare.net/kentotajiri/ss-77136469 -
BinaryConnect: Training Deep Neural Networks with binary weights during propagations
https://arxiv.org/pdf/1511.00363.pdf -
Binarized Neural Networks
https://arxiv.org/abs/1602.02505 -
Binarized Neural Networks: Training Deep Neural Networks with Weights and Activations Constrained to +1 or -1
https://arxiv.org/abs/1602.02830 -
XNOR-Net: ImageNet Classification Using Binary Convolutional Neural Networks
https://arxiv.org/abs/1603.05279 -
Xilinx UltraScale Architecture Configurable Logic Block User Guide
https://japan.xilinx.com/support/documentation/user_guides/ug574-ultrascale-clb.pdf