Rapid build Serverless AI applications: you write poetry

Foreword

First introduced in several important concepts under article appears:

Function calculates (Function Compute) : function calculates is an event-driven service, by computing function, users need to manage the operation of the servers, just write code and upload. Function calculates ready to computing resources, and is elastically stretchable run user code, and users only need to pay according to the actual code that runs resources consumed. More information function calculation reference .
Fun : Fun is a tool used to support Serverless application deployment, can help you easily manage function computing, API Gateway, logging services and other resources. It is through a resource configuration file (template.yml), help you develop, build, deploy operation. More Fun document reference .

Note: This tip requires Fun version 3.2.0 or greater.

Dependent tools

This project is developed under MacOS, tool involved is platform-independent, Linux and Windows for desktop systems should also apply. Before starting this example, make sure the following tools have been correctly installed, update to the latest version and configured correctly.

Fun and Fcli tools rely on the docker to simulate the local environment.
For MacOS user can use homebrew installation:

brew cask install docker
brew tap vangie/formula
brew install fun
brew install fcli

Windows and Linux users to install, please refer to:

  1. https://github.com/aliyun/fun/blob/master/docs/usage/installation.md
  2. https://github.com/aliyun/fcli/releases

After installation, remember to perform fun configinitialization at the configuration.

Note that if you have already installed a fun, ensure fun versions 3.2.0 or higher.

$ fun --version
3.2.2

background

AI model serving as a function of computing a typical application scenario. Data scientists often need training to find a good model for future software engineers to become a model system or service, usually this process is called model serving. Operation and maintenance functions without the need to calculate and resilient and elastic properties, exactly in line with the demands of high-availability data scientists distributed systems. This article describes the training of a TensorFlow CharRNN Five-character quatrains model automatically write poetry deployed to the example of a function calculation.

FaaS substantially all of the platforms to reduce cold start platform, the code will be provided to limit the package, function calculation is no exception. Since python TensorFlow library dependencies and models trained several hundred, even well above the compression function to calculate 50M code package size limit. For such a large volume of documents, Fun function calculates the command line tool natively supports the deployment of such a large dependence (3.2.0 or later), you can follow the prompts in the wizard.

Quick Start

1. cloning poetry project

git clone https://github.com/vangie/poetry.git

2. Installation depends

Since the training script model is time-consuming, so the trained models have been stored in advance in the model directory. If you want to re-train model, the implementation make traincan be.

$ fun install
using template: template.yml
start installing function dependencies without docker

building poetry/poetry
Funfile exist, Fun will use container to build forcely
Step 1/3 : FROM registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-python3.6:build-1.7.7
 ---> 373f5819463b
Step 2/3 : WORKDIR /code
 ---> Using cache
 ---> f9f03330ddde
Step 3/3 : RUN fun-install pip install tensorflow
 ---> Using cache
 ---> af9e756d07c7
sha256:af9e756d07c77ac25548fa173997065c9ea8d92e98c760b1b12bab1f3f63b112
Successfully built af9e756d07c7
Successfully tagged fun-cache-1b39d414-0348-4823-b1ec-afb05e471666:latest
copying function artifact to /Users/ellison/poetry
copy from container /mnt/auto/. to localNasDir

Install Success

Tips for next step
======================
* Invoke Event Function: fun local invoke
* Invoke Http Function: fun local start
* Build Http Function: fun build
* Deploy Resources: fun deploy

3. Functions run locally

Perform fun local invokefunctions that can be run locally, the right to return as follows:

$ fun local invoke poetry
Missing invokeName argument, Fun will use the first function poetry/poetry as invokeName

skip pulling image aliyunfc/runtime-python3.6:1.7.7...
FunctionCompute python3 runtime inited.
FC Invoke Start RequestId: b125bd4b-0d23-447b-8d8c-df36808a458b
.......(省略了部分日志)
犬差花上水风,一月秋中时。
江水无人去,山山有不知。
江山一中路,不与一时还。
山水不知处,江阳无所逢。
山风吹水色,秋水入云中。
水月多相见,山城入水中。
江云无处处,春水不相归。
野寺春江远,秋风落月深。

RequestId: 938334c4-5407-4a72-93e1-6d59e52774d8          Billed Duration: 14074 ms       Memory Size: 1998 MB    Max Memory Used: 226 MB

4. Deploy function

By fun deploydeploying upload function and functional dependencies to nas.

fun deploy

fun is done automatically rely on the deployment, when the fun deploy detected packed platform dependent than limit (50M), will enter the configuration wizard to help users automate configuration.

image.png

After selecting "Y" do not need to do other things, you can wait until the deployment is complete.

5. Run remote function

By fun invoke remote function call (you can also function calculation console call):

$ fun invoke
using template: template.yml

Missing invokeName argument, Fun will use the first function poetry/poetry as invokeName

========= FC invoke Logs begin =========
省略部分日志...
Restored from: /mnt/auto/model/poetry/model-10000
FC Invoke End RequestId: c0d7947d-7c44-428e-a5a0-30e6da6d1d0f

Duration: 18637.47 ms, Billed Duration: 18700 ms, Memory Size: 2048 MB, Max Memory Used: 201.10 MB
========= FC invoke Logs end =========

FC Invoke Result:
役不知此月,不是无年年。
何事无时去,谁堪得故年。
不知无限处,相思在山山。
何必不知客,何当不有时。
相知无所见,不得是人心。
不得无年日,何时在故乡。
不知山上路,不是故人人。

So far, the program has been successfully deployed to create poetry function is calculated.

More Reference

  1. 21 Fun deep learning project - based on the experience of Detailed TensorFlow
  2. Development function calculates the correct posture - Fun NAS Configuration Automation
  3. Development function calculates the correct posture - Fun NAS using the NAS Management Resources

" Alibaba Cloud native concern micro service, Serverless, container, Service Mesh and other technical fields, focusing cloud native popular technology trends, cloud native large-scale landing practice, most do understand the developer's native cloud technology circles."

Guess you like

Origin www.cnblogs.com/alisystemsoftware/p/12132611.html