Khám phá cách điện toán serverless cách mạng hóa AI/ML với khả năng mở rộng, hiệu quả chi phí và triển khai nhanh chóng. Xây dựng thông minh hơn, nhanh hơn ngay hôm nay!
Serverless computing is a cloud execution model that enables developers to build and run applications without the complexity of managing infrastructure. In this paradigm, the cloud provider dynamically manages the allocation and provisioning of servers, abstracting the underlying hardware and operating systems away from the user. Code is executed in stateless containers triggered by specific events, such as an HTTP request, a database modification, or a file upload. This approach is highly relevant to modern cloud computing strategies, as it allows organizations to pay only for the compute time consumed, automatically adhering to scalability requirements by expanding from zero to thousands of instances based on traffic demand.
Cốt lõi của điện toán phi máy chủ là khái niệm Chức năng như một dịch vụ (Function-as-a-Service - FaaS) , trong đó các ứng dụng được chia nhỏ thành các chức năng riêng lẻ thực hiện các tác vụ riêng biệt. Đối với những người làm trong lĩnh vực Học máy (Machine Learning - ML) , điều này cung cấp một con đường hợp lý để triển khai mô hình . Thay vì duy trì một máy chủ chuyên dụng hoạt động không hiệu quả trong thời gian lưu lượng truy cập thấp, một chức năng phi máy chủ có thể được khởi tạo theo yêu cầu để xử lý dữ liệu và tắt ngay lập tức sau khi hoàn thành.
However, a key consideration in this architecture is the "cold start"—the latency incurred when a function is invoked for the first time or after a period of inactivity. To mitigate this, developers often use lightweight architectures like YOLO26 or techniques like model quantization to ensure rapid loading times, which is essential for maintaining low inference latency.
Kiến trúc không máy chủ đặc biệt hiệu quả đối với các quy trình làm việc thị giác máy tính (CV) hướng sự kiện và các đường dẫn dữ liệu.
Đoạn mã sau đây minh họa một trình xử lý serverless theo khái niệm. Nó khởi tạo một thể hiện mô hình toàn cục để tận dụng "khởi động nóng" (trong đó container vẫn hoạt động giữa các yêu cầu) và xử lý đường dẫn hình ảnh đến.
from ultralytics import YOLO
# Initialize the model outside the handler to cache it for subsequent requests
# YOLO26n is ideal for serverless due to its compact size and speed
model = YOLO("yolo26n.pt")
def lambda_handler(event, context):
"""Simulates a serverless function handler triggered by an event. 'event' represents the input payload containing
the image source.
"""
image_source = event.get("url", "https://ultralytics.com/images/bus.jpg")
# Perform inference
results = model(image_source)
# Return prediction summary
return {
"statusCode": 200,
"body": {
"objects_detected": len(results[0].boxes),
"top_class": results[0].names[int(results[0].boxes.cls[0])] if len(results[0].boxes) > 0 else "None",
},
}
Để hiểu về điện toán phi máy chủ, cần phải phân biệt nó với các mô hình cơ sở hạ tầng khác thường được sử dụng trong MLOps .
By leveraging serverless architectures, developers can deploy robust AI solutions that are cost-effective and capable of handling unpredictable workloads, utilizing tools like the Ultralytics Platform to streamline the model training and management process before deployment.