Commit a73c656a authored by Mark Daoust's avatar Mark Daoust
Browse files

Add clarifications from discussion with @mdanatg

parent fceeb46d
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
"colab": { "colab": {
"name": "autograph.ipynb", "name": "autograph.ipynb",
"version": "0.3.2", "version": "0.3.2",
"views": {},
"default_view": {},
"provenance": [], "provenance": [],
"private_outputs": true, "private_outputs": true,
"collapsed_sections": [ "collapsed_sections": [
...@@ -36,12 +34,7 @@ ...@@ -36,12 +34,7 @@
"metadata": { "metadata": {
"id": "llMNufAK7nfK", "id": "llMNufAK7nfK",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -116,12 +109,7 @@ ...@@ -116,12 +109,7 @@
"metadata": { "metadata": {
"id": "RSez0n7Ptcvb", "id": "RSez0n7Ptcvb",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -144,12 +132,7 @@ ...@@ -144,12 +132,7 @@
"metadata": { "metadata": {
"id": "mT7meGqrZTz9", "id": "mT7meGqrZTz9",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -177,12 +160,7 @@ ...@@ -177,12 +160,7 @@
"metadata": { "metadata": {
"id": "ks_hiqcSJNvg", "id": "ks_hiqcSJNvg",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -217,12 +195,7 @@ ...@@ -217,12 +195,7 @@
"metadata": { "metadata": {
"id": "aA3gOodCBkOw", "id": "aA3gOodCBkOw",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -250,12 +223,7 @@ ...@@ -250,12 +223,7 @@
"metadata": { "metadata": {
"id": "_EMhGUjRZoKQ", "id": "_EMhGUjRZoKQ",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -278,12 +246,7 @@ ...@@ -278,12 +246,7 @@
"metadata": { "metadata": {
"id": "I1RtBvoKBxq5", "id": "I1RtBvoKBxq5",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -306,12 +269,7 @@ ...@@ -306,12 +269,7 @@
"metadata": { "metadata": {
"id": "SGjSq0WQvwGs", "id": "SGjSq0WQvwGs",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -342,12 +300,7 @@ ...@@ -342,12 +300,7 @@
"metadata": { "metadata": {
"id": "toxKBOXbB1ro", "id": "toxKBOXbB1ro",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -375,12 +328,7 @@ ...@@ -375,12 +328,7 @@
"metadata": { "metadata": {
"id": "jlyQgxYsYSXr", "id": "jlyQgxYsYSXr",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -405,12 +353,7 @@ ...@@ -405,12 +353,7 @@
"metadata": { "metadata": {
"id": "BKhFNXDic4Mw", "id": "BKhFNXDic4Mw",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -467,12 +410,7 @@ ...@@ -467,12 +410,7 @@
"metadata": { "metadata": {
"id": "IAOgh62zCPZ4", "id": "IAOgh62zCPZ4",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -507,12 +445,7 @@ ...@@ -507,12 +445,7 @@
"metadata": { "metadata": {
"id": "ySTsuxnqCTQi", "id": "ySTsuxnqCTQi",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -547,12 +480,7 @@ ...@@ -547,12 +480,7 @@
"metadata": { "metadata": {
"id": "ABX070KwCczR", "id": "ABX070KwCczR",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -591,12 +519,7 @@ ...@@ -591,12 +519,7 @@
"metadata": { "metadata": {
"id": "4yyNOf-Twr6s", "id": "4yyNOf-Twr6s",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -631,12 +554,7 @@ ...@@ -631,12 +554,7 @@
"metadata": { "metadata": {
"id": "ucmZyQVL03bF", "id": "ucmZyQVL03bF",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -667,12 +585,7 @@ ...@@ -667,12 +585,7 @@
"metadata": { "metadata": {
"id": "1sjaFcL717Ig", "id": "1sjaFcL717Ig",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -728,12 +641,7 @@ ...@@ -728,12 +641,7 @@
"metadata": { "metadata": {
"id": "xqoxumv0ssQW", "id": "xqoxumv0ssQW",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -756,12 +664,7 @@ ...@@ -756,12 +664,7 @@
"metadata": { "metadata": {
"id": "Pe-erWQdBoC5", "id": "Pe-erWQdBoC5",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -786,6 +689,9 @@ ...@@ -786,6 +689,9 @@
"\n", "\n",
"def fit(m, x, y, opt):\n", "def fit(m, x, y, opt):\n",
" l, accuracy = predict(m, x, y)\n", " l, accuracy = predict(m, x, y)\n",
" # Autograph automatically adds the necessary `tf.control_dependencies` here.\n",
" # (Without them nothing depends on `opt.minimize`, so it doesn't run.)\n",
" # This makes it much more like eager-code.\n",
" opt.minimize(l)\n", " opt.minimize(l)\n",
" return l, accuracy\n", " return l, accuracy\n",
"\n", "\n",
...@@ -826,15 +732,12 @@ ...@@ -826,15 +732,12 @@
"metadata": { "metadata": {
"id": "3xtg_MMhJETd", "id": "3xtg_MMhJETd",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
"# Use `recursive = True` to recursively convert functions called by this one.\n",
"@autograph.convert(recursive=True)\n",
"def train(train_ds, test_ds, hp):\n", "def train(train_ds, test_ds, hp):\n",
" m = mlp_model((28 * 28,))\n", " m = mlp_model((28 * 28,))\n",
" opt = tf.train.MomentumOptimizer(hp.learning_rate, 0.9)\n", " opt = tf.train.MomentumOptimizer(hp.learning_rate, 0.9)\n",
...@@ -893,12 +796,7 @@ ...@@ -893,12 +796,7 @@
"metadata": { "metadata": {
"id": "HYh6MSZyJOag", "id": "HYh6MSZyJOag",
"colab_type": "code", "colab_type": "code",
"colab": { "colab": {}
"autoexec": {
"startup": false,
"wait_interval": 0
}
}
}, },
"cell_type": "code", "cell_type": "code",
"source": [ "source": [
...@@ -909,9 +807,8 @@ ...@@ -909,9 +807,8 @@
" )\n", " )\n",
" train_ds = setup_mnist_data(True, 50)\n", " train_ds = setup_mnist_data(True, 50)\n",
" test_ds = setup_mnist_data(False, 1000)\n", " test_ds = setup_mnist_data(False, 1000)\n",
" tf_train = autograph.to_graph(train)\n",
" (train_losses, test_losses, train_accuracies,\n", " (train_losses, test_losses, train_accuracies,\n",
" test_accuracies) = tf_train(train_ds, test_ds, hp)\n", " test_accuracies) = train(train_ds, test_ds, hp)\n",
"\n", "\n",
" init = tf.global_variables_initializer()\n", " init = tf.global_variables_initializer()\n",
" \n", " \n",
...@@ -940,4 +837,4 @@ ...@@ -940,4 +837,4 @@
"outputs": [] "outputs": []
} }
] ]
} }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment