首页 > 解决方案 > 如何将 tensorflow 与 Graphcore IPU 一起使用

问题描述

我想用graphcore IPU测试性能,但我不知道怎么用tensorflow。有人可以帮我做到这一点吗?

标签: pythontensorflowartificial-intelligenceipu

解决方案


Graphcore Poplar SDK 包含两个 wheel 文件,用于安装适用于 Python 3 的 v1.15 或 v2.1 TensorFlow 的 Graphcore 端口。您应该在虚拟环境中安装两个 wheel 文件之一,然后您将需要更多能够在 IPU 设备上运行模型的步骤。

根据应用程序,需要将一些特定于 IPU 的模块导入添加到您的程序中:

from tensorflow.python.ipu import utils, ipu_compiler, scopes, loops, ipu_infeed_queue, ipu_outfeed_queue

您必须确保通过将 TensorFlow 图放置在 IPU 设备上来以 Graphcore IPU 硬件为目标,并删除代码中可能包含的任何 CPU/GPU/TPU 特定选项。然后,您可以使用自定义 IPU 编译器来编译 TensorFlow 图:

with scopes.ipu_scope("/device:IPU:0"):
compiled = ipu_compiler.compile(training_loop)

下一步是配置 IPU 设备:基本配置将包括定义您希望模型在多少个 IPU 上运行。假设您只需要一个 IPU:

config = utils.create_ipu_config()
config = utils.auto_select_ipus(config, [1])
utils.configure_ipu_system(config)

我建议阅读相关参考指南Targeting the IPU from TensorFlow作为 TensorFlow-to-Poplar API 的主要介绍。您还可以参考本文档作为在 IPU 上移植 TensorFlow 模型的实用指南,并提供一些最佳实践指南。


推荐阅读