Package: bminf
BMInfEfficient Inference for Big ModelsOverview•Installation•Quick Start•简体中文What's New2022/07/31 (BMInf 2.0.0) BMInf can now be applied to any transformer-based model.2021/12/21 (BMInf 1.0.0) Now the package no more depends oncupyand supports PyTorch backpropagation.2021/10/18 We updated thegenerateinterface and added a new CPM 2.1 demo.2021/09/24 We publicly released BMInf on the 2021 Zhongguancun Forum (AI and Multidisciplinary Synergy Innovation Forum).Note:README forBMInf-1can be found inold_docsdirectory. Examples of CPM-1/2 and EVA will be published soon.OverviewBMInf (Big Model Inference) is a low-resource inference package for large-scale pretrained language models (PLMs).BMInf supports running models with more than 10 billion parameters on a single NVIDIA GTX 1060 GPU in its minimum requirements. Running with better GPUs leads to better performance. In cases where the GPU memory supports the large model inference (such as V100 or A100), BMInf still has a significant performance improvement over the existing PyTorch implementation.If you use the code, please cite the followingpaper:@inproceedings{han2022bminf,
	title={BMInf: An Efficient Toolkit for Big Model Inference and Tuning},
	author={Han, Xu and Zeng, Guoyang and Zhao, Weilin and Liu, Zhiyuan and Zhang, Zhengyan and Zhou, Jie and Zhang, Jun and Chao, Jia and Sun, Maosong},
	booktitle={Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics: System Demonstrations},
	pages={224--230},
	year={2022}
}InstallationFrom pip:pip install bminfFrom source code: download the package and runpython setup.py installHardware RequirementHere we list the minimum and recommended configurations for running BMInf.Minimum ConfigurationRecommended ConfigurationMemory16GB24GBGPUNVIDIA GeForce GTX 1060 6GBNVIDIA Tesla V100 16GBPCI-EPCI-E 3.0 x16PCI-E 3.0 x16GPUs with compute
capability 6.1 or higher are supported by BMInf. Refer to thetableto check whether your GPU is supported.Software RequirementBMInf requires CUDA version >= 10.1 and all the dependencies can be automaticlly installed by the installation process.python>= 3.6torch>= 1.7.1cpm_kernels>= 1.0.9Quick StartUsebminf.wrapperto automatically convert your model.importbminf# initialize your model on CPUmodel=MyModel()# load state_dict before using wrappermodel.load_state_dict(model_checkpoint)# apply wrapperwithtorch.cuda.device(CUDA_DEVICE_INDEX):model=bminf.wrapper(model)Ifbminf.wrapperdoes not fit your model well, you can use the following method to replace it manually.Replacetorch.nn.ModuleListwithbminf.TransformerBlockList.module_list=bminf.TransformerBlockList([# ...],[CUDA_DEVICE_INDEX])Replacetorch.nn.Linearwithbminf.QuantizedLinear.linear=bminf.QuantizedLinear(torch.nn.Linear(...))PerformancesHere we report the speeds of CPM2 encoder and decoder we have tested on different platforms. You can also runbenchmark/cpm2/encoder.pyandbenchmark/cpm2/decoder.pyto test the speed on your machine!ImplementationGPUEncoder Speed (tokens/s)Decoder Speed (tokens/s)BMInfNVIDIA GeForce GTX 10607184.4BMInfNVIDIA GeForce GTX 1080Ti120012BMInfNVIDIA GeForce GTX 2080Ti227519BMInfNVIDIA Tesla V100296620BMInfNVIDIA Tesla A100436526PyTorchNVIDIA Tesla V100-3PyTorchNVIDIA Tesla A100-7CommunityWe welcome everyone to contribute codes following ourcontributing guidelines.You can also find us on other platforms:QQ Group: 735930538WeChat Official Account: OpenBMBWebsite:https://www.openbmb.orgWeibo:http://weibo.cn/OpenBMBTwitter:https://twitter.com/OpenBMBLicenseThe package is released under theApache 2.0License.ReferencesCPM-2: Large-scale Cost-efficient Pre-trained Language Models.Zhengyan Zhang, Yuxian Gu, Xu Han, Shengqi Chen, Chaojun Xiao, Zhenbo Sun, Yuan Yao, Fanchao Qi, Jian Guan, Pei Ke, Yanzheng Cai, Guoyang Zeng, Zhixing Tan, Zhiyuan Liu, Minlie Huang, Wentao Han, Yang Liu, Xiaoyan Zhu, Maosong Sun.CPM: A Large-scale Generative Chinese Pre-trained Language Model.Zhengyan Zhang, Xu Han, Hao Zhou, Pei Ke, Yuxian Gu, Deming Ye, Yujia Qin, Yusheng Su, Haozhe Ji, Jian Guan, Fanchao Qi, Xiaozhi Wang, Yanan Zheng, Guoyang Zeng, Huanqi Cao, Shengqi Chen, Daixuan Li, Zhenbo Sun, Zhiyuan Liu, Minlie Huang, Wentao Han, Jie Tang, Juanzi Li, Xiaoyan Zhu, Maosong Sun.EVA: An Open-Domain Chinese Dialogue System with Large-Scale Generative Pre-Training.Hao Zhou, Pei Ke, Zheng Zhang, Yuxian Gu, Yinhe Zheng, Chujie Zheng, Yida Wang, Chen Henry Wu, Hao Sun, Xiaocong Yang, Bosi Wen, Xiaoyan Zhu, Minlie Huang, Jie Tang.Language Models are Unsupervised Multitask Learners.Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever.