- Published on
在 OCI Ampere A1 计算实例上运行 AI
- Author
- Written by Peter Jausovec
- Name Peter Jausovec
- @pjausovec
创建免费的 Ampere VM
Note
根据 Oracle 的定价页,Oracle CPU (OCPU) 计费单元实际上是处理器的一个物理内核。一个开启超线程的 CPU,对应的是两个硬件执行线程,即所谓的 vCPU。。而对于 A1 实例,一个 OCPU 就是一个 vCPU。
选择图像和形状
- 单击 Change shape 按钮以选择不同的 VM 实例形态,确保您已选择虚拟机的实例类型。您可以在下一行中选择形态系列。我们正在寻找包含基于 ARM 的处理器和名为 VM.Standard.A 1.Flex 的形态名称的 Ampere 系列(它应该是此视图中唯一可用的形状)
- 选择VM.Standard.A 1.Flex,将 OCPU 数量调整为 4,并将内存量调整为 24 GB。完成此项操作后,我们将能够永久免费使用这一规格。
- 单击Select shape按钮以确认选择。
- 单击Change image按钮。然后让我们为形状获取正确的镜像。
选择镜像 选择镜像 - 在下拉菜单中选择Partner Image。然后在搜索框中,输入Ampere。您将看到可用于 Ampere A1 形状的可用镜像。
Ampere Tensorflow Image Ampere Tensorflow Image - 选中 Tensorflow 2.7 – Ampere AI Optimizer – Ubuntu 20.04 框和以下复选框以同意“Terms of Use(使用条款)”。然后,单击 Select Image 按钮。您应该会看到选定的 shape 和 image 框,如下图所示。
Tensorflow 2.7 – Ampere AI Optimizer – 已选择 Ubuntu 20.04 镜像 Tensorflow 2.7 – Ampere AI Optimizer – 已选择 Ubuntu 20.04 镜像
添加 SSH 密钥
Note
注意:您必须将 SSH 密钥文件的权限设置为 400。您可以运行chmod 400 <keyfile>
来执行此操作。
创建 AI 实例

连接到实例
$ ssh -i <keyfile> ubuntu@<public ip address>

sudo reboot
并在一分钟后再次登录。运行 TensorFlow -AIO 示例
$ cd ~/aio-examples
$ ./download_models.sh
Note
请注意,将所有模型下载到 VM 需要几分钟时间。
~/aioi-examples
和多个文件夹(例如classifications
、 object_detection
)。这些模型用来执行一些常用的 AI 推理计算机视觉任务,如图像分类和对象检测。resnet_50_v15
模型进行分类的示例开始:Note
resnet50 模型是什么?这是一个流行的模型,是 MLCommon 基准组件之一。您可以在这里读更多关于它的内容
cd classifications/resnet_50_v15
Note
对于 Ampere A1 实例,一个 OCPU 对应一个物理的 Ampere Altra 处理核心。它不同于 AMD (E3/E4)或 Intel Standard3(S3)中,一个 OCPU 对应一个超线程(HT)内核(一个物理内核对应两个 HT 内核)。
export AIO_NUM_THREADS=4
python run.py -m resnet_50_v15_tf_fp32.pb -p fp32
Note
在内存中,FP32 或全精度浮点是一种 32 位的数字格式。

AIO 运行半精度 (FP16) 模型
Note
FP16 是一种半精度浮点计算机数字格式,在内存中占用 16 位。
python run.py -m resnet_50_v15_tf_fp16.pb -p fp16
ubuntu@ai-vm:~/aio-examples/classification/resnet_50_v15$ python run.py -m resnet_50_v15_tf_fp16.pb -p fp16
/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.8) or chardet (3.0.4) doesn't match a supported version!
warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Running with 4 threads
Top-1 accuracy = 0.800
Top-5 accuracy = 1.000
Accuracy figures above calculated on the basis of 5 images.
Latency: 28 ms
Throughput: 36.29 ips
将数字与 AMD 和 Intel 实例(4 个 vCPU)进行比较
FP32 resnet_50_v15
模型:OCI Shape | $ / hr | Images per second | Performance (ips) / price |
---|---|---|---|
Ampere A1 | 0.04 | 19.23 | 480 |
AMD E4 | 0.05 | 15.43 | 308 |
Intel Standard3 | 0.08 | 18.24 | 228 |
FP16 resnet_50_v15
模型:OCI Shape | $ / hr | Images per second | Performance (ips) / price |
---|---|---|---|
Ampere A1 | 0.04 | 36.29 | 907 |
Jupyter Notebook 的可视化示例
cd ~/.aio-examples
./start_notebook.sh
buntu@ai-vm:~/aio-examples$ ./start_notebook.sh
On your local system please open a new terminal window and run:
ssh -N -L 8080:localhost:8080 -i ./your_key.key your_user@xxx.xxx.xxx.xxx
After that open one of the links printed out below in your local browser
[I 23:08:01.841 NotebookApp] Writing notebook server cookie secret to /home/ubuntu/.local/share/jupyter/runtime/notebook_cookie_secret
[I 23:08:02.270 NotebookApp] Serving notebooks from local directory: /home/ubuntu/aio-examples
[I 23:08:02.270 NotebookApp] Jupyter Notebook 6.4.8 is running at:
[I 23:08:02.270 NotebookApp] http://localhost:8080/?token=fd98a68431793485bb9dbf8590ad6f571dbabbfa96757b37
[I 23:08:02.270 NotebookApp] or http://127.0.0.1:8080/?token=fd98a68431793485bb9dbf8590ad6f571dbabbfa96757b37
[I 23:08:02.270 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 23:08:02.274 NotebookApp]
To access the notebook, open this file in a browser:
file:///home/ubuntu/.local/share/jupyter/runtime/nbserver-1367-open.html
Or copy and paste one of these URLs:
http://localhost:8080/?token=fd98a68431793485bb9dbf8590ad6f571dbabbfa96757b37
or http://127.0.0.1:8080/?token=fd98a68431793485bb9dbf8590ad6f571dbabbfa96757b37
ssh -N -L 8080:localhost:8080 -i ./your_key.key your_user@xxx.xxx.xxx.xxx
http://localhost:8080/?token=....
)。

classifications
文件夹,然后单击examples.ipynb
项目。