{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "N7ITxKLUkX0v" }, "source": [ "##### Copyright 2020 The TensorFlow Authors." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "cellView": "form", "execution": { "iopub.execute_input": "2022-12-14T21:18:28.184238Z", "iopub.status.busy": "2022-12-14T21:18:28.183616Z", "iopub.status.idle": "2022-12-14T21:18:28.187586Z", "shell.execute_reply": "2022-12-14T21:18:28.187089Z" }, "id": "yOYx6tzSnWQ3" }, "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": "6xgB0Oz5eGSQ" }, "source": [ "# 그래프 및 tf.function 소개" ] }, { "cell_type": "markdown", "metadata": { "id": "w4zzZVZtQb1w" }, "source": [ "
![]() | \n",
" ![]() | \n",
" ![]() | \n",
" ![]() | \n",
"
tf.function
가이드](./function.ipynb)의 *재추적 제어* 섹션에는 재추적을 피하기 위해 입력 사양을 설정하고 텐서 인수를 사용하는 방법에 관한 설명이 나와 있습니다. 비정상적으로 성능이 저하되는 것으로 판단되면 실수로 재추적하고 있지 않은지 확인하는 것이 좋습니다."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "F4InDaTjwmBA"
},
"source": [
"## `Function`은 언제 트레이싱합니까?\n",
"\n",
"`Function`이 트레이싱을 수행하는 경우를 알아보려면 코드에 `print` 문을 추가합니다. 대략적인 규칙으로, `Function`은 트레이싱할 때마다 `print` 문을 실행합니다."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-14T21:18:39.398147Z",
"iopub.status.busy": "2022-12-14T21:18:39.397902Z",
"iopub.status.idle": "2022-12-14T21:18:39.436857Z",
"shell.execute_reply": "2022-12-14T21:18:39.436250Z"
},
"id": "hXtwlbpofLgW"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tracing!\n",
"tf.Tensor(6, shape=(), dtype=int32)\n",
"tf.Tensor(11, shape=(), dtype=int32)\n"
]
}
],
"source": [
"@tf.function\n",
"def a_function_with_python_side_effect(x):\n",
" print(\"Tracing!\") # An eager-only side effect.\n",
" return x * x + tf.constant(2)\n",
"\n",
"# This is traced the first time.\n",
"print(a_function_with_python_side_effect(tf.constant(2)))\n",
"# The second time through, you won't see the side effect.\n",
"print(a_function_with_python_side_effect(tf.constant(3)))"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"execution": {
"iopub.execute_input": "2022-12-14T21:18:39.440013Z",
"iopub.status.busy": "2022-12-14T21:18:39.439527Z",
"iopub.status.idle": "2022-12-14T21:18:39.457679Z",
"shell.execute_reply": "2022-12-14T21:18:39.457124Z"
},
"id": "inzSg8yzfNjl"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Tracing!\n",
"tf.Tensor(6, shape=(), dtype=int32)\n",
"Tracing!\n",
"tf.Tensor(11, shape=(), dtype=int32)\n"
]
}
],
"source": [
"# This retraces each time the Python argument changes,\n",
"# as a Python argument could be an epoch count or other\n",
"# hyperparameter.\n",
"print(a_function_with_python_side_effect(2))\n",
"print(a_function_with_python_side_effect(3))"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "rtN8NW6AfKye"
},
"source": [
"새 Python 인수는 항상 새 그래프 생성을 트리거하므로 추가 트레이싱이 발생합니다.\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "D1kbr5ocpS6R"
},
"source": [
"## 다음 단계\n",
"\n",
"API 참조 페이지와 tf.function
으로 성능 향상하기 가이드에서 `tf.function`에 대한 자세한 내용을 확인할 수 있습니다."
]
}
],
"metadata": {
"colab": {
"collapsed_sections": [],
"name": "intro_to_graphs.ipynb",
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 0
}