iT邦幫忙

0

【Azure MLOps - 2】使用Azure DevOps建立專案與連線設定

  • 分享至 

  • xImage
  •  

在上一篇【Azure MLOps - 1】使用Azure DevOps建立AML pipelines,已經設定好練習會需要的教材: Azure DevOps與Azure Machine Learning。

本篇文章架構:

  1. 概念說明
  2. 在Azure DevOps建立專案
  3. 建立Azure DevOps與Azure Resource Manager連線
  4. 建立Azure DevOps與Azure Machine Learning (AML)連線
  5. 下載範例程式碼
  6. 將範例程式碼上傳至Azure DevOps Repo

1.概念說明

上一篇說明MLOps的精神是做到「資料版本控管」、「訓練模型的程式碼版本控管」、「模型的版本控管」。其實在Azure ML平台上,透過「註冊模型步驟」做到模型版本控管:
https://ithelp.ithome.com.tw/upload/images/20230113/20154404sksW6baFOP.png

除了模型版本控管之外,也可利用「註冊資料步驟」進行資料版本控管:
https://ithelp.ithome.com.tw/upload/images/20230113/20154404yTVtIryO5s.png

所以資料科學家在AML上進行模型開發的時候,工作流程如下:

  1. 上傳一個Dataset到 「AML data assets」
  2. 手動新增一個運算資源「compute instance」或「compute cluster」
  3. 自上一個步驟啟動的運算資源下,開啟一個實驗進行模型訓練、調超參數等等,追蹤所有訓練模型
  4. 產出多個模型後,經過種種測試,終於有一個最棒的模型,覺得應該就是它了
  5. 註冊這個超棒模型
  6. 把模型部署在Kubernetes clusters,以API的形式提供real-time inference

過了一段時間後,資料科學家會想要嘗試的演算法,所以當測試完新的演算法後,會需要註冊新的模型、把模型發佈到測試環境中(staging area)與前一版模型比較、如果測試結果比起前一版模型更好,接下來會把它部署到正式環境(production area)取代舊有的。

然後,又過了一段時間,上述事情(粗體字處)又需要再做一次,但是絕大部分都是重複的步驟,只有在調整訓練模型程式碼的時候會有差異。所以如果能使用CI/CD pipeline來協助進行自動化訓練、註冊模型、部署模型,會減輕許多負擔。

在接下來的練習中,我們就要在Azure DevOps中把這些重複步驟,變成一個一個可以被機器(稱作agent)看得懂的任務,不同步驟指令(tasks)串接後,形成一條pipeline,自動地完成資料科學家的本來由手動完成的步驟。因為原本需要手動點選UI,也是有人為錯誤的風險,如果變成自動化的CI/CD pipeline後,一切變得可控且可重複。
下圖顯示其實工作流程一樣,只是把工作寫成pipeline,讓agent代為執行(只要建立好Agent與AML之間的連線):
https://ithelp.ithome.com.tw/upload/images/20230113/20154404Vl1j0lZqpB.png

2.在Azure DevOps建立專案

點選新增專案,輸入名稱後,點選private,名字可以自由填寫,我寫的是MLOps-workshop-1:
https://ithelp.ithome.com.tw/upload/images/20230112/20154404lch3mclIbz.png

點選創建好的專案:
https://ithelp.ithome.com.tw/upload/images/20230112/20154404CpkvWIDd3M.png

就可以到這個專案的主畫面:
https://ithelp.ithome.com.tw/upload/images/20230112/20154404aD3EV7kRHC.png

左邊的一些圖標,代表的是這個專案在導入DevOps的各種所需功能。

3.建立Azure DevOps與Azure Resource Manager連線

為了讓DevOps可以與Azure Resource連線,與Azure Resource Manager (ARM)建立connection;點選project settings。
https://ithelp.ithome.com.tw/upload/images/20230112/201544041RX0jbnK84.png

選取service connection
https://ithelp.ithome.com.tw/upload/images/20230113/20154404aclXNxeZDt.png

點選新增後,選擇Azure Resource Manager
https://ithelp.ithome.com.tw/upload/images/20230112/20154404UYkgyJ6KHI.png

點選Service principal (automatic),按Next
https://ithelp.ithome.com.tw/upload/images/20230112/20154404G69prWsx4A.png

選擇訂閱
https://ithelp.ithome.com.tw/upload/images/20230112/20154404z2quUNEBCk.png

輸入這個connection名稱:azure-resource-connection
https://ithelp.ithome.com.tw/upload/images/20230112/20154404ttWVm0YI4H.png

最後就會看到這個connection了。
https://ithelp.ithome.com.tw/upload/images/20230112/20154404N0GnzAJj0u.png

4.建立Azure DevOps與Azure Machine Learning (AML)連線

如果想要AzureDevOps指定與某個Azure Machine Learning (AML)資源連線,也可在填寫步驟,指定到前一篇的建立的資源群組與AML服務。
https://ithelp.ithome.com.tw/upload/images/20230112/20154404BRf8BtwZnV.png

最後就可以看到這個新的與AML的connection。https://ithelp.ithome.com.tw/upload/images/20230112/20154404LFxr4X3JG6.png

5.下載範例程式碼

接下來為了模擬開發【新版的訓練模型程式碼情境】,我們從Github下載範例程式碼到自己的電腦,當作示意。
https://ithelp.ithome.com.tw/upload/images/20230113/20154404XDhev8lmZq.png

把剛剛下載的程式碼,作為示範的專案資料夾,使用vs code進行程式碼編輯和Git進行程式碼版本控管。
https://ithelp.ithome.com.tw/upload/images/20230113/20154404akLzaXu3y8.png

6. 將範例程式碼上傳至Azure DevOps Repo

假設資料科學家使用vscode開發、用Git來進行版本控管模型訓練程式碼,在自己的機器裡(或者用AML的compute,Azure compute instance)測試完數次,認為這次的訓練程式碼,可以commit,並push到Azure DevOps Repo上。

情境:把在自己機器上的Repo,推到Azure DevOps Repo
https://ithelp.ithome.com.tw/upload/images/20230113/201544048VnJpjHTOX.png

為了讓Azure DevOps的agent能夠取用所有程式碼,並且做到程式碼版本控管,把地端的這個一直都在使用的repository推到Azure DevOps Repo上。首先我們需要先從Azure DevOps取得「Push an existing repository from command line」指令,利用git remote add origin指令,添加Azure DevOps Repo作為遠端數據庫。
複製這一段指令
https://ithelp.ithome.com.tw/upload/images/20230113/20154404U6BGRL7N1z.png

貼在vscode terminal上:
https://ithelp.ithome.com.tw/upload/images/20230113/20154404WVZeciRTlu.png

再點選push:
https://ithelp.ithome.com.tw/upload/images/20230113/20154404ZwGLep1Hac.png

就可以在Azure DevOps Repo中,看到我們上傳repo結果了:
https://ithelp.ithome.com.tw/upload/images/20230113/20154404pbO44odmVM.png

完成!

以上示範是為了模擬資料科學家的工作流程,產出新版的訓練程式碼之後,會進行commit與push。

也可以使用【Import a repository】的方式把Github上範例程式碼url複製後,直接上傳加入Azure Repo中。
https://ithelp.ithome.com.tw/upload/images/20230113/20154404xQgu5Uz9Qd.png

下一篇【Azure MLOps - 3】使用Azure DevOps建立訓練模型的CI pipeline(上)


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言