diff --git a/python/paddle/fluid/compiler.py b/python/paddle/fluid/compiler.py index 4441481093fb5068b770d7f739424bfb1609e5a0..8f60f6f8b54f799b2495f92ac5b1914ed68387f7 100644 --- a/python/paddle/fluid/compiler.py +++ b/python/paddle/fluid/compiler.py @@ -224,12 +224,10 @@ class CompiledProgram(object): self._build_strategy.trainers_endpoints = tps self._persistable_vars = [] - for block_id in range(self._program_desc.num_blocks()): - bdesc = self._program_desc.block(block_id) - self._persistable_vars.extend([ - cpt.to_text(v.name()) for v in bdesc.all_vars() - if v.persistable() and v.type() != core.VarDesc.VarType.RAW - ]) + for node in self._graph.nodes(): + if node.is_var() and node.var() is not None and node.var().persistable() and \ + node.var().type() != core.VarDesc.VarType.RAW: + self._persistable_vars.append(cpt.to_text(node.name())) places = list(map(_place_obj, self._places)) diff --git a/python/paddle/fluid/contrib/slim/tests/test_quantization_pass.py b/python/paddle/fluid/contrib/slim/tests/test_quantization_pass.py index 3b82380f9433d4efc1e2a314165ed14e7bd6fdcb..c6a301b7f41d69bed6398f826304bcefdad4f84d 100644 --- a/python/paddle/fluid/contrib/slim/tests/test_quantization_pass.py +++ b/python/paddle/fluid/contrib/slim/tests/test_quantization_pass.py @@ -12,6 +12,7 @@ # see the license for the specific language governing permissions and # limitations under the license. +import os import unittest import random import numpy as np @@ -25,6 +26,9 @@ from paddle.fluid.contrib.slim.quantization import ConvertToInt8Pass from paddle.fluid.contrib.slim.quantization import TransformForMobilePass from paddle.fluid import core +os.environ["CUDA_VISIBLE_DEVICES"] = "0" +os.environ["CPU_NUM"] = "1" + def linear_fc(num): data = fluid.layers.data(name='image', shape=[1, 32, 32], dtype='float32') @@ -249,7 +253,11 @@ class TestQuantizationFreezePass(unittest.TestCase): marked_nodes.add(op) test_graph.draw('.', 'test' + dev_name + quant_type, marked_nodes) - quantized_main_program = main_graph.to_program() + build_strategy = fluid.BuildStrategy() + build_strategy.memory_optimize = False + build_strategy.enable_inplace = False + binary = fluid.CompiledProgram(main_graph.graph).with_data_parallel( + loss_name=loss.name, build_strategy=build_strategy) quantized_test_program = test_graph.to_program() iters = 5 batch_size = 8 @@ -264,7 +272,7 @@ class TestQuantizationFreezePass(unittest.TestCase): with fluid.scope_guard(scope): for _ in range(iters): data = next(train_reader()) - loss_v = exe.run(program=quantized_main_program, + loss_v = exe.run(binary, feed=feeder.feed(data), fetch_list=[loss]) if not for_ci: diff --git a/python/paddle/fluid/framework.py b/python/paddle/fluid/framework.py index 5b9dd8693190d1c9a6a71cc6bc6e6acf2a06aa6f..bde70c7c7833f97c83b0d66570ff1befa4297911 100644 --- a/python/paddle/fluid/framework.py +++ b/python/paddle/fluid/framework.py @@ -2232,10 +2232,10 @@ class IrGraph(object): Notes: the `graph` cannot contain a circle. Returns: - set(IrNode): nodes in topology order. + list(IrNode): nodes in topology order. """ ordered_nodes = core.topology_sort(self.graph) - return {IrNode(n) for n in ordered_nodes} + return [IrNode(n) for n in ordered_nodes] def build_adjacency_list(self): """ @@ -2303,7 +2303,7 @@ class IrGraph(object): """ Convert the graph into a Program. - Notes: When the graph includes backward operator nodes, the + WARN: When the graph includes backward operator nodes, the conversion process may be failed. Usually, this function is only used to convert a test graph.