DeepLearning | AI tech studio https://cyberagent.ai AI事業本部は、サイバーエージェントグループのデジタルマーケティング分野におけるサービス開発を行う組織です。 Thu, 01 Jul 2021 00:18:14 +0000 ja hourly 1 https://wordpress.org/?v=5.3.26 Verifying the power of a PCIe board with 16 Google® Coral Edge TPUs(1)Environment construction and simple operation verification https://cyberagent.ai/blog/research/edgetpu16_verify_en Wed, 30 Jun 2021 22:30:24 +0000 https://ai-blog-admin.cyberagent.ai/?post_type=blog&p=15161 Japanese / English

I am Katsuya Hyodo, a member of the CyberAgent AI Lab HCI (Human Computer Interaction) team. I have been working with a research team at Osaka University as a research engineer since April 2021. HCI is a word that may be unfamiliar to you, but we are a team that researches and develops customer service dialogue agents. Previously, I was managing the R&D team of a SIer. I am surrounded by people with amazing backgrounds, which makes me feel very intimidated, but I am able to expand my activities.

Now, some of you who are reading this article may know about my private activities, but this time I would like to write about something a little different from what I usually do. I was told that I can write whatever I want. I’m excited.

Google® Coral Edge TPU CRL-G116U-P3DF

Figure 1. CRL-G116U-P3DF (Cited [1])

1. Google® Coral Edge TPU CRL-G116U-P3DF

This is my first blog, and I will be examining the performance of this device and looking for realistic ways to use it. This is a high-performance accelerator card with 16 TPUs, released by ASUS in December 2020. The selling price on Amazon as of June 8, 2021 is $2,911. First of all, let’s take a look at what the specifications of this device are. The right column shows the specs of the CRL-G116U-P3DF that I will be testing. One thing worth noting about the specification is that it takes up a PCI Express 3.0 x16 slot, which conflicts with the GPU slot. And it’s as big and expensive as a GPU. It’s a trade-off between price and performance, but the pricing is a bit annoying. What is the best way to use the system?

Table 1. CRL-G18U-P3DF / CRL-G116U-P3DF specifications (Cited [2])

Also, the officially supported OS is Ubuntu 18.04 or Deian 10, which is quite old. If all the necessary resources are available as OSS and buildable, you may be able to install it on the latest Ubuntu 21.04 or Debian 11 OS. However, in order to avoid running into compiler version discrepancies, which could delay the verification process, we will follow the official tutorial.

This is a block diagram of the hardware. You have 16 TPUs connected there, two each with PCIe Gen3. In the past, my experience of using three of them in parallel for a long time was that they could get quite hot when used continuously. To keep the operating temperature of the 16 TPUs below the upper limit of 55 °C, two cooling fans are included, which I find somewhat satisfying.

Figure 2. Block Diagram (Cited [3])

 

Before setting it up, let’s compare it to the EdgeTPU USB Accelerator , just in case. If the exact numbers are nominal, the USB Accelerator is supposed to have 1.6 times higher processing performance per WATT. Also, at first glance, it appears that the processing performance per WATT is higher than that of a typical RTX30xx series GPU, but since the EdgeTPU is a device specialized for INT8 integer operations, we believe that a simple comparison is not possible. I will verify the operation later, but it seems to be high performance enough if you don’t take into account any degradation of the model accuracy due to INT8 quantization. The problem is how to use and operate 16 TPUs well.

Table 2. EdgeTPU USB Accelerator specifications (Cited [4])

2. Kitting of Google® Coral Edge TPU CRL-G116U-P3DF

So, without further ado, let’s kitting the accelerator card. The procedure for physical installation on the PC chassis is omitted, and the procedure from the software installation part is described sequentially. If your OS version is Ubuntu 18.04, you can follow the official user’s manual and get to the first operation check in about an hour. The official documentation is here.

2-1. Install the Edge TPU driver

2-1-1. Checking the Kernel version

If the version number displayed as a result of executing the following command is 4.18 or lower, go to 2-1-4. If 4.19 or higher, go to 2-1-2.

$ uname -r

2-1-2. Check for the existence of the Apex driver

If nothing is displayed as a result of executing the following command, go to 2-1-4. If you see output that includes the word apex, go to 2-1-3.

$ lsmod | grep apex

2-1-3. Disable Apex and Gasket

Execute the following command to reboot.

$ echo "blacklist gasket" >> /etc/modprobe.d/blacklist-apex.conf
 $ echo "blacklist apex" >> /etc/modprobe.d/blacklist-apex.conf
 $ sudo reboot

2-1-4. Driver installation

Execute the following command to reboot.

$ echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
 $ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
 $ sudo apt update && sudo apt install -y gasket-dkms libedgetpu1-std
 $ sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"
 $ sudo groupadd apex && sudo adduser $USER apex
 $ sudo rm /etc/modprobe.d/blacklist-apex.conf
 $ sudo reboot

2-2. Install the Edge TPU runtime

2-2-1. Install the Python library (PyCoral)

Execute the following command.

$ sudo apt install python3-pycoral

2-3. Checking Edge TPU operation

Verify that “Parrot Image Recognition” is working properly. Execute as follows.

$ mkdir coral && cd coral
 $ git clone https://github.com/google-coral/pycoral.git && cd pycoral
 $ bash examples/install_requirements.sh classify_image.py
 $ python3 examples/classify_image.py \
     --model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
     --labels test_data/inat_bird_labels.txt \
     --input test_data/parrot.jpg

If the result is displayed as shown below, the installation is successful.

Initializing TF Lite interpreter...
INFO: Initialized TensorFlow Lite runtime.
----INFERENCE TIME----
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
11.8ms
3.0ms
2.8ms
2.9ms
2.9ms
-------RESULTS--------
Ara macao (Scarlet Macaw): 0.76562

The image to be recognized is that of a parrot (Ara macao), as shown below. Up to this point, I was able to get it to work without any stumbling blocks, just like when using the EdgeTPU USB Accelerator.  It’s very easy. Since it is meaningless to verify only this, we would like to explore what we can do to maximize the benefits of multi-TPU by using specific APIs.

Figure 3. Ara macao (Cited [5])

3. So much for the first article

I know it is a bit insufficient, but this first article is only about setting up the environment and a simple operation check. In the next article, I plan to write a series of articles on the following topics without much time lag. However, the details and the order of publication will be changed flexibly depending on the results of the verification. Many of the articles I usually write in other spaces are very voluminous, but due to the limitations of the tools I use to write this article, it was very difficult to write a large volume of articles all at once, so I decided to split it up.

  1. Partitioning and Multi-TPU Inference of Quantized Models
  2. Partitioned inference of input data
  3. Serial inference of models for different tasks
  4. Parallel inference of models for different tasks
  5. Verification of resistance to continuous operation
  6. Verifying whether it is possible to drive containerization for each TPU
  7. Building an Inference Pipeline

See you next time.

4. References

[1] ASUS, AI-Accelerator-PCIe-Card, Overview, https://www.asus.com/jp/Networking-IoT-Servers/AIoT-Industrial-Solution/AI-Accelerator/AI-Accelerator-PCIe-Card/

[2] ASUS, AI Accelerator Card CRL-G18U-P3DF/CRL-G116U-P3DF Hardware User Manual, 1.3 Product specification

[3] ASUS, AI Accelerator Card CRL-G18U-P3DF/CRL-G116U-P3DF Hardware User Manual, 1.7 Block diagram

[4] Google Coral, USB Accelerator Tech specs, https://coral.ai/products/accelerator/

[5] Google Coral, Get started with the USB Accelerator, https://coral.ai/docs/accelerator/get-started/#3-run-a-model-on-the-edge-tpu

]]>
Google® Coral Edge TPUを16個搭載したPCIeボードの実力検証(1)環境構築と簡易動作検証 https://cyberagent.ai/blog/research/edgetpu16_verify_jp Wed, 30 Jun 2021 22:30:18 +0000 https://ai-blog-admin.cyberagent.ai/?post_type=blog&p=14996 Japanese / English

サイバーエージェント AI Lab HCI (Human Computer Interaction) チームの 兵頭 です。2021年4月から大阪大学の研究チームでリサーチエンジニアとしてお世話になっています。HCIというと少し聞きなれないワードですが、接客対話エージェントを研究・開発 しているチームです。前職は SIer の R&Dチーム のマネージメントをしていましたが、いきなりエンジニア職へ転向した、というちょっとした変わり者です。周りはものすごい経歴の方々に囲まれておりとても恐縮していますが、伸び伸びと活動させていただけています。

さて、本記事をご覧いただいている方の中には私の プライベートの活動 をご存じの方がいらっしゃるかもしれませんが、今回はちょっと普段とは色味の異なることを記事にしてみようと思います。好きなことを書いていいんですって。ワクワクしますね。

Google® Coral Edge TPU CRL-G116U-P3DF

図1 CRL-G116U-P3DF (参考文献 [1] より引用)

1. Google® Coral Edge TPU CRL-G116U-P3DF

初のブログですが、今回はこのデバイスの性能検証や現実的な使い道を模索します。2020年12月に ASUS から発売された、TPUが16個も搭載されたハイパフォーマンスアクセラレータカードです。2021年6月8日時点のAmazonでの販売価格は ¥291,103- です。まずはこのいかにもなデバイスがどのような仕様なのかを見てみましょう。右側の列が今回検証する   CRL-G116U-P3DF  のスペックです。 仕様上で注目すべき点は PCI Express 3.0 x16 のスロットを専有することでGPUのスロットと競合する点です。そしてGPU並に大きい、高価。とても悩ましいですね。いったいどのような用途で稼働させればペイできるのでしょうか。

表1 CRL-G18U-P3DF / CRL-G116U-P3DF 仕様 (参考文献 [2] より引用)

また、公式サポートOSが Ubuntu18.04 あるいは Deian 10 と、かなり古いものになっています。必要なリソースが全てOSSとして公開されていてビルド可能な状態であれば、最新の Ubuntu 21.04 や Debian 11 などのOSへも頑張れば導入できるかもしれませんが、コンパイラのバージョン齟齬などによって動作に支障をきたして本来実施したい検証が滞ることを避けるため、今回は公式のチュートリアルどおりにセッティングを行っていきたいと思います。

ハードウェアのブロックダイアグラムです。16個の TPU が PCIe Gen3 で2個ずつ接続されていますね。過去に3個を並列で長時間使用してみた体感として、連続利用をするとかなりの高温になることがありました。16個のTPUの作動温度上限の 55 ℃ 以下を保つために冷却用FANが2個も付属しているのはなんとなく納得感があります。

図2 ブロックダイアグラム (参考文献 [3] より引用)

 

セッティングの前に、念の為  EdgeTPU USB Accelerator  のスペックと比較してみましょう。正確な数値が公称されているとすれば、WATTあたりの処理性能は USB Accelerator のほうが 1.6 倍高いことになっています。また、一見すると一般的な RTX30xx 系のGPUと比べてWATTあたりの処理性能は高く見えますが、 EdgeTPU は INT8 の整数演算に特化したデバイスであることから単純比較はできないと考えます。のちに動作検証を行いますが、INT8量子化によるモデルの精度劣化を一切加味しない場合は十分に高性能であると言えそうです。問題は 16個 ものTPUをいかにうまく活用・運用するかに尽きそうです。

表2 EdgeTPU USB Accelerator 仕様 (参考文献 [4] より引用)

2. Google® Coral Edge TPU CRL-G116U-P3DF のキッティング

では早速ですが、アクセラレータカードをキッティングします。PC筐体への物理的な取り付けの手順は省略し、ソフトウェアの導入部分からの手順を順次記載します。OSのバージョンが Ubuntu 18.04 である場合は、公式のユーザーズマニュアルの通りに作業を実施することで、おおむね1時間ほどで初回動作確認までたどり着くことができます。公式のドキュメントは こちら です。

2-1. Edge TPU driver のインストール

2-1-1. Kernel のバージョン確認

下記のコマンドを実行した結果表示されたバージョン番号が 4.18 以下なら 2-1-4 へ。 4.19 以上なら 2-1-2 へ

$ uname -r

2-1-2. Apex ドライバの存在確認

下記のコマンドを実行した結果、何も表示されなければ 2-1-4 へ。 apex  という文字が含まれた出力が表示された場合は 2-1-3 へ

$ lsmod | grep apex

2-1-3. Apex および Gasket の無効化

下記のコマンドを実行して端末を再起動

$ echo "blacklist gasket" >> /etc/modprobe.d/blacklist-apex.conf
 $ echo "blacklist apex" >> /etc/modprobe.d/blacklist-apex.conf
 $ sudo reboot

2-1-4. ドライバインストール

下記のコマンドを実行して端末を再起動

$ echo "deb https://packages.cloud.google.com/apt coral-edgetpu-stable main" | sudo tee /etc/apt/sources.list.d/coral-edgetpu.list
 $ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
 $ sudo apt update && sudo apt install -y gasket-dkms libedgetpu1-std
 $ sudo sh -c "echo 'SUBSYSTEM==\"apex\", MODE=\"0660\", GROUP=\"apex\"' >> /etc/udev/rules.d/65-apex.rules"
 $ sudo groupadd apex && sudo adduser $USER apex
 $ sudo rm /etc/modprobe.d/blacklist-apex.conf
 $ sudo reboot

2-2. Edge TPU runtime のインストール

2-2-1. Pythonライブラリ (PyCoral) のインストール

下記コマンドを実行

$ sudo apt install python3-pycoral

2-3. Edge TPU の動作確認

恒例の 「オウムの画像認識」 が正常に行われるかどうかを確認します。下記のとおり実行します。

$ mkdir coral && cd coral
 $ git clone https://github.com/google-coral/pycoral.git && cd pycoral
 $ bash examples/install_requirements.sh classify_image.py
 $ python3 examples/classify_image.py \
     --model test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
     --labels test_data/inat_bird_labels.txt \
     --input test_data/parrot.jpg

下記のように結果が表示されれば導入成功です。

Initializing TF Lite interpreter...
INFO: Initialized TensorFlow Lite runtime.
----INFERENCE TIME----
Note: The first inference on Edge TPU is slow because it includes loading the model into Edge TPU memory.
11.8ms
3.0ms
2.8ms
2.9ms
2.9ms
-------RESULTS--------
Ara macao (Scarlet Macaw): 0.76562

認識対象の画像は下図のオウム (コンゴウインコ = Ara macao) の画像です。ここまでは何も躓くことなく EdgeTPU USB Accelerator を使用するときと同じ使用感で動作させることができました。とても簡単ですね。これだけの検証では意味がありませんので、特有のAPIなどを利用してマルチTPUの利点を最大限に活かしてどのようなことができるか、を模索していきたいと思います。

図3 Ara macao (参考文献 [5] より引用)

3. 初回記事はここまで

少々物足りないのは承知の上ですが、初回の記事は環境構築と簡易的な動作確認までとします。次回以降は概ね下記のようなトピックであまり期間を空けずに記事を連載していく予定です。ただし、詳細や公開の順序は検証結果に応じて柔軟に変更させていただくスタイルとするつもりです。私がいつも他のスペースで書いている記事はとてもボリュームのあるものが多いですが、本記事を書くツールの制約上、大きなボリュームの記事を一気に書き切ることがとても大変でしたので分割させていだく次第です。

  1. 量子化モデルの分割・マルチTPU推論
  2. 入力データの分割推論
  3. 異なるタスクのモデルの直列推論
  4. 異なるタスクのモデルの並列推論
  5. 連続稼働耐性の検証
  6. TPUごとのコンテナ化駆動は可能?
  7. 推論Pipelineの構築

では、次回をお楽しみに。

4. 参考文献

[1] ASUS, AI-Accelerator-PCIe-Card, 概要, https://www.asus.com/jp/Networking-IoT-Servers/AIoT-Industrial-Solution/AI-Accelerator/AI-Accelerator-PCIe-Card/

[2] ASUS, AI Accelerator Card CRL-G18U-P3DF/CRL-G116U-P3DF Hardware User Manual, 1.3 Product specification

[3] ASUS, AI Accelerator Card CRL-G18U-P3DF/CRL-G116U-P3DF Hardware User Manual, 1.7 Block diagram

[4] Google Coral, USB Accelerator Tech specs, https://coral.ai/products/accelerator/

[5] Google Coral, Get started with the USB Accelerator, https://coral.ai/docs/accelerator/get-started/#3-run-a-model-on-the-edge-tpu

]]>