OmniXRI-Jack
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
# 【vMaker Edge AI專欄 #17】 開發者如何選擇 Edge AI 開發方案 作者:Jack OmniXRI, 2024/05/15 ![vMaker_EdgeAI_17_Fig00](https://hackmd.io/_uploads/rkJmRzfXC.jpg) 常有人在問「我想學 Edge AI,我有個情境要應用 Edge AI,究竟要選那種方案才能快速上手及完成專案呢?」,這不禁會讓人想起星爺電影「食神」中的一句對白「施主,這個問題你應該要問你自己!」。 「Edge AI」到底是什麼,可能問十個專家會得到十一種答案,或許把「Edge AI」當成「交通工具」來比喻會更容易得到答案吧?舉例來說,當你問巨大機械(捷安特)什麼是交通工具,那麼他可能會回答「當然是腳踏車呀!」,而同樣的問題問睿能創意(GOGORO)、特斯拉(Tesla)和長榮集團(Evergreen)時,則會得到電動機車、電動跑車和飛機、輪船的答案,這些都沒有對錯,只是大家都以自己的立場回答問題而已。 ![vMaker_EdgeAI_17_Fig01](https://hackmd.io/_uploads/r1P7OqZ7A.jpg) Fig. 1 不同等級的交通工具。(OmniXRI整理製作,2024/05/15) 同樣地,當你問不同硬體廠商「什麼是 Edge AI?」時,單晶片廠商會回應你「當然是MCU呀!」,而MPU, NPU, GPU, SoC廠商則會回答是單板微電腦(SBC)、AI加速晶片(NPU, GPU, XPU)、智慧手機(Mobile),當你問筆電(NB)供應商時,肯定會得到「是AI PC無誤」,不過當你問向世界最大AI晶片供應商時,老黃會不疾不徐的說道「我們家的 EGX 伺服器才是最適合大家的 Edge AI 方案,超便宜的,才一千(萬)出頭而已。」。 從上述答案可看出「Edge AI」從數美金到數十萬美金的方案都有,為什麼有這麼大的跨度呢?因為廣義上來說,只要不上網就能把AI推論完成的都能算在內,若要再定義窄一點,則使用電池電力完成AI推論的才能算,那筆電、手機、嵌入式、穿戴式裝置會更接近「Edge AI」的範圍。 ![vMaker_EdgeAI_17_Fig02](https://hackmd.io/_uploads/r1wid9-XA.jpg) Fig. 2 不同等級的 Edge AI 方案。(OmniXRI整理製作,2024/05/15) 根據上述說明,所以如果把選擇「Edge AI方案」當成是要買「交通工具」或許就簡單清楚多了,首先要考慮目的、用途、使用頻度,再來考慮口袋有多深、性價比如何,當然還要考慮自己是否有足夠的駕馭能力,最後後續的油電費、維修保養費、過路停車費及折舊費也要多方考慮的,以免負擔不起。如 Fig.3 所示,當把以上考慮內容換成「應用場景」、「開發框架」、「運行功耗」、「模型訓練」、「推論速度」、「優化部署」及其它各種額外費用,那麼相信大家心中的那把尺就很清楚了。 ![vMaker_EdgeAI_17_Fig03](https://hackmd.io/_uploads/H1uOBT-mR.jpg) Fig. 3 選擇 Edge AI 方案考量重點。(OmniXRI整理製作,2024/05/15) 至於買「交通工具」究竟要自己上作很多功課,研究各種規格,還是要聽好友、老婆、親人甚至網友建議都無妨,甚至只因車上多一個小裝置就買了,反正只要滿足功能需求和對的起錢包就好,而選擇「Edge AI方案」亦是如此。接下來就分別對幾項挑選重點項目分享給大家參考一下。 ## 1. 應用與算力需求 依 Fig. 2所示, Edge AI 跨度頗大,硬體算力由小至大可分為下列五個等級 AI。 1. **穿戴式(Wearable)或智慧感測(Smart Sensor)**,即 MCU 等級,如 Arm Cortex-M 系列。部份 MCU 可能會內建微型神經加速處理器(NPU, 俗稱AI晶片)來增加算力。 2. **單板微電腦(Single Board Computer, SBC)**,即單核或多核(同質或大小核) 微處理器(MPU) 構成的開發板,如 Arm Cortex-A 系列。 3. **行動式(Mobile)**,即系統級晶片(SoC) 構成的裝置,如手機、平板等行動通訊裝置,通常除基本 MPU 功能外,還常會配置圖形處理器(GPU)、數位信號處理器(DSP)甚至會有神經加速處理器(NPU)。有些沒有內建 NPU 的 SoC 或 MPU 會另外加掛獨立運行的 NPU,如 Hailo, Kneron 等晶片。 4. **筆電(Notebook, NB)**,即具有一般x86(Intel, AMD), Arm (Apple Mac, Microsoft Surface) CPU的筆電,有時會搭載內顯或外顯 GPU,最近 AI PC 等級筆電則是將 NPU 也加入 CPU中。 5. **伺服器(Server)**,基本上和一般大型伺服器類似,只是號稱不上網(外網),只提供企業內網使用,包含模型訓練和推論,這裡就不多作介紹。 不同 Edge AI 應用情境,因為模型複雜度、參數數量及數值表示系統(如 FP32, FP16, BF16, INT8, INT4, FP8...)不同,所需算力(每秒計算操作量 Operations per Second, OPS)也會有很大差異,通常會以 MOPS(10^6), GOPS(10^9), TOPS(10^12)來表示。 通常 OPS 越高代表計算能力越強,但要注意的是實際進行推論計算時,每秒可完成的推論次數和 OPS 不一定完全成正比,這還和許多軟硬體設計有關連。就像車子從靜止加速到100KM所需的秒數,數字小表示馬力足、性能好,但實際開上路,哪台車子跑的快,除了這個數字外,還有很多路況及駕駛問題要考量。 另外算力夠不夠還要考慮的是多少要完成推論一次,假設在某個裝置上推論一次0.5秒,若要求三秒才推論一次就沒問題,但如果要求一秒要推論5次,那就要考慮換小一點的模型或快一點的裝置。 如 Fig. 4所示,通常「智慧感測」的模型量級最小,模型大小可能僅為數十到數百KB,而計算量通常僅要數到數百MOPS就足夠。再來為「電腦視覺」、「自然語言」、「生成式對話/繪圖」,最大的應該是「多模態應用」,參數量可能已達數百兆到數千兆,計算量更是要數十到數百TOPS才足以應付。 當然同一領域也會隨著不同應用有很大的差異,如「電腦視覺」中的「影像分類」和「影像分割」就有可能差數十到數百倍的計算量差異。所以不同的應用通常要搭配不同的算力來實現。從 Fig. 4中就可看出不同應用情境所需搭配的推論算力及較合適的硬體裝置,當然如果要更精算的話,就要找出實際要推論的模型及硬體規格來估算。 ![vMaker_EdgeAI_17_Fig04](https://hackmd.io/_uploads/BJKPv6-70.jpg) Fig. 4 依應用場景及算力需求選擇 Edge AI 方案建議圖。(OmniXRI整理製作,2024/05/15) ## 2. 開發框架與平台 再來要考慮的點是開發方式,找一個工程師熟悉的或容易在網路找到資源和支援的專用或開源工具,對於系統的改善及後續的維運會減少很多浪費。 一般在 MPU 及 MCU 等級裝置,Arm架構是較多人使用的,Arm分別就 Cortex-A(MPU) & Cortex-M(MCU)上提供了 Arm NN , Compute Library 和 CMSIS-NN 函式庫來加速運算,透過這一層可連接上層的 AI 開發框架,如 Google TensorFlow, PyTorch, ONNX,亦可連接下層的 CPU, GPU, NPU 甚至特定的加速裝置。 當然這樣的函式庫對大部份的 MPU/MCU 或中大型 AI 工程師可能都不好上手,所以各家 MPU/MCU 都有自家對應的開發工具,如下所示(依廠商英文字順序排列)。而部份工具有些為半開放,不限於自家產品才可使用。 - Infineon: [Imagimob](https://www.imagimob.com/) - Nordic: [Atlazo](https://www.nordicsemi.com/Nordic-news/2023/08/Nordic-to-acquire-AI-ML-technology-in-the-US) - Nuvoton: [NuEdgeWise](https://www.nuvoton.com/ai/resource/#Development) - NXP: [eIQ](https://www.nxp.com/design/design-center/software/eiq-ml-development-environment:EIQ) - QuickLogic: [SensiML](https://sensiml.com/) - Renesas: [Reality AI](https://www.renesas.com/us/en/products/microcontrollers-microprocessors/reality-ai) - ST: [CubeAI](https://stm32ai.st.com/stm32-cube-ai/), [NanoEdge](https://www.st.com/en/development-tools/nanoedgeaistudio.html) - TDK: [Qeexo](https://qeexo.tdk.com/) 如果這些工具還太工程,不好上手,也有很多整合型工具供應商,提供從資料標註、模型挑選、訓練調參、壓縮優化到部署管控的雲端或本機端工具,甚至有些還可收費幫忙完成特定專案。以下就簡單列出幾個較知名的廠商。(依廠商英文字順序排列) - [Always ai](https://alwaysai.co/) - [AZIP](https://aizip.ai/) - [Clika.](https://www.clika.io/) - [Cyberon](https://www.cyberon.com.tw/) - [Deeplite](https://www.deeplite.ai/) - [Edge Impulse](https://edgeimpulse.com/) - [Grovety](https://grovety.com/) - [Latent ai](https://latentai.com/) - [Nota ai](https://www.nota.ai/) - [Plumer ai](https://plumerai.com/) - [SensiML](https://sensiml.com/) - [Silo ai](https://www.silo.ai/) 近幾年由於嵌入式單板微電腦及單晶片市場導入 AI 的應用越來越多,所以連知名 AI 框架也開始陸續投入,如下所示。 - [Google TensorFlow](https://www.tensorflow.org/) - [TensorFlow Lite](https://www.tensorflow.org/lite/) - [TensorFlow Lite for Micorcontroller (TFLu)](https://www.tensorflow.org/lite/microcontrollers) - [PyTorch](https://pytorch.org/) - [PyTorch for Mobile](https://pytorch.org/mobile/home/) - [ExecuTorch](https://pytorch.org/executorch-overview) 另外為了讓未來開發軟體的人不用考慮是何種硬體(CPU, GPU, NPU, FPGA...)進行推論計算,將硬體抽象化,目前也有部份工具供應商也積極在推展中,如下所示。 - Microsoft: [DirectML](https://github.com/microsoft/DirectML) - Intel: [OneAPI](https://www.intel.com/content/www/us/en/developer/tools/oneapi/overview.html) - Khronos Group: [OpenCL](https://www.khronos.org/opencl/) ## 3. 硬體加速與功耗 現有大多數的數位信號處理及深度學習模型,主要都是在執行矩陣運算,其核心公式就是「Y=AX+B」,又稱「乘積累加運算」(Multiply Accumulate, MAC)。由於數量非常巨量,所以如何在同一時間內處理越多的 MAC ,就能讓推論速度加快。 在通用型硬體中,可以分為下列類型。其中較具代表性的供應商如下所示。 - 中央處理單元(CPU):x86(Intel, AMD), Arm, RISC-V - 繪圖處理單元(GPU):Nvidia, AMD, Intel, Arm - 數位信號處理器(DSP):TI, Ceva, Cadence(Tensilica Xtensa) - 神經網路加速處理單元(NPU):或稱xPU, x 依各廠商自行定義),Hailo, Arm(Ethos), SiMa, Kneron, VeriSilicon), Google TPU - 現場可程式化邏輯閘陣列(FPGA):AMD(Xilinx), Intel(Altera), Lattice, Microchip - 特定應用積體電路(ASIC):Groq LPU(LLM專用) 不同硬體加速方式不同,包括下列方式。 * CPU - 增加工作時脈頻率 * CPU - 單指令週期硬體乘法、除法、浮點數計算 * CPU - 使用DSP指令 (乘法累加MAC) * CPU - 平行 / 向量指令集 (SIMD, MVE, NEON) * CPU - 多核心加速 (同質、大小核、異質) * GPU - Nvidia(CUDA, Tensor, NVDLA) * DSP / NPU - 增加乘法累加MAC數量 * FPGA - 依需求設計上述可能作法 * ASIC - 依特定功能設計,如LLM ![vMaker_EdgeAI_17_Fig05](https://hackmd.io/_uploads/BJzxbxM7A.jpg) Fig. 5 Edge AI 硬體類型及加速方式。(OmniXRI整理製作,2024/05/15) ## 4. 模型優化與部署 如果硬體加速能力有限的話,選擇合適的工具來幫忙模型優化及壓縮,節省參數儲存空間(硬碟或快閃記憶體)及程式計算空間(隨機存取記憶體)又能保證模型變小後推論精度不會下降太多,就像多啦A夢的縮小隧道,人進入後雖然體形變小但所有生理機能卻能維持不變。 一般模型優化常見技術包括下列項目。 - 數值量化:把FP32降到FP16、INT8甚至FP8、INT4以節省儲存空間。 - 模型剪枝:把網路中不必要或低影響力的節點及權重刪除。 - 模型壓縮:共用部份參數或利用小矩陣取代大矩陣運算。 - 知識蒸餾:使用原(老師)模型輸出作為小(學生)模型訓練的資料集,經大量資料訓練後以小模型取代原模型。 除上述處理方式,亦可透過 AutoML 技術,自動調整模型部份超參數,如網路層數、節點數等,最後再依參數量、記憶體使用量或推論精度優先的條件來調整。這樣的方式雖然很方便不懂相關技術的工程師,但需要有非常強大的算力來協助調整及訓練模型。 綜合上述描述這項工作並非一般工程師有能力處理的,所以依賴現有工具才是好的方式,目前常見工具如下列所示。 - [Intel OpenVINO (with NNCF)](https://docs.openvino.ai/) - [Nvidia TensorRT](https://developer.nvidia.com/tensorrt) - [Google TensorFlow Lite](https://www.tensorflow.org/lite/) 最後得到這些優化後的模型,要在實際的硬體裝置運行時可能還要將特定的函式庫及環境設定檔一起部署進去,否則將無法順利執行推論,而這些工作最後是透過人為方式處理,還是透過工具打包,就依不同優化工具提供的內容而有所不同。 ![vMaker_EdgeAI_17_Fig06](https://hackmd.io/_uploads/rJriK-G7R.jpg) Fig. 6 Edge AI 模型優化加速方式。(OmniXRI整理製作,2024/05/15) ## 小結 看完上述介紹,不知大家是更清楚怎麼選擇開發方案了,還是更亂了呢?猜想這大概和買車前看完一堆攻略還是有一堆問號一樣吧?這裡幫大家簡單總結一下,如果較在意成品單價,則先確認應用情境,選擇合適模型並找出需求參數量及參考算力,定義推論頻度、速度及精度,決定可用硬體下限及參考單價,而其它項目就請工程師多花點時間解決吧。相信只要不要想用腳踏車的預算和規格來完成汽車才能作到的事,這樣就不會遇到太多麻煩事了。 ## 參考文獻 [1] 許哲豪, OmniXRI‘s Edge AI & TinyML 小學堂 Youtube 直播 https://www.youtube.com/@omnixri1784/streams [2] 許哲豪,【vMaker Edge AI專欄 #08】親愛的我把AI模型縮小了- 模型減量與壓縮技術簡介 https://omnixri.blogspot.com/2023/08/vmaker-edge-ai-08-ai.html [3] 許哲豪,【vMaker Edge AI專欄 #13】誰說單晶片沒有神經網路加速器NPU就不能玩微型AI應用? https://omnixri.blogspot.com/2024/01/vmaker-edge-ai-13-npuai.html [4] 許哲豪,【vMaker Edge AI專欄 #14】從CES 2024 看Edge AI及TinyML最新發展趨勢 https://omnixri.blogspot.com/2024/02/vmaker-edge-ai-14-ces-2024-edge-aitinyml.html [5] 許哲豪,【vMaker Edge AI專欄 #15】從MWC 2024看AI手機未來發展 https://omnixri.blogspot.com/2024/03/vmaker-edge-ai-15-mwc-2024ai.html **本文同步發表在[【台灣自造者 vMaker】](https://vmaker.tw/archives/category/%e5%b0%88%e6%ac%84/jack-omnixri)** --- OmniXRI 整理製作,歡迎點贊、收藏、訂閱、留言、分享 ###### tags: `vMaker` `Edge AI`

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully