Created
July 26, 2018 09:06
-
-
Save oraoto/52c567b22f17918ba961ef902f162c36 to your computer and use it in GitHub Desktop.
memory_optimize error
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-07-26T09:00:40.597172Z", | |
"start_time": "2018-07-26T09:00:39.730275Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"import paddle.fluid as fluid\n", | |
"import paddle\n", | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-07-26T09:00:40.609484Z", | |
"start_time": "2018-07-26T09:00:40.601315Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"main = fluid.Program()\n", | |
"startup = fluid.Program()\n", | |
"\n", | |
"with fluid.program_guard(main, startup):\n", | |
" a = fluid.layers.data('a', [1, 2,2], dtype='float32')\n", | |
" a = fluid.layers.abs(a)\n", | |
" b = fluid.layers.data('b', [1, 2,2], dtype='float32')\n", | |
" b = fluid.layers.abs(b)\n", | |
" cost = fluid.layers.square_error_cost(a, b)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-07-26T09:00:40.716227Z", | |
"start_time": "2018-07-26T09:00:40.613165Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"def test():\n", | |
" with fluid.program_guard(main):\n", | |
" result = exe.run(main, fetch_list=[cost, a, b], feed={\n", | |
" 'a': np.array([1., 2., 3., 4.]).reshape(1, 2, 2).astype('float32'),\n", | |
" 'b': np.array([1., 2., 3., 4.]).reshape(1, 2, 2).astype('float32')\n", | |
" })\n", | |
" print(\"Cost\", result[0])\n", | |
" print(\"a\", result[1])\n", | |
" print(\"b\", result[2])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-07-26T09:00:40.771057Z", | |
"start_time": "2018-07-26T09:00:40.720298Z" | |
} | |
}, | |
"outputs": [], | |
"source": [ | |
"exe = fluid.Executor(fluid.CPUPlace())\n", | |
"_ = exe.run(startup)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-07-26T09:00:40.892455Z", | |
"start_time": "2018-07-26T09:00:40.774909Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"('Cost', array([[[0., 0.],\n", | |
" [0., 0.]]], dtype=float32))\n", | |
"('a', array([[[1., 2.],\n", | |
" [3., 4.]]], dtype=float32))\n", | |
"('b', array([[[1., 2.],\n", | |
" [3., 4.]]], dtype=float32))\n" | |
] | |
} | |
], | |
"source": [ | |
"## 正确结果\n", | |
"test()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-07-26T09:00:40.945846Z", | |
"start_time": "2018-07-26T09:00:40.896361Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Hit Cache !!!! cache pool index is 0, var name is abs_1.tmp_0, cached var name is a, var shape is [-1L, 1L, 2L, 2L] \n", | |
"Hit Cache !!!! cache pool index is 0, var name is square_error_cost_0.tmp_0, cached var name is b, var shape is [-1L, 1L, 2L, 2L] \n", | |
"Hit Cache !!!! cache pool index is 0, var name is square_error_cost_0.tmp_1, cached var name is abs_0.tmp_0, var shape is [-1L, 1L, 2L, 2L] \n" | |
] | |
} | |
], | |
"source": [ | |
"## 执行memory_optimize\n", | |
"fluid.transpiler.memory_optimize(main, print_log=True)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": { | |
"ExecuteTime": { | |
"end_time": "2018-07-26T09:00:41.080010Z", | |
"start_time": "2018-07-26T09:00:40.948594Z" | |
} | |
}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"('Cost', array([[[0., 0.],\n", | |
" [0., 0.]]], dtype=float32))\n", | |
"('a', array([[[0., 0.],\n", | |
" [0., 0.]]], dtype=float32))\n", | |
"('b', array([[[1., 2.],\n", | |
" [3., 4.]]], dtype=float32))\n" | |
] | |
} | |
], | |
"source": [ | |
"# 错误结果\n", | |
"test()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.15" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment