preface

First, a few important concepts emerge from this article:

Function Compute: Function Compute is an event-driven service that lets the user write code and upload it instead of managing the server. Function computing prepares computing resources and runs user code on an elastic scale, with users paying only for the resources consumed by the actual code running. Function calculation refer to more information. Fun: Fun is a tool to support Serverless application deployment, helping you easily manage functions, API gateways, logging services, and more. It helps you develop, build, and deploy through a resource configuration file (template.yml). More documentation references for Fun.

Note: The tips described in this article require Fun version 3.2.0 or greater.

Depend on the tool

This project was developed under MacOS, the tools involved are platform independent, and should be equally applicable to Linux and Windows desktops. Before starting this example, ensure that the following tools have been correctly installed, updated to the latest version, and configured correctly.

  • Docker
  • Fun
  • Fcli

Fun and Fcli tools rely on Docker to emulate local environments. For MacOS users homebrew can be used to install:

brew cask install docker
brew tap vangie/formula
brew install fun
brew install fcli
Copy the code

For Windows and Linux users, see:

  1. Github.com/aliyun/fun/…
  2. Github.com/aliyun/fcli…

Once installed, remember to run Fun Config to initialize the configuration.

Note that if you have fun installed, make sure fun is 3.2.0 or older.

$fun - version 3.2.2Copy the code

background

A typical application scenario of the AI model serving is function calculation. After the data scientist has trained the model, he or she often needs to work with software engineers to translate the model into a system or service. This process is often referred to as Model serving. The operation – free and elastic scaling of function computing is exactly what data scientists want for highly available distributed systems. This article introduces an example of deploying a TensorFlow Charrnn-trained model for automatic quatrains to function calculations.

Almost all FaaS platforms have code package limits to reduce platform cold starts, and function computation is no exception. Since Python TensorFlow relies on libraries and trained models for hundreds of megabytes of files, even compression is far beyond the 50M code package size limit of function calculations. For such large files, the Fun tool for function calculation command line natively supports this heavy dependency deployment (version 3.2.0 and up). Follow the wizard’s instructions.

Quick start

1. Clone Poetry Project

git clone https://github.com/vangie/poetry.git
Copy the code

2. Install dependencies

Because the script to train the model is time-consuming, the trained model is stored in the Model directory ahead of time. If you want to retrain the model, just make train.

$ fun install
using template: template.yml
start installing functiondependencies without docker building poetry/poetry Funfile exist, Fun will use container to build forcely Step 1/3 : Two-thirds FROM registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-python3.6:build-1.7.7 -- - > 373 f5819463b Step: 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 copyingfunction 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
Copy the code

3. Run functions locally

The fun Local invoke is invoked to run the function locally, and the correct return is as follows:

$ fun local invoke poetry
Missing invokeName argument, Fun will use the first functionPoetry /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 ....... (omitted part of the log) Dog difference flower shangshui wind, January in autumn. No one goes to the river, mountains do not know. Jiangshan a middle road, and not at that time. Rivers and rivers do not know where, Jiangyang nowhere. Mountain wind blowing water color, autumn water into the clouds. Water and moon meet each other more, mountain city into the water. Jiangyun everywhere, spring water does not return. Wild temple spring river far, autumn wind falls on the deep moon. RequestId: 938334c4-5407-4a72-93e1-6d59e52774d8 Billed Duration: 14074 ms Memory Size: 1998 MB Max Memory Used: 226 MBCopy the code

4. Deploy functions

Deploy the function with Fun Deploy and upload the function dependency to the NAS.

fun deploy
Copy the code

Fun automatically deploits dependencies, and when Fun Deploy detects that packaged dependencies exceed the platform limit (50M), it goes to the configuration wizard to help users automate the configuration.

After selecting “Y”, nothing else needs to be done until deployment is complete.

5. Run the remote function

Call a remote function with A Fun Invoke (you can also compute a console call with a function) :

$ fun invokeusing 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.47MS, Duration: 18700 MS, Memory Size: 2048 MB, Max Memory Used: 201.10 MB ========= FC invoke Logs end ========= FC invoke Result: Service does not know this month, not every year. What has no time to go, who can die. I do not know the infinite, acacia in the mountains. Why not know guests, when not sometimes. Friends see nothing, not the heart. No year, when in the hometown. If you don't know the road on the mountain, you are not the same person.Copy the code

At this point, the poem creation program has been successfully deployed to function calculation.

More reference

  1. Deep Learning: 21 projects based on TensorFlow
  2. Develop proper posture for function computations – Fun automates NAS configuration
  3. Develop proper posture for function computations – use Fun NAS to manage NAS resources

“Alibaba Cloud originators pay close attention to technical fields such as microservice, Serverless, container and Service Mesh, focus on cloud native popular technology trends and large-scale implementation of cloud native, and become the technical circle that knows most about cloud native developers.”