From 449608e8105c7cc0a274ea98e43f64c9586bb7b6 Mon Sep 17 00:00:00 2001 From: wizardforcel <562826179@qq.com> Date: Fri, 14 Aug 2020 17:59:05 +0800 Subject: [PATCH] 2020-08-14 17:59:04 --- docs/tf-1x-dl-cookbook/12.md | 58 +++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/docs/tf-1x-dl-cookbook/12.md b/docs/tf-1x-dl-cookbook/12.md index b956fd23..b8e2ee50 100644 --- a/docs/tf-1x-dl-cookbook/12.md +++ b/docs/tf-1x-dl-cookbook/12.md @@ -16,7 +16,7 @@ 每个 TensorFlow 计算均以图形描述。 这允许在结构和操作的放置方面具有自然的灵活性,可以在计算的分布式节点之间拆分操作。 该图可以拆分为多个子图,这些子图分配给服务器集群中的不同节点。 -我强烈建议读者看一看大型分布式深度网络 Jeffrey Dean,Greg S.Corrado,Rajat Monga,Kai Chen,Matthieu Devin,Quoc V.Le,Mark Z.Mao,Marc'Aurelio Ranzato,Andrew Senior ,Paul Tucker,Ke Yang 和 Andrew Y. Ng。 NIPS,2012 年, [https://research.google.com/archive/large_deep_networks_nips2012.html](https://research.google.com/archive/large_deep_networks_nips2012.html) +我强烈建议读者看一看[大型分布式深度网络](https://research.google.com/archive/large_deep_networks_nips2012.html)(Jeffrey Dean,Greg S.Corrado,Rajat Monga,Kai Chen,Matthieu Devin,Quoc V.Le,Mark Z.Mao,Marc'Aurelio Ranzato,Andrew Senior ,Paul Tucker,Ke Yang 和 Andrew Y. Ng。 NIPS,2012 年) 本文的一项关键结果是证明可以运行分布式**随机梯度下降**(**SDG**),其中多个节点在数据碎片上并行工作,并且独立且异步地更新 通过将更新发送到参数服务器来实现渐变。 引用论文摘要: @@ -28,7 +28,7 @@ An example of distributed gradient descent with a parameter server as taken from [https://research.google.com/archive/large_deep_networks_nips2012.html](https://research.google.com/archive/large_deep_networks_nips2012.html) -您应该阅读的另一份文档是白皮书 *TensorFlow:异构分布式系统上的大规模机器学习*MartínAbadi 等人,2015 年 11 月, [http://download.tensorflow.org/paper/ whitepaper2015.pdf](http://download.tensorflow.org/paper/whitepaper2015.pdf) +您应该阅读的另一份文档是白皮书 [TensorFlow:异构分布式系统上的大规模机器学习](http://download.tensorflow.org/paper/whitepaper2015.pdf)(MartínAbadi 等人,2015 年 11 月) 考虑其中包含的一些示例,我们可以在下面的图片的左侧看到 TensorFlow 代码的片段,然后将其表示为右侧的图形: @@ -60,7 +60,7 @@ An example of synchronous and asynchronous data parallel training # 做好准备 -第一步是安装支持 GPU 的 TensorFlow 版本。 正式的 TensorFlow 安装说明是您的起点 [https://www.tensorflow.org/](https://www.tensorflow.org/) 。 请记住,您需要一个通过 CUDA 或 CuDNN 支持 GPU 的环境。 +第一步是安装支持 GPU 的 TensorFlow 版本。 [正式的 TensorFlow 安装说明是您的起点](https://www.tensorflow.org/)。 请记住,您需要一个通过 CUDA 或 CuDNN 支持 GPU 的环境。 # 怎么做... @@ -117,7 +117,7 @@ print("Time taken:", datetime.now() - startTime) # 做好准备 -此食谱的灵感来自尼尔·特内霍尔茨(Neil Tenenholtz)撰写的一篇不错的博客文章,该文章可在线获取: [https://clindatsci.com/blog/2017/5/31/distributed-tensorflow](https://clindatsci.com/blog/2017/5/31/distributed-tensorflow) +此食谱的灵感来自尼尔·特内霍尔茨(Neil Tenenholtz)撰写的一篇不错的博客文章,[该文章可在线获取](https://clindatsci.com/blog/2017/5/31/distributed-tensorflow) # 怎么做... @@ -189,7 +189,7 @@ with tf.Session() as sess: # 做好准备 -同样,此食谱的灵感来自尼尔·特纳霍尔茨(Neil Tenenholtz)撰写的一篇不错的博客文章,该文章可在线获取: [https://clindatsci.com/blog/2017/5/31/distributed-tensorflow](https://clindatsci.com/blog/2017/5/31/distributed-tensorflow) +同样,此食谱的灵感来自尼尔·特纳霍尔茨(Neil Tenenholtz)撰写的一篇不错的博客文章,[该文章可在线获取](https://clindatsci.com/blog/2017/5/31/distributed-tensorflow) # 怎么做... @@ -252,13 +252,13 @@ with tf.Session(server.target): # 还有更多... -可以在 [https://github.com/ischlag/distributed-tensorflow-example/blob/master/example.py](https://github.com/ischlag/distributed-tensorflow-example/blob/master/example.py) 在线获取针对 MNIST 的分布式训练的示例。 +可以在[这个页面](https://github.com/ischlag/distributed-tensorflow-example/blob/master/example.py)在线获取针对 MNIST 的分布式训练的示例。 -此外,请注意,出于效率考虑,您可以决定拥有多个参数服务器。 使用参数,服务器可以提供更好的网络利用率,并且可以将模型扩展到更多并行计算机。 可以分配多个参数服务器。 有兴趣的读者可以看看 [https://www.tensorflow.org/deploy/distributed](https://www.tensorflow.org/deploy/distributed) +此外,请注意,出于效率考虑,您可以决定拥有多个参数服务器。 使用参数,服务器可以提供更好的网络利用率,并且可以将模型扩展到更多并行计算机。 可以分配多个参数服务器。 有兴趣的读者可以看看[这里](https://www.tensorflow.org/deploy/distributed) # 训练分布式 TensorFlow MNIST 分类器 -此配方用于以分布式方式训练完​​整的 MNIST 分类器。 该食谱的灵感来自 [http://ischlag.github.io/2016/06/12/async-distributed-tensorflow/](http://ischlag.github.io/2016/06/12/async-distributed-tensorflow/) 中的博客文章,此处提供了在 TensorFlow 1.2 上运行的代码 [https://github.com/ischlag/distributed-tensorflow-example](https://github.com/ischlag/distributed-tensorflow-example) +此配方用于以分布式方式训练完​​整的 MNIST 分类器。 该食谱的灵感来自[这个页面](http://ischlag.github.io/2016/06/12/async-distributed-tensorflow/)中的博客文章,[此处提供了在 TensorFlow 1.2 上运行的代码](https://github.com/ischlag/distributed-tensorflow-example) # 做好准备 @@ -417,7 +417,7 @@ with sv.prepare_or_wait_for_session(server.target) as sess: # 做好准备 -我们将使用 Docker,并假设您熟悉该系统。 如果没有,请确保查看并安装 [https://www.docker.com/](https://www.docker.com/) 。 我们要做的是构建 TF 服务版本。 +我们将使用 Docker,并假设您熟悉该系统。 如果没有,[请确保查看并安装](https://www.docker.com/)。 我们要做的是构建 TF 服务版本。 # 怎么做... @@ -446,7 +446,7 @@ cd .. bazel test tensorflow_serving/... ``` -5. 现在,让我们看一个保存模型的示例,以便服务器可以保存它。 此步骤的灵感来自用于构建 MNIST 训练器和服务模型的示例(请参见 [https://github.com/tensorflow/serving/blob/master/tensorflow_serving/example/mnist_saved_model.py](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/example/mnist_saved_model.py) )。 第一步是将构建器导入为 saved_model_builder。 然后,大部分工作由`SavedModelBuilder()`完成,该工作将已训练模型的*快照*保存到可靠的存储中。 请注意,此处`export_path`是/ tmp / mnist_model / +5. 现在,让我们看一个保存模型的示例,以便服务器可以保存它。 此步骤的灵感来自[用于构建 MNIST 训练器和服务模型的示例](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/example/mnist_saved_model.py)。 第一步是将构建器导入为 saved_model_builder。 然后,大部分工作由`SavedModelBuilder()`完成,该工作将已训练模型的*快照*保存到可靠的存储中。 请注意,此处`export_path`是/ tmp / mnist_model / ```py from tensorflow.python.saved_model import builder as saved_model_builder @@ -477,11 +477,11 @@ tensorflow_model_server --port=9000 --model_name=mnist --model_base_path=/tmp/mn # 这个怎么运作... -Google 在 2016 年 2 月发布了 TensorFlow Serving( [https://www.tensorflow.org/serving/](https://www.tensorflow.org/serving/) ),这是一种针对机器学习模型的高性能服务系统,专为生产环境而设计。 截至 2017 年 8 月,谷歌内部有 800 多个使用 TensorFlow Serving 的项目投入生产。 +Google 在 2016 年 2 月发布了 [TensorFlow Serving](https://www.tensorflow.org/serving/),这是一种针对机器学习模型的高性能服务系统,专为生产环境而设计。 截至 2017 年 8 月,谷歌内部有 800 多个使用 TensorFlow Serving 的项目投入生产。 # 还有更多... -TensoFlow Serving 是一款非常通用的软件,在本食谱中,我们只是初步探究了潜在用途。 如果您有兴趣进一步了解高级功能。 例如大批量运行或动态加载模型,则应查看 [https://github.com/tensorflow/serving/blob/master/tensorflow_serving/g3doc/serving_advanced.md](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/g3doc/serving_advanced.md) +TensoFlow Serving 是一款非常通用的软件,在本食谱中,我们只是初步探究了潜在用途。 如果您有兴趣进一步了解高级功能。 例如大批量运行或动态加载模型,则应查看[这个页面](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/g3doc/serving_advanced.md) # 使用 Compute Engine 在 Google Cloud(GCP)上运行分布式 TensorFlow @@ -489,13 +489,13 @@ TensoFlow Serving 是一款非常通用的软件,在本食谱中,我们只 # 做好准备 -看看 GCP 在 [https://cloud.google.com/](https://cloud.google.com/) 中的工作方式会很好。 请注意,GCP 提供 300 美元的免费赠金,以开始使用任何 GCP 产品。 此外,在免费试用期间和之后,某些产品针对符合条件的客户可以免费使用。 (优惠如有更改,请参见 [https://cloud.google.com/free/](https://cloud.google.com/free/) )。 +看看 GCP 在 [GoogleCloud](https://cloud.google.com/) 中的工作方式会很好。 请注意,GCP 提供 300 美元的免费赠金,以开始使用任何 GCP 产品。 此外,在免费试用期间和之后,某些产品针对符合条件的客户可以免费使用。 (优惠如有更改,请参见[这个页面](https://cloud.google.com/free/)。 # 怎么做... 这是我们进行食谱的方法: -1. 通过网络控制台 [https://pantheon.google.com/cloud-resource-manager](https://pantheon.google.com/cloud-resource-manager) 创建一个新的 Google Cloud 项目。 +1. [通过网络控制台](https://pantheon.google.com/cloud-resource-manager)创建一个新的 Google Cloud 项目。 ![](img/d91fcd12-0e0f-49ac-8a2f-976810b3e96d.png) @@ -507,7 +507,7 @@ TensoFlow Serving 是一款非常通用的软件,在本食谱中,我们只 | ![](img/41ea2e03-f1d7-4aac-a6e3-33db31053786.png) | ![](img/ed57ff64-af8b-43fb-a692-892811cf9dfb.png) | -3. 登录到网络 cloudshell [https://pantheon.google.com/cloudshell/editor](https://pantheon.google.com/cloudshell/editor) ? +3. 登录到网络 [cloudshell](https://pantheon.google.com/cloudshell/editor)。 ![](img/848d8c7b-e216-41ff-82f2-17c390720f1e.png) @@ -573,7 +573,7 @@ gcloud compute instances create \ # 还有更多... -如果我们不想管理 TensorFlow,那么我们可以决定使用 Google 代表您运行的托管版本。 这是在下一个食谱中描述的 CloudML 服务。 此外,如果您决定不将 GPU 与 CloudML 一起使用,那么此 URL 是一个不错的起点 [https://cloud.google.com/ml-engine/docs/using-gpus](https://cloud.google.com/ml-engine/docs/using-gpus) +如果我们不想管理 TensorFlow,那么我们可以决定使用 Google 代表您运行的托管版本。 这是在下一个食谱中描述的 CloudML 服务。 此外,如果您决定不将 GPU 与 CloudML 一起使用,[那么此 URL 是一个不错的起点](https://cloud.google.com/ml-engine/docs/using-gpus) # 在 Google CloudML 上运行分布式 TensorFlow @@ -581,7 +581,7 @@ CloudML 是 Google 运行的 Tensorflow 的托管版本。 无需自己运行 TF # 做好准备 -在这里,我们假设您已经创建了一个 Cloud Platform Project,为您的项目启用计费,并启用了 Google Compute Engine 和 Cloud Machine Learning API。 这些步骤类似于先前食谱中描述的步骤。 此食谱的灵感来自 [https://cloud.google.com/ml-engine/docs/distributed-tensorflow-mnist-cloud-datalab](https://cloud.google.com/ml-engine/docs/distributed-tensorflow-mnist-cloud-datalab) 中提供的 MNIST 训练代码。 +在这里,我们假设您已经创建了一个 Cloud Platform Project,为您的项目启用计费,并启用了 Google Compute Engine 和 Cloud Machine Learning API。 这些步骤类似于先前食谱中描述的步骤。 此食谱的灵感来自[这个页面](https://cloud.google.com/ml-engine/docs/distributed-tensorflow-mnist-cloud-datalab)中提供的 MNIST 训练代码。 # 怎么做... @@ -589,8 +589,10 @@ CloudML 是 Google 运行的 Tensorflow 的托管版本。 无需自己运行 TF 1. 第一步只是下载示例代码 -git clone [https://github.com/GoogleCloudPlatform/cloudml-dist-mnist-example](https://github.com/GoogleCloudPlatform/cloudml-dist-mnist-example) +```py +git clonehttps://github.com/GoogleCloudPlatform/cloudml-dist-mnist-example cd cloudml-dist-mnist-example +``` 2. 然后,我们下载数据并将其保存在 GCP 存储桶中 @@ -621,7 +623,7 @@ gcloud ml-engine jobs submit training ${JOB_NAME} \ --train_steps 10000 ``` -4. 如果需要,您可以通过访问 [https://pantheon.google.com/mlengine/](https://pantheon.google.com/mlengine/) 中的 CloudML 控制台来控制训练过程。 +4. 如果需要,您可以通过访问[这个页面](https://pantheon.google.com/mlengine/)中的 CloudML 控制台来控制训练过程。 5. 训练结束后,就可以直接从 CloudML 服务模型了 ```py @@ -648,7 +650,7 @@ CloudML 是使用 Google 运行的托管版本的 TensorFlow 的便捷解决方 # 还有更多... -CloudML 的一项非常酷的功能是能够通过并行运行多个试验来自动调整模型中包含的超参数的能力。 这为您提供了超参数的优化值,从而最大化了模型的预测精度。 如果您有兴趣了解更多信息,那么看看 [https://cloud.google.com/ml-engine/docs/hyperparameter-tuning-overview](https://cloud.google.com/ml-engine/docs/hyperparameter-tuning-overview) +CloudML 的一项非常酷的功能是能够通过并行运行多个试验来自动调整模型中包含的超参数的能力。 这为您提供了超参数的优化值,从而最大化了模型的预测精度。 如果您有兴趣了解更多信息,那么看看[这里](https://cloud.google.com/ml-engine/docs/hyperparameter-tuning-overview) # 在 Microsoft Azure 上运行分布式 TensorFlow @@ -656,13 +658,13 @@ Microsoft Azure 提供了一项名为 Batch AI 的服务,该服务使我们能 # 做好准备 -第一步,我们需要一个 Azure 帐户:如果您还没有 Azure 帐户,则可以在此处免费创建一个帐户: [https://azure.microsoft.com/zh-cn/services/batch-ai /](https://azure.microsoft.com/en-us/services/batch-ai/) 。 Azure 向新用户提供为期 30 天的$ 200 信用额度。 此食谱将遵循 Microsoft Azure 提供的示例,以使用 TensorFlow 分布式在两个 GPU 上运行 MNIST,相关代码可在 Github 上获得: [https://github.com/Azure/batch-shipyard/tree/master/recipes / TensorFlow-Distributed](https://github.com/Azure/batch-shipyard/tree/master/recipes/TensorFlow-Distributed) +第一步,我们需要一个 Azure 帐户:如果您还没有 Azure 帐户,则可以[在此处免费创建一个帐户](https://azure.microsoft.com/en-us/services/batch-ai/) 。 Azure 向新用户提供为期 30 天的$ 200 信用额度。 此食谱将遵循 Microsoft Azure 提供的示例,以使用 TensorFlow 分布式在两个 GPU 上运行 MNIST,相关代码可[在 Github 上获得](https://github.com/Azure/batch-shipyard/tree/master/recipes/TensorFlow-Distributed) # 怎么做... 我们按以下步骤进行: -1. 第一步是安装 Azure CLI。 可在此处 [https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) [获得在不同 OS 平台上安装 Azure CLI 的详细信息。](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) 。 +1. 第一步是安装 Azure CLI。 可在[此处](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)获得在不同 OS 平台上安装 Azure CLI 的详细信息。 2. 在创建群集之前,您需要使用命令`az login`登录 Azure。 它将生成一个代码,并为您提供一个网站地址,将要求您在其中验证您的凭据,一旦网站上的所有步骤都结束,将要求您关闭并验证您的 az 凭据。 3. 配置默认位置,创建和配置资源组。 @@ -672,7 +674,7 @@ az configure --defaults group=myResourceGroup az configure --defaults location=eastus ``` -4. 接下来,我们将需要使用命令创建存储,并根据您的操作系统设置环境变量,有关环境变量及其值的详细信息,请参见 [https://docs.microsoft.com/zh-cn / azure / batch-ai / quickstart-cli](https://docs.microsoft.com/en-us/azure/batch-ai/quickstart-cli) +4. 接下来,我们将需要使用`az`命令创建存储,并根据您的操作系统设置环境变量,有关环境变量及其值的详细信息,请参见[这里](https://docs.microsoft.com/en-us/azure/batch-ai/quickstart-cli) 5. 下载并提取预处理的 MNIST 数据库 @@ -768,13 +770,13 @@ az batchai job stream-file --job-name myjob --output-directory-id stdouterr --na # 还有更多... -上面我们学习了如何使用 Azure 命令行工具将 Microsoft Azure Batch AI 用于分布式 TensorFlow。 我们也可以使用 Jupyter Notebook 做同样的事情。 这将涉及设置 Azure Active Directory 并进行新的 App 注册。 可以在以下链接上获得详细信息: [https://docs.microsoft.com/zh-cn/azure/azure-resource-manager/resource-group-create-service-principal-portal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal) 。 +上面我们学习了如何使用 Azure 命令行工具将 Microsoft Azure Batch AI 用于分布式 TensorFlow。 我们也可以使用 Jupyter Notebook 做同样的事情。 这将涉及设置 Azure Active Directory 并进行新的 App 注册。 [可以在以下链接上获得详细信息](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal)。 -Azure BatchAI 也可以与其他 AI 深度学习库一起使用,我们建议您仔细阅读 BatchAI Github 以获取更多详细信息: [https://github.com/Azure/BatchAI](https://github.com/Azure/BatchAI) 。 +Azure BatchAI 也可以与其他 AI 深度学习库一起使用,我们建议您仔细阅读 BatchAI Github [以获取更多详细信息](https://github.com/Azure/BatchAI)。 # 在 Amazon AWS 上运行分布式 TensorFlow -Amazon AWS 提供了配备 NVIDIA K8 GPU 的 P2.x 机器。 为了能够使用,第一步再次涉及创建一个 Amazon AWS 账户。 如果还没有,可以使用以下链接创建它: [https://portal.aws.amazon.com/billing/signup?nc2=h_ct & redirect_url = https%3A%2F%2Faws .amazon.com%2Fregistration-confirmation#/ start](https://portal.aws.amazon.com/billing/signup?nc2=h_ct&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start) 。 登录帐户后,仪表板将如下所示: +Amazon AWS 提供了配备 NVIDIA K8 GPU 的 P2.x 机器。 为了能够使用,第一步再次涉及创建一个 Amazon AWS 账户。 如果还没有,[可以使用以下链接创建它](https://portal.aws.amazon.com/billing/signup?nc2=h_ct&redirect_url=https%3A%2F%2Faws.amazon.com%2Fregistration-confirmation#/start)。 登录帐户后,仪表板将如下所示: ![](img/b32ea001-d1a5-464b-b2ec-a1a43c8d1001.png) @@ -822,7 +824,7 @@ ssh -i " .pem" ubuntu@ec2-XXXXXXXXXXXXX.compute-1.ama # 这个怎么运作... -您可以运行在我们创建的实例上学到的代码。 工作结束后,不要忘记退出,并从仪表板停止实例。 有关价格和使用情况的更多详细信息,请参见: [https://aws.amazon.com/documentation/ec2/](https://aws.amazon.com/documentation/ec2/) +您可以运行在我们创建的实例上学到的代码。 工作结束后,不要忘记退出,并从仪表板停止实例。 有关价格和使用情况的更多详细信息,请参见[这里](https://aws.amazon.com/documentation/ec2/) # 还有更多... @@ -833,4 +835,4 @@ http://0.0.0.0:8888 /?token = 3156e ... 您将 URL 复制并粘贴到浏览器中,就可以开始使用了。 -此外,可以通过查看 AWS CloudFormation 简化整个过程。 它使用模板创建和配置 Amazon Web Services 资源。 这样可以简化设置分布式深度学习集群的过程。 有兴趣的读者可以看看 [https://aws.amazon.com/blogs/compute/distributed-deep-learning-made-easy/](https://aws.amazon.com/blogs/compute/distributed-deep-learning-made-easy/) \ No newline at end of file +此外,可以通过查看 AWS CloudFormation 简化整个过程。 它使用模板创建和配置 Amazon Web Services 资源。 这样可以简化设置分布式深度学习集群的过程。 有兴趣的读者可以看看[这里](https://aws.amazon.com/blogs/compute/distributed-deep-learning-made-easy/) \ No newline at end of file -- GitLab