/usr/local/lib/python3.6/site-packages/transformers/commands/__pycache__
NameSizeModeActions
add_new_model.cpython-36.pyc65310644editdlrm
add_new_model_like.cpython-36.pyc426880644editdlrm
convert.cpython-36.pyc49430644editdlrm
download.cpython-36.pyc16600644editdlrm
env.cpython-36.pyc26050644editdlrm
lfs.cpython-36.pyc72440644editdlrm
run.cpython-36.pyc33720644editdlrm
serving.cpython-36.pyc67480644editdlrm
train.cpython-36.pyc45890644editdlrm
transformers_cli.cpython-36.pyc12610644editdlrm
user.cpython-36.pyc84530644editdlrm
__init__.cpython-36.pyc7940644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/transformers/commands/__pycache__/serving.cpython-36.pyc (6748B)
3 Eg[ @s2ddlmZmZddlmZmZmZddlmZm Z m Z ddl m Z ddl mZyLddlmZmZmZdd lmZdd lmZdd lmZdd lmZd ZWn(eefk reZddZdZYnXe jdZ edddZ!GdddeZ"GdddeZ#GdddeZ$GdddeZ%GdddeZ&dS) )ArgumentParser Namespace)AnyListOptional)Pipelineget_supported_taskspipeline)logging)BaseTransformersCLICommand)BodyFastAPI HTTPException)APIRoute) BaseModel) JSONResponse)runTcOsdS)N)xyrrG/usr/local/lib/python3.6/site-packages/transformers/commands/serving.pyr"srFztransformers-cli/serving)argscCs:t|j|jr|jnd|j|j|jd}t||j|j|j S)z~ Factory function used to instantiate serving server from provided command line arguments. Returns: ServeCommand N)taskmodelconfig tokenizerdevice) r rrrrr ServeCommandhostportworkers)rZnlprrrserve_command_factory+s r#c@seZdZUdZedS)ServeModelInfoResultz" Expose model information N)__name__ __module__ __qualname____doc__dictinfosrrrrr$;s r$c@s&eZdZUdZeeeee dS)ServeTokenizeResultz Tokenize result model N) r%r&r'r(rstrtokensrint tokens_idsrrrrr+Cs r+c@seZdZUdZedS)ServeDeTokenizeResultz! DeTokenize result model N)r%r&r'r(r,textrrrrr0Ls r0c@seZdZUdZedS)ServeForwardResultz Forward result model N)r%r&r'r(routputrrrrr2Ts r2c@seZdZeedddZeeeedddZ ddZ d d Z e d d d e dd d fee dddZe d d d e dd d e d d d feee e dddZe d d d fddZd S)r)parsercCs|jddd}|jdttdd|jdtdd d |jd td d d |jdtddd |jdtdd|jdtdd|jdtdd|jdtddd |jtddS)z Register this command to argparse so it's available for the transformer-cli Args: parser: Root parser to register command-specific arguments ZservezFCLI tool to run inference requests through REST and GraphQL endpoints.)helpz--taskzThe task to run the pipeline on)typechoicesr5z--host localhostz$Interface the server will listen on.)r6defaultr5z--porti"z Port the serving will listen to.z --workersr zNumber of http workersz--modelz%Model's name or path to stored model.)r6r5z--configz,Model's config name or path to stored model.z --tokenizerzTokenizer name to use.z--devicezSIndicate the device to run onto, -1 indicates CPU, >= 0 indicates GPU (default: -1))funcN) add_parser add_argumentr,r r. set_defaultsr#)r4Z serve_parserrrrregister_subcommand]s& z ServeCommand.register_subcommand)r r r!r"c Cs||_||_||_||_ts&tdnttjd|d|tt d|j t t dgdt d|j tt dgdt d |jtt dgdt d |jtt dgdgd d |_dS) NzUsing serve command requires FastAPI and uvicorn. Please install transformers with [serving]: pip install "transformers[serving]".Or install FastAPI and uvicorn separately.zServing model over :/GET)Zresponse_modelresponse_classmethodsz /tokenizePOSTz /detokenizez/forwardiX)Zroutestimeout) _pipeliner r!r"_serve_dependencies_installed RuntimeErrorloggerinforr model_infor$rtokenizer+ detokenizer0forwardr2_app)selfr r r!r"rrr__init__|sD zServeCommand.__init__cCst|j|j|j|jddS)N)r r!r")rrPr r!r")rQrrrrszServeCommand.runcCstt|jjjdS)N)r*)r$varsrGrr)rQrrrrLszServeCommand.model_infoNT)embedF) text_input return_idscCsxy:|jjj|}|r.|jjj|}t||dSt|dSWn8tk rr}ztddt|ddWYdd}~XnXdS)z Tokenize the provided input and eventually returns corresponding tokens id: - **text_input**: String to tokenize - **return_ids**: Boolean flags indicating if the tokens have to be converted to their integer mapping. )r-r/)r-i)rerror) status_codedetailN)rGrrMZconvert_tokens_to_idsr+ Exceptionrr,)rQrUrVZ tokens_txtr/errrrMs zServeCommand.tokenize)r/skip_special_tokenscleanup_tokenization_spacescCs\y|jjj|||}td|dStk rV}ztddt|ddWYdd}~XnXdS)a: Detokenize the provided tokens ids to readable text: - **tokens_ids**: List of tokens ids - **skip_special_tokens**: Flag indicating to not try to decode special tokens - **cleanup_tokenization_spaces**: Flag indicating to remove all leading/trailing spaces and intermediate ones. rW)rr1i)rrX)rYrZN)rGrdecoder0r[rr,)rQr/r]r^Z decoded_strr\rrrrNs  zServeCommand.detokenizecsft|dkrtggdSy|j|}t|dStk r`}ztddt|iWYdd}~XnXdS)zF **inputs**: **attention_mask**: **tokens_type_ids**: r)r3Z attention)r3irXN)lenr2rGr[rr,)rQinputsr3r\rrrrOs    zServeCommand.forward)r%r&r' staticmethodrr?rr,r.rRrrLrboolrMrrNrOrrrrr\s2&  " rN)'argparserrtypingrrrZ pipelinesrr r utilsr rWr ZfastapirrrZfastapi.routingrZpydanticrZstarlette.responsesrZuvicornrrH ImportErrorAttributeErrorobject get_loggerrJr#r$r+r0r2rrrrrs,