2021年2月18日 星期四

學習筆記|Machine learning DevOps的五個關鍵思考點


 


因為近幾年手頭上的專案多和machine learning 相關最近趁著過年期間,沈澱思緒,整理一下學習心得。

管理專案需要考量一向很多,Machine learning DevOps 相關的專案也不例外。

雖然該考量的面向很多,不過再三思考過後,特別點出Peggy認為特別必需優先思考的五個關鍵點,提供給有需要或有興趣的朋友參考。

本文為個人經驗談,也歡迎交流討論。☺️


1.  What problem you want to solve? What value you want to deliver?

也許有朋友看到這個放在第一個關鍵點會有些疑問,覺得這也太普通了吧,似乎和其他種專案沒兩樣。

Yes!  Yes! You are right! 這邊Peggy想強調的是,machine learning 的 Dev 與 Ops ,也是和其他研發專案一樣,最優先的是要好好思考與確認要解決什麼問題?更甚至是對客戶的價值是什麼?

不要太興奮,馬上jump進入一些很 fashion 的 Machine learning term/algorithm。例如當時 Deep learning 當紅,就想著一定要用Deep learning,但卻沒有思考到要解決什麼問題,又這問題適合用Deep learning 來解決嗎?

以幾年前,Peggy 手上的一個專案 TrendX,用machine learning 來偵測malware。在專案初期,就很快確認最主要的價值是要偵測 Ransomware (勒索軟體), 而非一般的 malware 。

又以另一個專案Writing style 為例,最初也是花了一些時間定義要解決的問題— BEC ( Business Email Compromise) 。主要是用machine learning 學出寫信者的寫作DNAs,當有人假冒組織內重要人物(例如 CEO) 發信給組織成員,寫作風格一改變,就會被這個偵測到。 且第一版本專注於支援英文,之後才是其他重要語系。

當把要解決的問題/範圍/情境事先定義得越清楚,對之後的 Data pipeline 以及判定哪些machine learning solution 較適合都很有幫助。

另外,Value 這部分,不只單純指多賺的營收、也可能是提升品牌價值、提供differentiation 的功能辨識度等等。
帶來多少 Value 這點,建議早點初步了解,進階更是去計劃如何驗證,最晚POC 完成後,也要開始。
如果公司分工較明確與細緻,那同一個team 的成員或leader 可能不一定可以回答這個問題。但,建議至少要嘗試往PM / marketing 相關的stakeholders 那邊請教一下。

2. Data is king


Data pipeline: Data -> Features -> Algorithms -> Models

一聊到 machine learning,很容易馬上聯想到最 sexy 的部分— Algorithm,也有些人會花很多effort在嘗試各種不同演算法。

然而,在real practice 中,Data is the king! 

大神 Andrew Ng(曾任VP & Chief Scientist of Baidu, Co-Chairman and Co-Founder of Coursera, 與 Professor at Stanford University and Co-founder of Google Brain的) 也曾說 

"it's not who has the best algorithm who wins, it's who has the most data". 


在實務上也是,最棒的data 是兼具quantity 與 quality。
我們也常遇到,solution 的precision 和recall 不如預期時,除了增加data 的量之外,對 data 做些 purify,把quality提升後,常就會有所改善。



3. Operation 


是的,Machine learning solution 也是有Operation 的,除非在POC 階段就掰了。
只要是有上線、有on production 的 ML solution,幾乎都會面臨到Operation 的階段。

以下是 ML solution 上線前常思考的幾個問題:

- 是放事先 train 好的 model 上去,還是要作 on-line 的training?
- ML solution 同一個model 的有效性是多久? 需要rolling model 嗎?
- 如果需要rolling model ,多久需要rolling? 怎麼rolling ?
- 怎麼 monitor 上線後的成效和異常狀況?
- 當異常狀況發生時,如何handle? 如何做urgent 處理以減少business impact?
- 需要多少 Engineer 來作這個operation? 怎麼分工?
...



4. Performance 


因為手上經手過的這幾個machine learning projects都是在 public cloud 上,有AWS的也有Azure的。
這時候,我們通常會用QPS 來衡量model 的 performance.

QPS :Queries Per Second,每秒查詢數。每一個特定的server 在每秒能夠支援的查詢次數,也即是最大吞吐能力。
這邊進一步要思考的點在於,model 的 Response time (ms)。一個query 從進service 到solution 到回應客戶端,共要花多少時間?可以接受花多少時間?
以我們提供的其中一個服務為例,我們的 criteria 是500 ms 含 ML model 300 ms 以及Process time 低消。
比較常用語言是python and Golang,以實務經驗來說,通常要快快做ML solution POC 和 data analyzing , python 還蠻適合的。
然而,對上線(非internal POC) 的版本,建議盡量用Golang。Golang 有內建支援 concurrent process channeling ,效能會好很多。


5. Cost 


一個machine learning solution 可帶來多少效益?需要花多少成本?

關於成本,上述提到的operation 就不重複提了。最基本又直接的問法是,需要開多少instance? 規格是什麼? ex,T2.large 就好嗎?還是要開到更高規格?

以每天的query量,以及model 的回應速度,需要多少機器power 去支持?
每個月花這些錢與前面提的operation efforts有帶來足夠的效益嗎?

畢竟若一個ML solution 花數十萬、甚至數百萬以上,又要不少 Ops effort ,但卻沒有帶來應有的Value,那就太傷了。


Machine Learning DevOps 還有其他蠻多需要考慮的點,不過Peggy認為以上五點是蠻關鍵的思考面向,提供給有需要的朋友參考。

另外對相關主題有興趣的朋友,也可以到Andrew 大神的網站下載他的著作—“MACHINE LEARNING YEARNING”,閱讀後會很有收穫。



以下是手上版本的 Table of Content給您參考囉。Enjoy :-)

1 Why Machine Learning Strategy
2 How to use this book to help your team
3 Prerequisites and Notation
4 Scale drives machine learning progress
5 Your development and test sets
6 Your dev and test sets should come from the same distribution
7 How large do the dev/test sets need to be?
8 Establish a single-number evaluation metric for your team to optimize
9 Optimizing and satisficing metrics
10 Having a dev set and metric speeds up iterations
11 When to change dev/test sets and metrics
12 Takeaways: Setting up development and test sets
13 Build your first system quickly, then iterate
14 Error analysis: Look at dev set examples to evaluate ideas
15 Evaluating multiple ideas in parallel during error analysis
16 Cleaning up mislabeled dev and test set examples
17 If you have a large dev set, split it into two subsets, only one of which you look at
18 How big should the Eyeball and Blackbox dev sets be?
19 Takeaways: Basic error analysis
20 Bias and Variance: The two big sources of error
21 Examples of Bias and Variance
22 Comparing to the optimal error rate
23 Addressing Bias and Variance
24 Bias vs. Variance tradeoff
25 Techniques for reducing avoidable bias 
26 Error analysis on the training set
27 Techniques for reducing variance
28 Diagnosing bias and variance: Learning curves
29 Plotting training error
30 Interpreting learning curves: High bias
31 Interpreting learning curves: Other cases
32 Plotting learning curves
33 Why we compare to human-level performance
34 How to define human-level performance
35 Surpassing human-level performance
36 When you should train and test on different distributions
37 How to decide whether to use all your data
38 How to decide whether to include inconsistent data
39 Weighting data
40 Generalizing from the training set to the dev set
41 Identifying Bias, Variance, and Data Mismatch Errors
42 Addressing data mismatch
43 Artificial data synthesis
44 The Optimization Verification test
45 General form of Optimization Verification test
46 Reinforcement learning example
47 The rise of end-to-end learning
48 More end-to-end learning examples
49 Pros and cons of end-to-end learning
50 Choosing pipeline components: Data availability
51 Choosing pipeline components: Task simplicity 
52 Directly learning rich outputs
53 Error analysis by parts
54 Attributing error to one part
55 General case of error attribution
56 Error analysis by parts and comparison to human-level performance
57 Spotting a flawed ML pipeline
58 Building a superhero team - Get your teammates to read this

/

圖出自 :

reference: 



歡迎轉貼,禁止商業使用,請註明原文標題、連結以及作者。

2 則留言:

  1. 最近在準備ML的資料,看到這篇覺得很用心,適合新手閱讀,大推~~

    回覆刪除

Peggy的實驗空間| 小書庫 Index card ( 讀書筆記總目錄 )

  一直很喜歡閱讀,也常從閱讀好書中與讀書會得到許多的力量與啟發,不管是在人生的低潮抑或是順遂的時候。在閱讀之路上,這幾年也保持一個習慣。當閱讀到喜歡的書籍,且那陣子時間允許,就會提醒自己閱讀完後整理出心得筆記。一方面藉機鍛鍊寫作肌肉與思路,方便之後的複習和查閱。另一方面,也可以...