From cb4b1ba3a448a30c1151376272dd7631d1300c69 Mon Sep 17 00:00:00 2001 From: Xiao Yu Date: Wed, 15 May 2019 13:55:27 -0700 Subject: [PATCH] Remove tailing slash in profiler tutorial (#2236) --- docs/r2/tensorboard_profiling_keras.ipynb | 105 ++++++++++------------ 1 file changed, 47 insertions(+), 58 deletions(-) diff --git a/docs/r2/tensorboard_profiling_keras.ipynb b/docs/r2/tensorboard_profiling_keras.ipynb index cfdf536ed2..e659003b4f 100644 --- a/docs/r2/tensorboard_profiling_keras.ipynb +++ b/docs/r2/tensorboard_profiling_keras.ipynb @@ -7,8 +7,7 @@ "version": "0.3.2", "provenance": [], "collapsed_sections": [], - "toc_visible": true, - "include_colab_link": true + "toc_visible": true }, "kernelspec": { "name": "python3", @@ -19,31 +18,21 @@ "cells": [ { "cell_type": "markdown", - "metadata": { - "id": "view-in-github", - "colab_type": "text" - }, - "source": [ - "\"Open" - ] - }, - { "metadata": { "id": "djUvWu41mtXa", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "##### Copyright 2019 The TensorFlow Authors." ] }, { + "cell_type": "code", "metadata": { "id": "su2RaORHpReL", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "#@title Licensed under the Apache License, Version 2.0 (the \"License\");\n", "# you may not use this file except in compliance with the License.\n", @@ -61,11 +50,11 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "NztQK2uFpXT-", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "# TensorBoard Profile: Profiling basic training metrics in Keras\n", "\n", @@ -83,11 +72,11 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "eDXRFe_qp5C3", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "\n", "## Overview\n", @@ -97,11 +86,11 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "dG-nnZK9qW9z", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "## Prerequisites\n", "\n", @@ -110,21 +99,22 @@ "\n", "* Select “GPU” in the Accelerator drop-down in Notebook Settings (Assuming you run this notebook on Colab).\n", "\n", - ">![Notebook Settings](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-notebook-settings.png?raw=1\\)\n", + ">![Notebook Settings](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-notebook-settings.png?raw=1)\n", "\n" ] }, { + "cell_type": "markdown", "metadata": { "id": "DZhGh-G7KoKL", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "## Setup" ] }, { + "cell_type": "code", "metadata": { "id": "3U5gdCw_nSG3", "colab_type": "code", @@ -134,7 +124,6 @@ "height": 119 } }, - "cell_type": "code", "source": [ "# Ensure latest TensorFlow is installed.\n", "!pip install -q tf-nightly-gpu-2.0-preview\n", @@ -159,6 +148,7 @@ ] }, { + "cell_type": "code", "metadata": { "id": "1qIKtOBrqc9Y", "colab_type": "code", @@ -168,7 +158,6 @@ "height": 34 } }, - "cell_type": "code", "source": [ "from __future__ import absolute_import\n", "from __future__ import division\n", @@ -199,16 +188,17 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "8ZM-6NzYgPRn", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Confirm TensorFlow can see the GPU." ] }, { + "cell_type": "code", "metadata": { "id": "gp2p-MemgAIh", "colab_type": "code", @@ -218,7 +208,6 @@ "height": 34 } }, - "cell_type": "code", "source": [ "device_name = tf.test.gpu_device_name()\n", "if device_name != '/device:GPU:0':\n", @@ -237,11 +226,11 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "6YDAoNCN3ZNS", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "## Run a simple model with TensorBoard callback\n", "\n", @@ -252,12 +241,12 @@ ] }, { + "cell_type": "code", "metadata": { "id": "ImCFrQ74eerE", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "BATCH_NORM_DECAY = 0.997\n", "BATCH_NORM_EPSILON = 1e-5\n", @@ -519,22 +508,22 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "1lAek-Lye8_q", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Download CIFAR-10 data from [TensorFlow Datasets](https://www.tensorflow.org/datasets)." ] }, { + "cell_type": "code", "metadata": { "id": "H8A67-bNXzsx", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "cifar_builder = tfds.builder('cifar10')\n", "cifar_builder.download_and_prepare()\n" @@ -543,22 +532,22 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "21jm6LOSq9EN", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Build data input pipeline and compile ResNet56 model." ] }, { + "cell_type": "code", "metadata": { "id": "j-ryO6OxnQH_", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "HEIGHT = 32\n", "WIDTH = 32\n", @@ -604,11 +593,11 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "_5llFQBKHFmA", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "When creating TensorBoard callback, you can specify the batch num you want to profile. By default, TensorFlow will profile the second batch, because many one time graph optimizations run on the first batch. You can modify it by setting `profile_batch`. You can also turn off profiling by setting it to 0.\n", "\n", @@ -616,12 +605,12 @@ ] }, { + "cell_type": "code", "metadata": { "id": "WmY-2znGJxNY", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "log_dir=\"logs/profile/\" + datetime.now().strftime(\"%Y%m%d-%H%M%S\")\n", "\n", @@ -631,16 +620,17 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "ylDhh7zlJ273", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Start training by calling [Model.fit()](https://https://www.tensorflow.org/api_docs/python/tf/keras/models/Model#fit). " ] }, { + "cell_type": "code", "metadata": { "id": "LEb_1HETJ_tX", "colab_type": "code", @@ -650,7 +640,6 @@ "height": 275 } }, - "cell_type": "code", "source": [ "model.fit(train_data,\n", " steps_per_epoch=20,\n", @@ -732,11 +721,11 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "042k7GMERVkx", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "## Visualizing profile result using TensorBoard\n", "\n", @@ -746,12 +735,12 @@ ] }, { + "cell_type": "code", "metadata": { "id": "6pck56gKReON", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "!tar -zcvf logs.tar.gz logs/profile/" ], @@ -759,15 +748,15 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "TZOf_K4L-Nkv", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Download `logdir.tar.gz` by right-clicking it in “Files” tab.\n", "\n", - "![Download](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-download-logdir.png?raw=1\\)\n", + "![Download](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-download-logdir.png?raw=1)\n", "\n", "Please make sure you have the latest [TensorBoard](https://www.tensorflow.org/tensorboard) installed on you local machine as well. Execute following commands on your local machine:\n", "\n", @@ -782,25 +771,25 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "ciSIRibhRi6N", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Open a new tab in your Chrome browser and navigate to [localhost:6006](http://localhost:6006) and then click “Profile” tab. You may see the profile result like this:\n", "\n", - "![Trace View](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-trace-viewer.png?raw=1\\)\n", + "![Trace View](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-trace-viewer.png?raw=1)\n", "\n", "\n" ] }, { + "cell_type": "markdown", "metadata": { "id": "roE94vH9mJ6k", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "## Trace Viewer\n", "Once you click the profile tab, you will see Trace Viewer. The page displays a timeline of different events that happened on the CPU and the accelerator during the collection period.\n", @@ -813,7 +802,7 @@ "\n", "In addition to clicking, you can drag the mouse to select a rectangle covering a group of trace events. This will give you a list of events that intersect that rectangle and summarize them for you. The `m` key can be used to measure the time duration of the selected events.\n", "\n", - "![List of Events](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-trace-viewer-select.png?raw=1\\)\n", + "![List of Events](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-trace-viewer-select.png?raw=1)\n", "\n", "The trace events are collected from three sources:\n", "\n", @@ -829,26 +818,26 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "XAcO9sj4B2DK", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "## Debug Performance\n", "Now, you're going to use the Trace Viewer to improve your model's performance. \n", "\n", "Let's go back to the profile result you have just captured.\n", "\n", - "![GPU kernel](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-idle-gpu.png?raw=1\\)\n", + "![GPU kernel](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-idle-gpu.png?raw=1)\n", "\n", "GPU events show that GPU has nothing to do at all in the first harf of the step.\n", "\n", - "![CPU events](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-input-cpu.png?raw=1\\)\n", + "![CPU events](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-input-cpu.png?raw=1)\n", "\n", "CPU events show that CPU is occupied by data input pipeline in the beginning of this step.\n", "\n", - "![Runtime](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-blocking-runtime.png?raw=1\\)\n", + "![Runtime](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-blocking-runtime.png?raw=1)\n", "\n", "In TensorFlow runtime, there is a big block named `Iterator::GetNextSync`, which is a blocking call to get the next batch from data input pipeline. And it blocks the training step. So if you could prepare the input data for step `s` in `s-1` step, you can probably train this model faster.\n", "\n", @@ -856,12 +845,12 @@ ] }, { + "cell_type": "code", "metadata": { "id": "JZ6UeYx9TT2T", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "train_data = cifar_builder.as_dataset(split=tfds.Split.TRAIN)\n", "train_data = train_data.repeat()\n", @@ -877,16 +866,17 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "EfD6pnhgT7q3", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Re-run the model." ] }, { + "cell_type": "code", "metadata": { "id": "tgFqaHYBUADP", "colab_type": "code", @@ -896,7 +886,6 @@ "height": 204 } }, - "cell_type": "code", "source": [ "log_dir=\"logs/profile/\" + datetime.now().strftime(\"%Y%m%d-%H%M%S\")\n", "\n", @@ -940,22 +929,22 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "LFtVDt-9UVkn", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Woohoo! You have just improvd training performance from *~235ms/step* to *~200ms/step*. " ] }, { + "cell_type": "code", "metadata": { "id": "if5LuLl_pgna", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "!tar -zcvf logs.tar.gz logs/profile/" ], @@ -963,16 +952,16 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "aBBKSVJVp4yk", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "\n", "Download `logs` directory again to see the new profile result in TensorBoard.\n", "\n", - "![TF Runtime](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-prefetch-runtime.png?raw=1\\)\n", + "![TF Runtime](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-prefetch-runtime.png?raw=1)\n", "\n", "The big `Iterator::GetNextSync` block is not there anymore.\n", "\n", @@ -991,11 +980,11 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "pLfa4vMn626q", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "## Other ways for profiling\n", "In addition to TensorBoard callback, TensorFlow also provides two additional way to trigger profiler manually: *Profiler APIs* and *Profiler Service*.\n", @@ -1008,22 +997,22 @@ ] }, { + "cell_type": "markdown", "metadata": { "id": "gt9Dm8PkL1FI", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "### Profiler APIs" ] }, { + "cell_type": "code", "metadata": { "id": "VYywGzC2GQ8w", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "# Context manager APIs\n", "with tf.python.eager.profiler.Profiler('logdir_path'):\n", @@ -1041,23 +1030,23 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "NSHEq0rIHHBs", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "### Profiler Service\n", "\n" ] }, { + "cell_type": "code", "metadata": { "id": "USTAe02KHcql", "colab_type": "code", "colab": {} }, - "cell_type": "code", "source": [ "# This API will start a gRPC server with your TensorFlow job which can receive\n", "# on-demand profiling request.\n", @@ -1069,15 +1058,15 @@ "outputs": [] }, { + "cell_type": "markdown", "metadata": { "id": "AgIro3xQIXUa", "colab_type": "text" }, - "cell_type": "markdown", "source": [ "Then you can send profiling request to profiler server to perform on-demand profiling on TensorBoard by clicking the “Capture Profile” button:\n", "\n", - "![CAPTURE PROFILE](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-capture.png?raw=1\\)\n", + "![CAPTURE PROFILE](https://github.com/tensorflow/tensorboard/blob/master/docs/r2/images/profiler-capture.png?raw=1)\n", "\n", "A message will show up after successfully captured. Then you can refresh TensorBoard to visualize the result." ]