Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

Found a bug for if-else op

Open ktlichkid opened this issue 8 years ago • 2 comments

If the condition variable of if-else op is a scalar, it will not split it correctly and run both true block and false block with the same condition variable.

Here is a minimal environment to reproduce the issue:

import unittest
import contextlib

import paddle.fluid.core as core
import paddle.fluid.layers as layers
import paddle.fluid.framework as framework
from paddle.fluid.executor import Executor
from paddle.fluid.framework import default_startup_program
from paddle.fluid.framework import default_main_program


class TestHelper(object):
    def __init__(self):
        self._counter = layers.fill_constant(shape=[1], dtype='int64', value=1)
        self._max_len = layers.fill_constant(shape=[1], dtype='int64', value=10)
        self.cond = layers.less_than(x=self._counter, y=self._max_len)

    @contextlib.contextmanager
    def block(self):
        yield


class TestIfElse(unittest.TestCase):
    def setUp(self):
        helper = TestHelper()
        var = layers.fill_constant(shape=[1], dtype='int64', value=0)
        with helper.block():
            ie = layers.IfElse(helper.cond)
            with ie.true_block():
                ie.output(var)
            with ie.false_block():
                ie.output(var)

            if_out = ie()
            layers.Print(if_out, message="If else's output")

    def testIfElse(self):
        cpu = core.CPUPlace()
        exe = Executor(cpu)
        exe.run(default_startup_program())
        exe.run(default_main_program())


if __name__ == '__main__':
    unittest.main()

ktlichkid avatar May 17 '18 07:05 ktlichkid

It seems the issue still exists. Could you please also run this unittest after you merged your conditional block PR? THX! @qingqing01

ktlichkid avatar Jul 23 '18 09:07 ktlichkid

您好,此issue在近一个月内暂无更新,我们将于今天内关闭。若在关闭后您仍需跟进提问,可重新开启此问题,我们将在24小时内回复您。因关闭带来的不便我们深表歉意,请您谅解~感谢您对PaddlePaddle的支持! Hello, this issue has not been updated in the past month. We will close it today for the sake of other user‘s experience. If you still need to follow up on this question after closing, please feel free to reopen it. In that case, we will get back to you within 24 hours. We apologize for the inconvenience caused by the closure and thank you so much for your support of PaddlePaddle Group!

shanyi15 avatar Aug 15 '18 10:08 shanyi15