Saravanan666/pypi-org huggingface dataset:
Package: fastga
This repository holds the code base supporting an article submitted to theGECCO 2017conference. Since the article is still being reviewed, the authors’ identitiescannot be disclosedfor the moment. They will be as soon as the reviewing process is over. In the meantime, this repository will be maintained actively by the authors, however using an anonymous account.fastgais an extremely small module sporting our so-calledfast mutation operator(orheavy-tailed mutation operator), which is designed to perform bitwise mutation using a power-law-distributed mutation rate. This allows a high number of bits to be flipped in one step with high probability (compared to the classical (1+1) EA for example), which is especially desirable when such long-distance “jumps” are necessary to escape local optima.Requirementspython3+NumPyInstallationThe pip way (recommended)(Optionnal)Create a python virtual environment and activate it. In a console, type :$ virtualenv ~/some_convenient_location/fastga
$ cd ~/some_convenient_location/fastga
$ source bin/activateIn a console (with your virtualenv activated if you use one), type :$ pip install fastgaThe git waySimply clone this repository to a convenient location :$ mkdir some_convenient_location && cd some_convenient_location
$ git clone https://github.com/FastGA/fast-genetic-algorithms.gitthen add it to yourPYTHONPATH:$ export PYTHONPATH=some_convenient_location:$PYTHONPATH(you can also put this command in your .bashrc file to make it permanent).UsageOur mutation operator is implemented in the classFastMutationOperator, along with the abstract classBaseMutationOperator(which you shouldn’t use directly but rather subclass to your own classes if needed) and the classOnePlusOneMutationOperator(which, as the name suggests, is an implementation of the (1+1) EA). In a python shell, typefrom fastga import FastMutationOperatorTwo parameters are required to create an instance :an integernwhich is the size of the bit strings that can be mutated by the operator ;a floatbeta> 1 which is the exponent used in the mutation rate power law.Given these two parameters, the operator’s mutation rateris such that, for eachiin {1 .. n//2}, the probability thatrisi/nis proportional to i^{-beta} (with a suitable normalization factor). As such, lower values of beta tend to favor a higher number of bits flipped in one mutation step.You can now instantiate an operator :operator = FastMutationOperator(n=100, beta=1.5)and use itsmutatemethod to mutaten-length bit strings :bit_string = [0] * 100
for i in range(10):
    operator.mutate(bit_string, inplace=True)
    print(bit_string)
Package: fastgame
什么是fastgameFastgame是一个帮助你快速构建游戏或简单的GUI界面的python第三方库。内部封装pygame2复杂的API。为什么使用fastgame下面是同样在pygame和fastgame中显示文字的对比使用pygame:importsysimportpygameaspgpg.init()screen=pg.display.set_mode((400,400))pg.display.set_caption('Hello World')font=pg.font.Font(None,16)text=font.render('hello world',True,(0,0,0))whileTrue:screen.blit(text,(0,0))foreventinpg.event.get():ifevent.type==pg.QUIT:pg.quit()sys.exit()pg.display.update()使用fastgame:importfastgameasfggame=fg.FastGame(title='Hello World',size=(400,400))text=fg.Label('hello world')@game.updatedefupdate():text.update()game.mainloop()在哪里查看fastgamegithub网址:https://github.com/stripepython/fastgame文档:https://stripepython.github.io/fastgame-document/document.html
Package: fastGAT
Fast Graph ATtention neural networksWhat's that?Fast Graph ATtention neural networks(fastGAT) is a new algorithm based on GAT(graph attention networks). We designed our algorithm with AngleLSH(Angle based Local Sensity Hashing), for a faster running speed and a less memory usage.
In a word, you can use our algorithm instead of GAT in everywhere with more great effect.How to install it?Just use:pip install fastGATHow to use it?A demo for fast run.you can just use:importfastGAT.fastGATasftproc=ft.exe()proc.tra_val()proc.test()for simple demo, which will running our method in CORA dataset.customize your own hyperparameters.usefromfasGAT.modelimportfastGATasmftblablabla..customize your own datasetjust try the numpy format matrix , which for example：adj: the adj matrix
features: feature vector combination of all nodes
labels: label of all nodesMORE INFORMATIONFor more infomation, you might go to here:fastGATDoes it well?You can enjoy some images follow for the detail of it.concat me.you can send any problem and BUG using the issue in github.  Or call me with:2273067585@qq.com.
Package: fastgedcom
FastGedcomA lightweight tool to parse, browse and edit gedcom files.Install FastGedcom using pip fromits PyPI page:pipinstallfastgedcomFeaturesEasy to write! Free choice of fields, data, and formatting.fromfastgedcom.parserimportstrict_parsefromfastgedcom.helpersimportformat_datedocument=strict_parse("gedcom_file.ged")birth_date=(document["@I1@"]>"BIRT")>="DATE"print(format_date(birth_date))The syntax is flexible and permissive. If you don't like magic operator overloads, you can use standard methods!It supports gedcom files encoded in UTF-8 (with and without BOM), UTF-16 (also named UNICODE), ANSI, and ANSEL.If a field is missing, you will get aFakeLinecontaining an empty string. This help reducing the boiler plate code massively. And, you can differentiate aTrueLinefrom aFakeLinewith a simple boolean check.indi=document["@I13@"]death=indi>"DEAT"ifnotdeath:print("No DEAT field. The person is alive")# Can continue anywayprint("Death date:",format_date((indi>"DEAT")>="DATE"))Typehints for salvation! Autocompletion and type checking make development so much easier.There are only 3 main classes:Document,TrueLine, andFakeLine.There are type aliases for code clarity:Record,XRef,IndiRef,FamRef, and more.Why FastGedcom ?FastGedcom's aim is to keep the code close to your gedcom files. So, you don't have to learn what FastGedcom does, the data you have, is the data you get. The content of the gedcom file is unchanged. The data processing is optional to best suit your needs. FastGedcom is more of a starting point of your data processing than a all-round full-featured librairy.The nameFastGedcomdoesn't just come from its ease of use. Parsing is really fast. And, for getting the relatives of a person as fast as possible, there is theFamilyLinkclass.Hereare the benchmark I used.Documentation and examplesWant to see more code?Here are some examplesThe documentation of FastGedcom is availablehereon ReadTheDocs.FeedbackFeedback are welcome, and they will be greatly appreciated!If you like this project, consider putting a star onGithub, thank you!For any feedback or question, please feel free to contact me by email atgatien.bouyer.dev@gmail.comor viaGithub issues.
Package: fastgen
FastGenA CLI for your next FastAPI Project👀Take A Lookthis is a glanc of the project structure you will have once you useFastGenNavigate Quicklyinstallationcommandsinfonewg✨InstallationUsing pip :$python-mpipinstallfastgenUsing Poetry :$poetryaddfastgen🧭CommandsUsage:$fastgen[OPTIONS]COMMAND[ARGS]...Options:--install-completion: Install completion for the current shell.--show-completion: Show completion for the current shell, to copy it or customize the installation.--help: Show this message and exit.Commands:infonewfastgen infoUsage:$fastgeninfo[OPTIONS]Options:--help: Show this message and exit.fastgen newUsage:$fastgennew[OPTIONS]⭐ProjectNameArguments:⭐ Project Name:requiredOptions:--dir 📁 Directory Path--package-manager 📦 Package Manager: [default: pip]
( Options are pip , poetry )--migrations / --no-migrations: [default: False]--docker / --no-docker: [default: False]--testing / --no-testing: [default: False]--database 📅 Database: [default: postgresql] ( Options are postgresql,mysql,sqlite )--orm ⚙️ ORM: [default: False]--help: Show this message and exit.fastgen gUsage:$fastgeng[OPTIONS]<component><component_name>Available ComponentsComponentIn stockroutergenerates new rotuer at app/api/routersmodelgenerates new sqlmodel or sqlalchemy mode at app/database/modelsschemagenerates new pydantic schema at app/api/schemasOptions--model-type: available only for model components , optional values are ( sqlmodel , sqlalchemy )--path: specifiy where to create the componentRELATIVE TO THE CURRENT WORKING DIRECOTRYif not in default pathNote: the naming is preferred to be in lower case so it can be resolved correctlyArguments🪲Encountered A Problem !feel free to open an issue discussing the problem you faced🤝🏻Contributingplease refer toContribution Guide
Package: fastgenerateapi
FastGenerateApi联系作者Github介绍稳定版本：v0.0.21
建议python版本：3.9+FastGenerateApi 使用说明软件架构说明封装了 快速生成API,包括(增,删,改,查,递归查询,递归删除,关联修改,关联查询)
封装了 新增缓存配置，默认不使用缓存；新增树状查询方案，可配置选择
封装了 Websocket API和分组消息发送
封装了 路由接口路径的灵活配置,返回值字段的灵活配置,分页参数的灵活配置,等其他项
封装了 增,改 对唯一字段的校验,非空字段的校验
封装了 删 对唯一字段追加时间戳格式修改
封装了 查 灵活的筛选,以及swagger文档的自动生成
封装了 通过数据库模型,自动生成schemas,并swagger附带文档
封装了 类方法的实现,增加了相关的钩子函数
封装了 通用性接口,例如excel的导入导出,pdf文件生成,模型数据跨表取值
待封装 RPC的调用使用教程简单使用增删改查进一步优化使用查询筛选文档注意项（本地FastAPI源码修改，上线部署不需要修改）其他接口书写方式websocket 使用配置参数的使用使用说明1. 简单使用数据库模型以 附带的example为例,代码如下启动后自动生成 增,删,改,查 接口app = FastAPI()

class StaffView(APIView):
  model_class = StaffInfo

app.include_router("v1", StaffView())

uvicorn.run(app)注意点：路径自动添加数据库模型转换的字段 "/staff-info"自动添加swagger对应的标签，内容为数据库模型的描述自动通过数据库模型生成对应的所有的schemas2. 增删改查进一步优化使用根据增,删,改,查类，对应成员的填写
数据库模型 class PydanticMeta， 对schemas生成空值:include, excludeinclude: 为兼容手写schemas，推荐只限制数据库模型字段get_one_include, get_one_exclude与include同时生效，无include自动包含数据库模型搜友字段可添加跨表字段，自动生成校验和文档其他字段: ("test", Optioanl[str], FieldInfo(..., description="文档描述"))get_all_include, get_all_excludecreate_include, create_excludeupdate_include, update_exclude待完成...3. 查询筛选文档注意项本地FastAPI源码修改，上线部署不需要修改(fastapi == 0.97.0、0.87.0)源码修改文件路径：fastapi/dependencies/utils.py/第302行可搜索方法：get_dependant...
param_field = get_param_field(
    param=param, default_field_info=params.Query, param_name=param_name
)
############### 添加内容  ####################
try:
	if type(call).__name__ == 'ModelMetaclass' and issubclass(call, BaseModel):
	    param.default.description = call.__fields__.get(param_name).field_info.description  
except:
    ...
##################################
if param_name in path_param_names:
  ...4、其他接口书写方式方法使用规则view 标识符号get/post/put/patch/delete 方法后续字段: 路由路径pk 路径参数,可省略多段路径： view_get_test__testurl .../test/test其他使用与原FastAPI一致class TestSchema(BaseModel):
  test: str
  pk: str

class TestView(BaseView):

  def view_get_test_pk(self, pk: str, name: str) -> TestSchema:
    return self.success(data={
      "test": name,
      "pk": pk
    })

# url = .../test/{pk}5、websocket 使用详情请查看example文件6、配置参数的使用第一步：配置参数的查看如果生成.env.example全局Settings中继承SettingsModelfrom fastgenerateapi import SettingsModel

class Settings(SettingsModel):
    """
        Global settings
    """
    ...第二步：配置参数修改在.env中修改参数值，会自动生效[AppSettings]
# 当前页字段
APP_CURRENT_PAGE_FIELD=page
Package: fastgenius
InstallationpipinstallfastgeniusUsage>>>importfastgenius>>>genius=fastgenius.Genius('client_access_token')>>>genius.get_artist('Madonna')Artist(Madonna)>>>genius.get_artist('Madona')Artist(Madona(D’Lamotta))>>>genius.get_artist(['Madonna','TuPac']){'Madonna':Artist(Madonna),'TuPac':Artist(2Pac)}>>>artists=genius.get_artist(['Madonna','TuPac'])>>>artists['Madonna'].songs[]>>>artists=genius.get_artist(['Madonna','TuPac'],get_songs=True)>>>artists['Madonna'].songs[Song(Madonna-IntotheGroove(ExtendedRemix)),Song(LeoTheKind-MaterialGirl),Song(Madonna-Masterpiece-MDNAWorldTour/Live2012),Song(GeniusPolskaTłumaczenia-Madonna&Quavo-Future),...]>>>artists['Madonna'].songs[0].lyrics"\\nAnd you can dance\\nFor inspiration\\nCome on\\nI'm waiting\\nCome, ...">>>big_syke=genius.get_artist('Big Syke',get_songs=True)>>>len(big_syke.songs)78>>>big_syke=genius.get_artist('Big Syke',get_songs=True,primary_artist_only=True)>>>len(big_syke.songs)17
Package: fast-geodist
fast-geodistAn implementation of theHaversine formulafor calculatingGreat Circle distanceusing Rust andPyO3.This package was started as an experiment for learning how to implement functions in Rust and wrap them for use in python. The Haversine Formula is implemented followinggeorust, with an array-wise implementation written usingndarray::parallel. It is wrapped for python usingMaturinand integratesrust-numpyfor array operations.Installationpip install fast-geodistQuick startThe package provides two main entry points:importnumpyasnpfromfast_geodistimporthaversine# input either a tuple of (lat/lon, lat/lon)result=haversine((1,1,0,0))# or a numpy array of coordinates pairs# useful if lots of distances need to be calculated# will be computed in parallelresult=haversine(np.array([(1,1,0,0),(2,2,0,0)]))BenchmarksThe results of benchmarking show the rust implementation is14x fasterthan the python implementation. This benchmark computes distances on an array containing 1,000,000 pairs of coordinates (seebench.py):--------------------------------------------- benchmark: 2 tests ---------------------------------------------
Name (time in ms)              Min                   Max                  Mean                Median
--------------------------------------------------------------------------------------------------------------
test_benchmark_fast       164.0635 (1.0)        171.7663 (1.0)        168.0218 (1.0)        168.4129 (1.0)
test_benchmark_slow     2,335.4281 (14.23)    2,439.7850 (14.20)    2,395.6077 (14.26)    2,406.6356 (14.29)
--------------------------------------------------------------------------------------------------------------Computed on an Intel i7-1165G7.DevelopmentPrequisites:Python (>=3.7) and makeRust toolchainAfter cloning the repository, the Makefile includes helpful commands for setting up a development environment, linting, formatting, testing, and benchmarking. Get started as follows:# setup a new virtual environmentpython-mvenv.venvsource.venv/bin/activate# install the development dependenciesmakeinstall# check other available commandsmakehelpTooling:Cargo andPytestare used for testing the Rust and Python code respectively (see/tests).Python code is linted usingflake8and formatted usingBlack; rust code withcargo fmtandcargo clippy.pre-commitis used to run these checks locally before files are pushed to gitTheGithub Actions pipelineruns these checks and testsSemantic-releaseis used withconventional commitsfor automated releasing to PyPIReferencesAs well as the excellent PyO3 documentation, the following posts helped with creation of this package:https://blog.yossarian.net/2020/08/02/Writing-and-publishing-a-python-module-in-rusthttps://depth-first.com/articles/2020/08/10/python-extensions-in-pure-rust-with-pyo3/http://saidvandeklundert.net/learn/2021-11-18-calling-rust-from-python-using-pyo3/https://itnext.io/how-to-bind-python-numpy-with-rust-ndarray-2efa5717ed21
Package: fastgif
fastgifPython package for creating a gif utilizing multiprocessing to speed up the process.
The individual plots are saved in a temp directory and are afterwards cleaned.
This takes into account keyboard interrupts as well.Usageimportfastgifimportmatplotlib.pyplotaspltimportnumpyasnpdefget_fig(idx):x_space=np.linspace(0,10,30)+(idx/20)fig,ax=plt.subplots(dpi=150)ax.plot(x_space,np.sin(x_space))ax.grid()ax.set_ylim(-1.2,1.2)ax.set_xlabel('x')ax.set_ylabel('sin(x)')fig.suptitle(f'Sine wave gif')returnfigfastgif.make_gif(get_fig,100,'images/sine.gif',show_progress=True,writer_kwargs={'duration':0.01})Creates the following gif:
Package: fastgm
fastgmFast GMSSL Library for Python基于Cython的快速国密算法Python实现，目前支持SM2, SM3, SM4（ECB、CBC）介绍基于Cython的快速国密算法Python实现，目前支持SM2, SM3, SM4（ECB、CBC）安装教程pip install fastgm使用说明SM2SM2是国家密码管理局发布的椭圆曲线公钥密码算法。对标RSA使用方法：生成秘钥from fastgm import SM2

sk, pk = SM2.generate_key()  # sk为私钥，pk为公钥，均为hex格式使用公钥加密from fastgm import SM2

pk = 'B9C9A6E04E9C91F7BA880429273747D7EF5DDEB0BB2FF6317EB00BEF331A83081A6994B8993F3F5D6EADDDB81872266C87C018FB4162F5AF347B483E24620207' # 公钥，Hex格式

data = b'helloworld' # 待加密内容，格式为bytes数组

sm2 = SM2() # 初始化
enc = sm2.encrypt(pk, data) # 运行加密算法使用私钥解密from fastgm import SM2

sk = '00B9AB0B828FF68872F21A837FC303668428DEA11DCD1B24429D0C99E24EED83D5'  # 私钥

sm2 = SM2() # 初始化

dec = sm2.decrypt(sk, enc) # 运行解密算法，enc为加密内容SM3SM3密码杂凑算法是中国国家密码管理局2010年公布的中国商用密码杂凑算法标准。对标MD5使用方法：from fastgm import SM3
data = b'helloworld'  # 待哈希bytes数组
h = SM3().hash(data)  # 哈希运算SM4SM4.0（原名SMS4.0）是中华人民共和国政府采用的一种分组密码标准。对标AES。使用方法：生成秘钥from fastgm import SM4

key = SM4.generate_key() # key为16位bytes数组Zero Padding ECB加解密from fastgm import SM4

key = b'1' * 16  # key为16位bytes数组
data = b'helloworld' # 待加密内容

sm4 = SM4(key, padding='pkcs7')  # 初始化, padding可选zero, pkcs7。gmssl-python库默认为pkcs7

enc = sm4.encrypt_ecb(data) # 加密
dec = sm4.decrypt_ecb(enc)  # 解密PKCS7 Padding CBC加解密from fastgm import SM4

key = b'1' * 16  # key为16位bytes数组
iv = b'2' * 16  # 初始化向量, iv为16位bytes数组
data = b'helloworld' # 待加密内容

sm4 = SM4(key, padding='pkcs7')  # 初始化, padding可选zero, pkcs7。gmssl-python库默认为pkcs7

enc = sm4.encrypt_cbc(iv, data) # 加密
dec = sm4.decrypt_cbc(iv, enc)  # 解密benchmark以SM4为例，加密1024个helloworld，共计10240个字符，只需约0.3ms。纯Python实现的gmssl-python需要约171ms。fastgm（本方法）gmssl-pythoncrytographysm229.9 ms ± 1.39 ms1.12 s ± 22.3 ms未提供sm3802 µs ± 21.4 µs111 ms ± 10.4 ms未提供sm4299 µs ± 6.61 µs170 ms ± 1.22 ms283 µs ± 6.57 µs测试环境，Intel 8265U，WSL2。参考[1]https://github.com/guanzhi/GmSSL[2]https://github.com/duanhongyi/gmssl[3]https://github.com/gongxian-ding/gmssl-python[4]https://github.com/pyca/cryptography
Package: fastgm-whl
fastgmFast GMSSL Library for Python基于Cython的快速国密算法Python实现，目前支持SM2, SM3, SM4（ECB、CBC）介绍基于Cython的快速国密算法Python实现，目前支持SM2, SM3, SM4（ECB、CBC）安装教程pip install fastgm使用说明SM2SM2是国家密码管理局发布的椭圆曲线公钥密码算法。对标RSA使用方法：生成秘钥from fastgm import SM2

sk, pk = SM2.generate_key()  # sk为私钥，pk为公钥，均为hex格式使用公钥加密from fastgm import SM2

pk = 'B9C9A6E04E9C91F7BA880429273747D7EF5DDEB0BB2FF6317EB00BEF331A83081A6994B8993F3F5D6EADDDB81872266C87C018FB4162F5AF347B483E24620207' # 公钥，Hex格式

data = b'helloworld' # 待加密内容，格式为bytes数组

sm2 = SM2() # 初始化
enc = sm2.encrypt(pk, data) # 运行加密算法使用私钥解密from fastgm import SM2

sk = '00B9AB0B828FF68872F21A837FC303668428DEA11DCD1B24429D0C99E24EED83D5'  # 私钥

sm2 = SM2() # 初始化

dec = sm2.decrypt(sk, enc) # 运行解密算法，enc为加密内容SM3SM3密码杂凑算法是中国国家密码管理局2010年公布的中国商用密码杂凑算法标准。对标MD5使用方法：from fastgm import SM3
data = b'helloworld'  # 待哈希bytes数组
h = SM3().hash(data)  # 哈希运算SM4SM4.0（原名SMS4.0）是中华人民共和国政府采用的一种分组密码标准。对标AES。使用方法：生成秘钥from fastgm import SM4

key = SM4.generate_key() # key为16位bytes数组Zero Padding ECB加解密from fastgm import SM4

key = b'1' * 16  # key为16位bytes数组
data = b'helloworld' # 待加密内容

sm4 = SM4(key, padding='pkcs7')  # 初始化, padding可选zero, pkcs7。gmssl-python库默认为pkcs7

enc = sm4.encrypt_ecb(data) # 加密
dec = sm4.decrypt_ecb(enc)  # 解密PKCS7 Padding CBC加解密from fastgm import SM4

key = b'1' * 16  # key为16位bytes数组
iv = b'2' * 16  # 初始化向量, iv为16位bytes数组
data = b'helloworld' # 待加密内容

sm4 = SM4(key, padding='pkcs7')  # 初始化, padding可选zero, pkcs7。gmssl-python库默认为pkcs7

enc = sm4.encrypt_cbc(iv, data) # 加密
dec = sm4.decrypt_cbc(iv, enc)  # 解密benchmark以SM4为例，加密1024个helloworld，共计10240个字符，只需约0.3ms。纯Python实现的gmssl-python需要约171ms。fastgm（本方法）gmssl-pythoncrytographysm229.9 ms ± 1.39 ms1.12 s ± 22.3 ms未提供sm3802 µs ± 21.4 µs111 ms ± 10.4 ms未提供sm4299 µs ± 6.61 µs170 ms ± 1.22 ms283 µs ± 6.57 µs测试环境，Intel 8265U，WSL2。参考[1]https://github.com/guanzhi/GmSSL[2]https://github.com/duanhongyi/gmssl[3]https://github.com/gongxian-ding/gmssl-python[4]https://github.com/pyca/cryptography
Package: fastgoertzel
fastgoertzelA Python implementation of the Goertzel algorithm built usingRustfor improved run time and efficiency on large datasets and loops.To-Do:Improved speed.(Significantly increased speed by using numpy arrays).Implement benchmarking for speed comparison.Add IIR and k-th FTT implementation of Goertzel.Add support for sampling rate.InstallationYou can install using two methods:Usingpip install:$pipinstallfastgoertzelUsingmaturinafter cloning repository:$gitclonegit://github.com/0zean/fastgoertzel.git
$cdfastgoertzel
$maturindevelopUsageimportnumpyasnpimportpandasaspdimportfastgoertzelasGdefwave(amp,freq,phase,x):returnamp*np.sin(2*np.pi*freq*x+phase)x=np.arange(0,512)y=wave(1,1/128,0,x)amp,phase=G.goertzel(y,1/128)print(f'Goertzel Amp:{amp:.4f}, phase:{phase:.4f}')# Compared to max amplitude FFT outputft=np.fft.fft(y)FFT=pd.DataFrame()FFT['amp']=np.sqrt(ft.real**2+ft.imag**2)/(len(y)/2)FFT['freq']=np.fft.fftfreq(ft.size,d=1)FFT['phase']=np.arctan2(ft.imag,ft.real)max_=FFT.iloc[FFT['amp'].idxmax()]print(f'FFT amp:{max_["amp"]:.4f}, 'f'phase:{max_["phase"]:.4f}, 'f'freq:{max_["freq"]:.4f}')
Package: fastgplearn
FastGPLearnWelcome to FastGPLearn.FastGPLearn implements Genetic Programming in Python, with ascikit-learninspired and compatible API.
And the FastGPLearn applied thetorchandnumpybackend for fast calculated, make it accessible forCUDA.FastGPLearn inspired bygplearn,BGP,Documentfastgplearn document (English)fastgplearn document (Chinese)writing...Quick InstallpipinstallfastgplearnLicenseMIT LicenceContactDeveloper: boliqq07:986798607@qq.comSupport
Package: fastgpt
fastgptfastgpt 是什么fastgpt是一个基于transformers和onnxruntime的python库，可以无缝衔接的使用 onnxruntime 量化后的 transfromers GPT 模型做文本生成任务，提高推理速度、降低资源成本。fastgpt 的背景GPT模型是通过序列文本预测下一个词的训练任务得到的预训练模型，可以在文本生成任务上达到很好的效果。transformers库是近些年最火的做预训练模型的 python 库，在其背后的社区，网友、组织分享开源了各式各样的预训练模型，尤其是截止 2022 年 6 月 23 日，社区的开源文本生成模型多达到5068个。onnx是由微软，亚马逊 ，Facebook 和 IBM 等公司共同开发的，针对机器学习所设计的开放式的文件格式，经过 onnxruntime 量化压缩的预训练模型，在 cpu 硬件上推理速度在各开源框架的对比中首屈一指。然而，通过transformers官方的 onnx 接口转换、onnx 量化 API，却没有做好 GPT 模型转换的兼容问题，经常转换失败。而手动进行 onnx 转换需要自定义很多配置，对于新手不很友好。fastgpt库，就是为了无缝衔接 transformers 库调用 GPT 模型转换 onnx 格式推理，使用者可以在仅修改两行代码的情况下，使用 onnx 量化后的 GPT 模型，做 transformers 库的文本生成函数。原 transformers 代码：fromtransformersimportAutoModelForCausalLMmodel=AutoModelForCausalLM.from_pretrained("distilgpt2")fastgpt 代码：fromfastgptimportCausalLMModelForOnnxGenerationmodel=CausalLMModelForOnnxGeneration.from_pretrained("distilgpt2")在 fastgpt 这一行代码中，会执行以下流程transformers hub 的模型下载pytorch 模型推理，输出 logitsonnx 格式转换onnx 格式模型推理，输出 logits，进行对比差异onnx 量化onnx 量化格式模型推理，输出 logits，进行对比差异把兼容 transformers 文本生成函数的 onnx 格式 GPT 模型，包装到 model 中安装pipinstallfastgpt快速 demofromtransformersimportAutoTokenizerfromfastgptimportCausalLMModelForOnnxGenerationmodel=CausalLMModelForOnnxGeneration.from_pretrained("distilgpt2")tokenizer=AutoTokenizer.from_pretrained("distilgpt2")prompt_text="Natural language processing (NLP) is the ability of a computer program to understand human language as it is spoken and written"input_ids=tokenizer(prompt_text,return_tensors="pt",add_special_tokens=False).input_idsgenerated_ids=model.generate(# 这里完全兼容transformers的generate函数input_ids,max_length=64+input_ids.shape[1],decoder_start_token_id=tokenizer.cls_token_id,eos_token_id=tokenizer.sep_token_id,output_scores=True,temperature=1,repetition_penalty=1.0,top_k=50,top_p=0.9,do_sample=True,num_return_sequences=1,length_penalty=2.0,early_stopping=True,)print(tokenizer.decode(generated_ids[0],skip_special_tokens=True))print("="*20)fastgpt 的优点兼容 transformers: 基于 transformers 库的文本生成函数，功能非常丰富。fastgpt 在 onnx 格式模型上，兼容该函数。兼容 cache: 在文本生成的一个个 token 生成过程中的past_key_value需要在 GPT 模型上持续迭代输入，fastgpt 已经通过 onnx 格式做好衔接。代码修改低成本：代码替换原版 transformers 仅需修改两行代码。onnx 格式占内存小：对于 distilgpt2 模型，torch 版318MB, onnx 量化版243MBcpu 上速度更快: 用时约降低33%生成速度评测(ms)生成长度 4 评测模型框架beam:1beam:2beam:3beam:4torch290.779475.693560.458648.756fastgpt195.265292.272378.933466.14生成长度 8 评测模型框架beam:1beam:2beam:3beam:4torch482.199817.065905.6461052.983fastgpt341.735471.028583.264713.009生成长度 16 评测模型框架beam:1beam:2beam:3beam:4torch878.3381518.1981619.3361813.197fastgpt635.157838.7871009.4971210.047生成长度 32 评测模型框架beam:1beam:2beam:3beam:4torch1661.8192854.8893081.5853436.284fastgpt1238.5851599.7241921.7852256.674生成长度 64 评测模型框架beam:1beam:2beam:3beam:4torch3257.9294274.2014256.854677.168fastgpt2510.4843081.8512697.2963150.157model name : Intel(R) Xeon(R) CPU E5-2673 v4 @ 2.30GHz
cpu cores : 2详见 GITHUB ACTIONS 的cml 报告补充对于CodeGen系列代码生成模型，官方是不支持transformers库的，因此不能直接用fastgpt加载，请转至example/codegen进行onnx量化和文本生成感谢transformersfastT5onnxruntime