{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "ISubpr_SSsiM" }, "source": [ "##### Copyright 2020 The TensorFlow Authors.\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "cellView": "form", "execution": { "iopub.execute_input": "2024-01-11T19:25:23.957806Z", "iopub.status.busy": "2024-01-11T19:25:23.957355Z", "iopub.status.idle": "2024-01-11T19:25:23.961193Z", "shell.execute_reply": "2024-01-11T19:25:23.960634Z" }, "id": "3jTMb1dySr3V" }, "outputs": [], "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", "# You may obtain a copy of the License at\n", "#\n", "# https://www.apache.org/licenses/LICENSE-2.0\n", "#\n", "# Unless required by applicable law or agreed to in writing, software\n", "# distributed under the License is distributed on an \"AS IS\" BASIS,\n", "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "# See the License for the specific language governing permissions and\n", "# limitations under the License." ] }, { "cell_type": "markdown", "metadata": { "id": "6DWfyNThSziV" }, "source": [ "# tf.function によるパフォーマンスの改善\n", "\n", "
![]() | \n",
" ![]() | \n",
" ![]() | \n",
" ![]() | \n",
"
tf.Graph
に追加してしまいます。\n",
"\n",
"トレーニングループ全体を `tf.function` にラップしたいのであれば、データを `tf.data.Dataset` としてラップし、AutoGraph にトレーニングループを動的に展開させるようにするのが最も安全な方法です。"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"execution": {
"iopub.execute_input": "2024-01-11T19:25:31.209479Z",
"iopub.status.busy": "2024-01-11T19:25:31.209202Z",
"iopub.status.idle": "2024-01-11T19:25:31.356892Z",
"shell.execute_reply": "2024-01-11T19:25:31.356232Z"
},
"id": "WGZ19LspbZ27"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"train([(1, 1), (1, 1), (1, 1)]) contains 11 nodes in its graph\n",
"train([(1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1), (1, 1)]) contains 32 nodes in its graph\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"train(<_FlatMapDataset element_spec=(TensorSpec(shape=