Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.
This repository was archived by the owner on Jan 24, 2024. It is now read-only.

调整 paddle.jit.not_to_static 装饰范围 #120

@SigureMo

Description

@SigureMo

我们目前会将整个 SIR 函数用 paddle.jit.to_static 包装

def value_fn(self, context, sir_name):
return FallbackWrapper(
paddle.jit.to_static(
compile_sir(context, sir_name), enable_fallback=False
)
)

将其转换为动转静的 StaticFunction,转换的函数中主体逻辑就是利用 Interpreter 解释 SIR,进行组网,由于这部分可能有些动转静会出问题的语法,因此使用了 paddle.jit.not_to_static 进行装饰

def compile_sir(context, name):
@paddle.jit.not_to_static
def wrapper(args):
"""
This function will be decorated by paddle.to_static.
so the args is variables, not eager tensors.
"""
interpreter = Interpreter(context)
SIR = interpreter.get_sir(name)
state = prepare_state(SIR, args)
return interpreter.run_sir(name, state)
return wrapper

然而实际情况我们有些 API 仍然需要 to_static 的代码转换,比如 paddle.to_tensor,因此我们希望不利用 paddle.jit.not_to_static 将整个函数装饰,而是只装饰部分,避免部分代码动转静转写出问题,并将组网代码进行转换

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions