1. 24 8月, 2022 1 次提交
  2. 18 8月, 2022 1 次提交
  3. 17 8月, 2022 1 次提交
    • N
      [CodeStyle][NPU] use np.testing.assert_allclose instead of... · 2de0d676
      Nyakku Shigure 提交于
      [CodeStyle][NPU] use np.testing.assert_allclose instead of self.assertTrue(np.allclose(...)) (part 1) (#44988)
      
      * autofix
      
      * try resolve precision issues
      
      * revert some changes
      
      * clean some `err_msg`
      
      * 0.0001 -> 1e-4
      
      * update commented assert code
      
      * try to fix some shape errors
      
      * `numpy` -> `np`
      
      * empty commit, trigger kunlun ci, test=kunlun
      
      * empty commit, retrigger kunlun ci, test=kunlun
      
      * empty commit, trigger kunlun ci, try fix npu memcpy_h2d, test=kunlun
      
      * try fix npu import error, test=kunlun
      2de0d676
  4. 12 7月, 2022 1 次提交
    • X
      [ Dy2Static ]Change NameVisitor in while to FunctionScopeAnalysis (#44155) · c5c6026e
      xiongkun 提交于
      * change NameVisitor to FunctionScopeAnalysis
      
      * polish the logic of undefined var in while_loop. create vars after body execution
      
      * replace old NameVisitor in while and fix all CI
      
      * Togather with CreateVariableTransformer
      
      * add create_variable_transformer
      
      * fix bugs
      
      * merge
      
      * fix some error, TODO: ForNodePreTransform ahead
      
      * merge for unite PR
      
      * fix conflict with base_transformer PR
      
      * fix ci errors, fix [for i in range()] error
      
      * fix according to code review
      c5c6026e
  5. 28 6月, 2022 1 次提交
  6. 27 6月, 2022 1 次提交
  7. 13 6月, 2022 1 次提交
  8. 05 6月, 2022 1 次提交
    • S
      【code format check upgrade】 step2:yapf (#42944) · a072fca8
      Sing_chan 提交于
      * use yapf to format all python file
      
      * yapf exclude two unittests file for they rely on writing and reading file, and format will break them
      
      * disable diff_py_file because too many diff files cause command following failed
      a072fca8
  9. 27 5月, 2022 1 次提交
  10. 18 3月, 2022 1 次提交
  11. 15 12月, 2021 1 次提交
    • 0
      [Dy2stat]Fix error in tensor_shape_transformer. (#37999) · 50822491
      0x45f 提交于
      * fix error when tensor_shape_transformer. Before in stmt like `if len(paddle.shape(x)[0]) > 0`, `paddle` will be used as a variable
      
      * handle other call like `fluid.layers.mean` and `fluid.layers.shape`
      
      * add unit test
      50822491
  12. 11 6月, 2021 1 次提交
    • H
      [Dy2stat] Add Support for a, b = static_variable Grammar (#33499) · aa50868f
      Huihuang Zheng 提交于
      For python, if users write `a, b = var`, the `__getitem__` method will iterate through 0, 1, 2 ... until `__getitem__` throws an IndexError, then stop. The var[0], var[1] will be given to a, b respectively. If more values are given, the unpack size would cause error.
      
      We didn't raise the IndexError in the past and we add statement in `__getitem__` to raise IndexError here to support grammar like `a, b = var` in this PR.
      aa50868f
  13. 10 6月, 2021 1 次提交
  14. 11 3月, 2021 1 次提交
  15. 04 3月, 2021 1 次提交
    • H
      [Dy2stat] Fix Read-Only Attribute as while_loop Output (#31415) · 6bf02a12
      Huihuang Zheng 提交于
      Fix Read-Only Attribute as while_loop Output:
      
      Usually, our convert_while_loop will be like:
      ```
          [a, b, c] = paddle.jit.dy2static.convert_while_loop(
                  condition_name, body_name, [a, b, c])
      ```
      where a, b, c are in loop_var_names.
      
      However, if loop_var_names contains property such as foo.x, we cannot
      assign the attribute as output of convert_while_loop because Python
      property is a kind of read-only attribute. To handle the case, we replace
      the attributes which are output of convert_while_loop with generated
      variables, then if we know the attribute is not read-only at runtime, we
      assign the attribute. The created statements are like:
      ```
          [a, b, __attribute_variable_1] = paddle.jit.dy2static.convert_while_loop(
                  condition_name, body_name, [a, b, foo.x])
          if not isinstance(getattr(type(foo), x, None), property): foo.x = __attribute_variable_1
      ```
      6bf02a12
  16. 26 2月, 2021 1 次提交
  17. 22 2月, 2021 1 次提交
    • H
      [Dy2stat] Refactoring tensor_shape_transformer.py to Fix Change after Assign Bug (#31082) · cf43a321
      Huihuang Zheng 提交于
      **Problem**
      In our old shape transformer logic, if user write:
      ```
      s = tensor.shape
      ...
      y = paddle.some_api(s)
      ```
      Dy2stat will change it to
      ```
      ...
      y = paddle.some_api(convert_var_shape(tensor))
      ```
      However it will cause fatal bug if user changes the shape of `x` after assign. For example:
      ```
      s = tensor.shape
      ...
      tensor = paddle.some_change_shape_api(tensor)
      ...
      y = paddle.some_api(s)
      ```
      Then the Dy2stat will get wrong result because the code is translated into:
      ```
      tensor = paddle.some_change_shape_api(tensor)
      ...
      y = paddle.some_api(convert_var_shape(tensor)) # tensor shape has been changed, not origin `s` value
      ```
      
      **Solution Logic**
      
      It can not be solved in the old logic, so I refactoring tensor_shape_transformer logic. Now we will use `s` to store shape attribute and generate a var `s__STATIC_CONVERT_VAR_SHAPE_SUFFIX` to store static shape API `shape(tensor)`
      ```
      s = tensor.shape
      ...
      y = paddle.some_api(s)
      ```
      Dy2stat will change it to
      ```
      s = tensor.shape
      s__STATIC_CONVERT_VAR_SHAPE_SUFFIX = shape(tensor)
      ...
      y = paddle.some_api(choose_shape_attr_or_api(s, s__STATIC_CONVERT_VAR_SHAPE_SUFFIX ))
      ```
      In this case, the code is consistent with origin dygraph meaning and it fixed the change after assign bug.
      
      **Code Key Note**
      
      To help reviewers, the key change of this PR is changing `self.name_to_var_shape` from "mapping name to shape node" to "mapping name to its STATIC_CONVERT_VAR_SHAPE_SUFFIX name", then if a variable name has the SUFFIX, we can choose to use attribute shape or shape api. Other changes go with the key change.
      
      **Consideration**
      The issue of this PR is that we store extra static `shape` API result, will it harms the speed of Dy2stat? In some cases it will, but we argue that the benefit would be greater than the cost.
      
      1. The extra calling to static `shape` API will happen when coder assign among shape variables. Take the following dygraph code as an instance:
      ```
      s1 = tensor.shape
      s2 = s1
      s3 = s2
      ...
      ```
      Then we called extra static `shape` APIs again and again, however users seldom write code like this.
      
      2. If the shape variable is used a lot, for example:
      ```
      s = tensor.shape
      y1 = paddle.some_api1(s)
      y2 = paddle.some_api2(s)
      y3 = paddle.some_api3(s)
      ```
      Our old logic will create 3 shape APIs but now just 1. This is more common user code pattern. In fact, if reviewers take a look at the current unit test in this PR, you could see the op numbers decrease after this PR. So we argue that this PR can also improve speed in this code pattern.
      cf43a321
  18. 20 2月, 2021 1 次提交
  19. 08 1月, 2021 2 次提交
  20. 24 11月, 2020 1 次提交
  21. 29 9月, 2020 1 次提交
    • H
      [Dy2stat] Refine Dy2stat APIs to 2.0rc (#27430) · cc2fc938
      Huihuang Zheng 提交于
      Refine Dy2stat APIs to 2.0rc
      
      After discussion, we accepted 3 key points from reviewers:
      
      1. In 2.0rc we changed dygraph_to_static folder to dy2static
      2. Keep the three files: convert_call_func.py, convert_operators.py, variable_trans_func.py
      3. Remove convert_operators path when users import convert_xxx. 
      
      After this PR, users can import convert_xxx APIs by:
      
      `import paddle.jit.dy2static.convert_xxx`
      
      The file structure will be:
      
      ```
      jit
          dy2static
                convert_operators.py
                convert_func_call.py
                variable_trans_func.py
      ```
      
      Detail changed API in files:
      
      In python/paddle/jit/dygraph_to_static/convert_call_func.py:
      from ...fluid.dygraph.dygraph_to_static.convert_call_func import convert_call  #DEFINE_ALIAS
      
      In python/paddle/jit/dygraph_to_static/convert_operators.py:
      from ...fluid.dygraph.dygraph_to_static.convert_operators import cast_bool_if_necessary  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_assert  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_ifelse  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_len  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_logical_and  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_logical_not  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_logical_or  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_print  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_var_dtype  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_var_shape  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.convert_operators import convert_while_loop  #DEFINE_ALIAS
      
      In python/paddle/jit/dygraph_to_static/variable_trans_func.py:
      from ...fluid.dygraph.dygraph_to_static.variable_trans_func import create_fill_constant_node  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.variable_trans_func import create_static_variable_gast_node  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.variable_trans_func import data_layer_not_check  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.variable_trans_func import to_static_variable  #DEFINE_ALIAS
      from ...fluid.dygraph.dygraph_to_static.variable_trans_func import to_static_variable_gast_node  #DEFINE_ALIAS
      cc2fc938
  22. 11 6月, 2020 1 次提交
    • L
      [Dy2Static]Convert var.shape stmt and Convert the return variables of... · f16e2778
      liym27 提交于
      [Dy2Static]Convert var.shape stmt and Convert the return variables of Tensor-dependent 'if' staments to Tensor if it not  (#24911)
      
      * Support int and long: int or long -> six.integer_types. 
      
      * Modify test_tensor_shape: fix bug and modify comment. 
      
      * Support convert_var_shape to convert var.shape stmt
      
      * Modify code in ifelse_simple_func.py because don't support return non-Tensor in Tensor-dependent 'if' stament currently. 
      
      * Convert the return variables of Tensor-dependent 'if' staments to Tensor if it not. test=develop
      f16e2778
  23. 08 5月, 2020 1 次提交
  24. 25 3月, 2020 1 次提交
    • H
      Rename Decorator "dygraph_to_static_graph" to "dygraph_to_static_func" (#23150) · e9b18c74
      Huihuang Zheng 提交于
      This PR does exact the thing as the title. The reason is that we plan to develop 4 decorators
      
      "dygraph_to_static_code"
      "dygraph_to_static_program"
      "dygraph_to_static_func"
      "dygraph_to_static_output"
      
       The 4 decorators will emphasize different part when translating dygraph to static graph. Decorator name "dygraph_to_static_graph" is too big for the function it implements.
      e9b18c74
  25. 17 3月, 2020 1 次提交
  26. 06 3月, 2020 1 次提交