Azure Functions for AI Inference
Run machine learning inference on Azure Functions with custom containers, Durable Functions for complex pipelines, and Blob Storage model caching.
Azure Functions Hosting Plans
| Plan | Memory | Timeout | Best For ML |
|---|---|---|---|
| Consumption | 1.5 GB | 10 min | Small models (sklearn, ONNX) |
| Flex Consumption | 4 GB | 30 min | Medium models with always-ready instances |
| Premium (EP1-EP3) | 3.5-14 GB | Unlimited | Larger models with warm instances |
| Container Apps | Custom | Custom | Full PyTorch/TF with GPU support |
Python Function with ML Model
import azure.functions as func import json import onnxruntime as ort from azure.storage.blob import BlobServiceClient app = func.FunctionApp() # Load model at module level for reuse session = ort.InferenceSession("model/sentiment.onnx") @app.route(route="predict", methods=["POST"]) def predict(req: func.HttpRequest) -> func.HttpResponse: body = req.get_json() inputs = {session.get_inputs()[0].name: body["tokens"]} result = session.run(None, inputs) return func.HttpResponse( json.dumps({"sentiment": result[0].tolist()}), mimetype="application/json" )
Durable Functions for ML Pipelines
Durable Functions enable orchestrating multi-step inference pipelines where you need to chain preprocessing, inference, and postprocessing as separate functions with built-in retry logic and state management.
Model Management with Blob Storage
Store model versions in Azure Blob Storage and download them during function initialization. Use the function's local temporary storage as a model cache to avoid re-downloading on warm invocations.
FUNCTIONS_WORKER_PROCESS_COUNT to 1 for ML workloads to avoid memory contention between worker processes.Ready to Go Deeper?
Live instructor-led courses from our partners. Affiliate disclosure.
AI & ML Courses - 30% Off
Live instructor-led AI, machine learning, data science, and cloud courses for working professionals. Use code Limited30 at checkout.
EdurekaDataCamp - AI & Data Science
Hands-on Python, machine learning, and AI courses with interactive exercises and real projects.
DataCampedX - Top AI Courses
University-level AI courses from MIT, Harvard, Stanford. Earn certificates that employers recognize.
edX