PaddlePaddle / PaddleSOT

A Bytecode level Implementation of Symbolic OpCode Translator For PaddlePaddle
Apache License 2.0
15 stars 25 forks source link

cannot work with `FLAGS_enable_pir_api=1` #417

Open gglin001 opened 1 year ago

gglin001 commented 1 year ago

开启 FLAGS_enable_pir_api=1examples/trace_basic.py 报错

# export FLAGS_enable_pir_api=1

# python examples/trace_basic.py
[Cost Model] New step start, current state is StepState.RUN_SOT
[eval_frame_callback] start to translate: <code object foo at 0x7f7bdb4310b0, file "/alleng/repos/PaddleSOT/examples/trace_basic.py", line 7>
[transform] OriginCode: foo
  8           0 LOAD_FAST                0 (x)
              2 LOAD_FAST                1 (y)
              4 BINARY_ADD
              6 STORE_FAST               2 (z)

  9           8 LOAD_FAST                2 (z)
             10 LOAD_CONST               1 (1)
             12 BINARY_ADD
             14 RETURN_VALUE
[Cache]: Firstly call <code object foo at 0x7f7bdb4310b0, file "/alleng/repos/PaddleSOT/examples/trace_basic.py", line 7>
[Executor] code options: co_cellvars=()
start execute opcode: <code object foo at 0x7f7bdb4310b0, file "/alleng/repos/PaddleSOT/examples/trace_basic.py", line 7>
[Translate Executor]: (line   8) LOAD_FAST    x, stack is []
[Translate Executor]: (line   8) LOAD_FAST    y, stack is [TensorVariable([2, 3], float32, True, var_0, x, object_0)]
[Translate Executor]: (line   8) BINARY_ADD   None, stack is [TensorVariable([2, 3], float32, True, var_0, x, object_0), TensorVariable([2, 3], float32, True, var_1, y, object_1)]
Traceback (most recent call last):
  File "/alleng/repos/PaddleSOT/sot/utils/exceptions.py", line 40, in impl
    return func(*args, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/function_graph.py", line 454, in symbolic_call
    out_metas = infer_meta_fn(func, *metas, **kwmetas)
  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 245, in __call__
    value = self.value_fn(*args, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 243, in value_fn
    return infer_meta(func, *args, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 164, in infer_meta
    return VariableCreator().infer_meta(func, *args, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 113, in infer_meta
    args, kwargs = convert_meta_to_variable(
  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 131, in convert_meta_to_variable
    return map_if_extend(
  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 215, in map_if_extend
    return map_if(
  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 187, in map_if
    return map_structure(replace, *structures)
  File "/alleng/repos/Paddle/python/paddle/utils/layers_utils.py", line 263, in map_structure
    return pack_sequence_as(structure[0], [func(*x) for x in entries])
  File "/alleng/repos/Paddle/python/paddle/utils/layers_utils.py", line 263, in <listcomp>
    return pack_sequence_as(structure[0], [func(*x) for x in entries])
  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 184, in replace
    return true_fn(*args)
  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 213, in wrapped_true_fn
    return true_fn(x)
  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 134, in <lambda>
    true_fn=lambda x: VariableCreator().get_variable(x),
  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 106, in get_variable
    self.var_cache[var_feature_name] = self.create_var(meta)
  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 93, in create_var
    var = self.main_program.global_block().create_var(
AttributeError: 'paddle.base.libpaddle.pir.Block' object has no attribute 'create_var'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/executor_cache.py", line 180, in start_translate
    new_custom_code, guard_fn = simulator.transform()
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/opcode_executor.py", line 1688, in transform
    self.run()
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/opcode_executor.py", line 497, in run
    is_stop = self.step(cur_instr)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/opcode_executor.py", line 537, in step
    return getattr(self, instr.opname)(instr)  # run single step.
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/opcode_executor.py", line 245, in wrapper
    return call_fn(self, instr)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/opcode_executor.py", line 115, in inner
    res = BuiltinVariable(fn, graph=self._graph, tracker=DanglingTracker())(
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/variables/callable.py", line 68, in __call__
    return self.call_function(*args, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/variables/callable.py", line 594, in call_function
    return handler(*args, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/variable_dispatch.py", line 876, in <lambda>
    lambda magic_name, var, other: var.graph.call_tensor_method(
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/function_graph.py", line 370, in call_tensor_method
    return inner_error_default_handler(self.symbolic_call, message_handler)(
  File "/alleng/repos/PaddleSOT/sot/utils/exceptions.py", line 46, in impl
    raise InnerError(
sot.utils.exceptions.InnerError: Call tensor_method error: Tensor.__add__, may be not a valid operator api ?.
Origin Exception is: 
 Traceback (most recent call last):

  File "/alleng/repos/PaddleSOT/sot/utils/exceptions.py", line 40, in impl
    return func(*args, **kwargs)

  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/function_graph.py", line 454, in symbolic_call
    out_metas = infer_meta_fn(func, *metas, **kwmetas)

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 245, in __call__
    value = self.value_fn(*args, **kwargs)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 243, in value_fn
    return infer_meta(func, *args, **kwargs)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 164, in infer_meta
    return VariableCreator().infer_meta(func, *args, **kwargs)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 113, in infer_meta
    args, kwargs = convert_meta_to_variable(

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 131, in convert_meta_to_variable
    return map_if_extend(

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 215, in map_if_extend
    return map_if(

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 187, in map_if
    return map_structure(replace, *structures)

  File "/alleng/repos/Paddle/python/paddle/utils/layers_utils.py", line 263, in map_structure
    return pack_sequence_as(structure[0], [func(*x) for x in entries])

  File "/alleng/repos/Paddle/python/paddle/utils/layers_utils.py", line 263, in <listcomp>
    return pack_sequence_as(structure[0], [func(*x) for x in entries])

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 184, in replace
    return true_fn(*args)

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 213, in wrapped_true_fn
    return true_fn(x)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 134, in <lambda>
    true_fn=lambda x: VariableCreator().get_variable(x),

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 106, in get_variable
    self.var_cache[var_feature_name] = self.create_var(meta)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 93, in create_var
    var = self.main_program.global_block().create_var(

AttributeError: 'paddle.base.libpaddle.pir.Block' object has no attribute 'create_var'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/alleng/repos/PaddleSOT/examples/trace_basic.py", line 26, in <module>
    main()
  File "/alleng/repos/PaddleSOT/examples/trace_basic.py", line 16, in main
    symbolic_translate_out = symbolic_translate(foo)(x, y)
  File "/alleng/repos/PaddleSOT/sot/translate.py", line 107, in impl
    return impl_sot(*args, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/translate.py", line 91, in impl_sot
    raise e
  File "/alleng/repos/PaddleSOT/sot/translate.py", line 89, in impl_sot
    outs = fn(*args, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/translate.py", line 79, in callback
    return eval_frame_callback(frame, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/transform.py", line 69, in eval_frame_callback
    custom_code = OpcodeExecutorCache()(frame, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/executor_cache.py", line 61, in __call__
    new_custom_code, guard_fn = self.translate(frame, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/executor_cache.py", line 132, in translate
    custom_new_code, guard_fn = start_translate(frame, **kwargs)
  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/executor_cache.py", line 214, in start_translate
    raise InnerError(OpcodeExecutorBase.error_message_summary(e)) from e
sot.utils.exceptions.InnerError: In simulate execution:

    File "/alleng/repos/PaddleSOT/examples/trace_basic.py", line 8, in foo
        z = x + y
    sot.utils.exceptions.InnerError: Call tensor_method error: Tensor.__add__, may be not a valid operator api ?.
Origin Exception is: 
 Traceback (most recent call last):

  File "/alleng/repos/PaddleSOT/sot/utils/exceptions.py", line 40, in impl
    return func(*args, **kwargs)

  File "/alleng/repos/PaddleSOT/sot/opcode_translator/executor/function_graph.py", line 454, in symbolic_call
    out_metas = infer_meta_fn(func, *metas, **kwmetas)

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 245, in __call__
    value = self.value_fn(*args, **kwargs)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 243, in value_fn
    return infer_meta(func, *args, **kwargs)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 164, in infer_meta
    return VariableCreator().infer_meta(func, *args, **kwargs)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 113, in infer_meta
    args, kwargs = convert_meta_to_variable(

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 131, in convert_meta_to_variable
    return map_if_extend(

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 215, in map_if_extend
    return map_if(

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 187, in map_if
    return map_structure(replace, *structures)

  File "/alleng/repos/Paddle/python/paddle/utils/layers_utils.py", line 263, in map_structure
    return pack_sequence_as(structure[0], [func(*x) for x in entries])

  File "/alleng/repos/Paddle/python/paddle/utils/layers_utils.py", line 263, in <listcomp>
    return pack_sequence_as(structure[0], [func(*x) for x in entries])

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 184, in replace
    return true_fn(*args)

  File "/alleng/repos/PaddleSOT/sot/utils/utils.py", line 213, in wrapped_true_fn
    return true_fn(x)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 134, in <lambda>
    true_fn=lambda x: VariableCreator().get_variable(x),

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 106, in get_variable
    self.var_cache[var_feature_name] = self.create_var(meta)

  File "/alleng/repos/PaddleSOT/sot/infer_meta.py", line 93, in create_var
    var = self.main_program.global_block().create_var(

AttributeError: 'paddle.base.libpaddle.pir.Block' object has no attribute 'create_var'
2742195759 commented 1 year ago

pir最终态动转静目前这个功能,还在迭代中,没有完全支持。如果只是想要跑 pir 执行器,建议使用 FLAGS_enable_new_ir_in_executor 。