利用 Amazon Bedrock Inference Profile 實現 Model 成本追蹤與管理

2024 年 11 月初,Amazon Bedrock 宣布了新功能 - Inference profile,使客戶能夠利用 cost allocation tag 按部門、團隊、應用程式對推理成本進行分類,並追蹤其 on-demand 模型的成本和資源利用率。
什麼是 Inference Profile?
Inference profile 讓企業能夠更靈活地配置和管理 Bedrock 上的基礎模型。透過這項功能,使用者能夠有效追蹤部署到各個 AWS Region 的模型使用情況並最佳化資源配置。這項功能特別適合需要掌握各 AI 模型使用狀況的企業,例如想要追蹤不同專案或客戶的模型使用量等應用場景。
Inference Profile 的類型
Amazon Bedrock 提供兩種類型的 Inference Profile:
1. AWS 預設的 Cross-Region Inference Profile
由 Amazon Bedrock 預先定義的設定檔,支援將請求 route 到多個 AWS 區域。使用者只需在發送模型調用請求時指定inference profile ID 或 ARN,就能實現跨區域的模型調用。
2. Application Inference Profile
應用程式 Inference Profile 則是由使用者自行建立,主要用於追蹤成本和模型使用情況。使用者可以建立 inference profile 將模型呼叫請求 route 到一個或多個區域
Inference Profile 優勢
成本追蹤與監控
透過 cost allocation tag 的整合,企業能夠輕鬆追蹤 on-demand 模型推理請求的成本,並進行成本分類。另外,cost allocation tag 也可以與 AWS Billing 無縫整合更讓成本管理變得更加便利。
用量指標追蹤
Inference Profile 提供了與 CloudWatch logs 的完整整合。使用者可以收集並分析模型調用的使用量指標,取得詳細的監控資訊,進而做出更明智的決策。這些資料不僅能幫助優化資源配置,還能提供重要的營運洞察。
跨區域推理
讓企業能夠透過多區域部署來提高處理量。系統會自動在多個區域間分配模型調用請求,特別是在尖峰使用期間,這種分配機制能夠提供更好的服務彈性,確保系統的穩定性和可靠性。
如何建立 Inference Profile
可以簡單地利用 CLI 或是 API 的方式建立 Amazon Bedrock Instance Profile。以下以 CLI 為例:
1. 利用 CLI 建立 inference profile aws bedrock create-inference-profile --inference-profile-name <your-inference-profile-name> --model-source copyFrom=<model-arn> --tags key=<your-tag-key>,value=<your-tag-value>

2. 如果忘記先 TAG Resource 也沒關係,可以利用 tag-resource 再 tag 已建立的 instance profile
a. 查詢 application inference profiles,複製 instanceProfileArn
i. aws bedrock list-inference-profiles --type-equal APPLICATION

b. 利用 tag-resource 下此 inference profile 的 tag,並在 “resource-arn” 處使用剛剛查詢到的 instanceProfileArn
i. aws bedrock tag-resource --resource-arn <your-resource-arn> --tags key=user,value=ginny
c. 確認是否有 tag 到 aws bedrock list-tags-for-resource --resource-arn <your-resource-arn>

3. 呼叫 Bedrock 的時候 model id 使用前面指令產生的 InferenceProfileArn 即可

或者也可以使用 AWS Bedrock console 中的 Playground 測試。
選擇 Model 後,在右側 “Inference” 的下拉選單選擇 “Inference profiles”,可以看到能夠選擇剛建立的 inference profile - ginnyhuangTAG

Bill and Cost Management 成本追蹤與監控
1. 如果 tag 先前沒有在 Bill and Cost Management 服務中的 Cost Allocation Tags 被 activate 的話,需要把 tags activate 起來才能分帳。如圖,勾選此 Tag key 後點選 “Activate”
注意 Cost allocation tags 在 payer account level 才可以做調整

2. Activate 之後,會需要等約 24 小時才能在 Cost Explorer 中 filter Tag
3. 如已 Activate 成功,即可進入 Cost Explorer 的頁面右側 filter Tag。選擇先前下的 tag 後,即可看到此 tag 底下的花費及用量。

CloudWatch 用量指標追蹤

結語
Amazon Bedrock 的 Inference Profile 功能為企業有效管理 AI model 的使用成本。企業能透過 cost allocation tag 實現精確的成本分配,並且也能利用 CloudWatch 進行用量監控。隨著企業對 AI 應用的需求持續增長,有效的成本及資源管理變得越來越重要。Inference Profile 的推出,不僅協助企業內部,更能為 SaaS 服務提供商進行有效的成本及用量管理,讓企業能夠建立更精準的計費模型。
參考資料
https://docs.aws.amazon.com/bedrock/latest/userguide/inference-profiles.html
https://docs.aws.amazon.com/bedrock/latest/userguide/tagging.html

作者

Ginny Huang是任職於台灣 AWS 的解決方案架構師。對生成式 AI 解決方案充滿熱情,致力於了解客戶需求並協助客戶設計解決方案。

Ting-Yao Chang 是任職於台灣 AWS 的解決方案架構師,擅長了解客戶需求並設計架構,服務過許多大型企業;近期致力於生成式 AI 技術,協助客戶探索使用情境並提供解決方案建議。
關於Amazon Web Services
自 2006 年來,Amazon Web Services 一直在提供世界上服務最豐富、應用廣泛的雲端服務。AWS 不斷擴展可支持幾乎任何雲端工作負載的服務,為客戶提供超過 240 種功能全面的雲端服務,包括運算、儲存、資料庫、聯網、分析、機器學習與人工智慧、物聯網、行動、安全、混合雲、媒體,以及應用開發、部署和管理等方面,遍及 33 個地理區域內的 105 個可用區域(Availability Zones),並已公佈計畫在馬來西亞、墨西哥、紐西蘭、沙烏地阿拉伯和泰國等建立 6 個 AWS 地理區域、18 個可用區域。全球超過百萬客戶信任 AWS,包含發展迅速的新創公司、大型企業和政府機構。AWS 協助客戶強化自身基礎設施,提高營運上的彈性與應變能力,同時降低成本。欲瞭解更多 AWS 的相關資訊,請至: aws.amazon.com。