Create an AI-Powered Poem Generator Using Alibaba Cloud Function Compute

This article explains how Alibaba Cloud Function Compute can be used for AI model serving, walks through a three‑step deployment of a TensorFlow‑based Chinese poem generator, compares serverless with traditional ECS setups, and discusses cold‑start mitigation, cost optimization, and monitoring features.

Alibaba Cloud Native
Alibaba Cloud Native
Alibaba Cloud Native
Create an AI-Powered Poem Generator Using Alibaba Cloud Function Compute

Function Compute and AI Inference

Function Compute (FC) is Alibaba Cloud's serverless Function‑as‑a‑Service platform. It runs code in response to events such as OSS, MNS or API Gateway and provides built‑in logging, monitoring and automatic scaling. For AI inference, a trained model can be packaged and exposed as an HTTP endpoint, enabling low‑latency predictions without managing servers.

Three‑step deployment of an automatic Chinese poem generator

Train a TensorFlow CharRNN model on approximately 70,000 lines of five‑character Chinese poetry. Save the model and checkpoint files.

Use the open‑source funcraft CLI to create a deployment package. Because the model and TensorFlow runtime exceed FC’s 50 MB package limit, funcraft automatically uploads the large files to a NAS file system and mounts the NAS path at runtime.

Create a template.yml that declares the runtime (e.g., Python 3.9), memory, timeout and the NAS mount point. Deploy with fun deploy . The function loads the model from NAS, generates a poem line for each HTTP request, and returns the result together with execution latency.

Invocation methods

GUI – Alibaba Cloud console or IDE plugins.

CLI – funcraft provides project scaffolding ( funcraft init), local debugging ( funcraft local invoke) and deployment ( fun deploy).

SDK – FC SDKs are available for Python, Java, Node.js, Go and other languages.

Key advantages for AI workloads

Automatic elastic scaling in milliseconds; no capacity planning required.

Pay‑per‑use pricing; idle functions incur no cost.

Built‑in CloudMonitor metrics (duration, memory, invocations) and alerting.

Reserved mode (FC 2.0) keeps a configurable number of instances warm, reducing cold‑start latency from >20 s to <300 ms.

Combining reserved capacity with on‑demand scaling improves resource utilization (>80 % in tests) and lowers total cost.

Cold‑start mitigation

FC 1.0 recommends a time‑triggered warm‑up function. FC 2.0 introduces a reserved instance mode that pre‑allocates execution environments. Experiments show that without reservation latency spikes can exceed 20 s, while reserved mode keeps most requests under 300 ms.

Performance and cost comparison

Three scenarios were evaluated:

Latency‑sensitive service on ECS.

Cost‑sensitive service on ECS.

FC with MKL‑accelerated TensorFlow.

FC achieved comparable latency to ECS while providing sub‑second scaling and higher resource utilization. Using a mixed reserved + pay‑as‑you‑go pricing model reduced cost by up to 40 % compared with always‑on ECS.

Practical notes

Install Git and funcraft (available at https://github.com/alibaba/funcraft).

Run funcraft init to generate a project skeleton, edit template.yml to set nasConfig and the function handler.

Deploy with fun deploy; the CLI uploads NAS files automatically if they exceed the package size limit.

Monitor function metrics in CloudMonitor to verify latency and memory usage.

References

Open‑source repository:

https://github.com/alibaba/funcraft
serverlesscost optimizationTensorFlowcold startfunction computeAI model servingFuncraft
Alibaba Cloud Native
Written by

Alibaba Cloud Native

We publish cloud-native tech news, curate in-depth content, host regular events and live streams, and share Alibaba product and user case studies. Join us to explore and share the cloud-native insights you need.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.