-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SOT][dynamic shape] Support dynamic int input #64323
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/jit/sot/opcode_translator/executor/function_graph.py
Outdated
Show resolved
Hide resolved
@@ -566,6 +669,9 @@ def symbolic_call(self, infer_meta_fn, compute_fn, func, *args, **kwargs): | |||
""" | |||
self.collect_input_variables(list(args)) | |||
self.collect_input_variables(list(kwargs.values())) | |||
if ENV_SOT_ALLOW_DYNAMIC_SHAPE.get(): | |||
self.analyze_dynamic_inputs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
symbolic_call
每次组网都会调用一次吧,这是不是分析次数太多了?按我理解在 input_variables
稳定后调用一次就可以了?
str, DynamicShape | SymbolicInt | int | ||
] = self.dynamic_inputs | ||
for variable in find_traceable_vars(self.input_variables): | ||
if isinstance(variable.tracker, LocalTracker): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
从代码风格上来看,推荐使用类似 early return 的形式来减少单分支 if 的缩进
def fn():
- if x:
- foo()
+ if not x:
+ return
+ foo()
for i in range(n):
- if x:
- foo()
+ if not x:
+ continue
+ foo()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py
Outdated
Show resolved
Hide resolved
return f"{self.graph.OUT_VAR_PREFIX}{self.var_name}" | ||
|
||
def _reconstruct(self, codegen: PyCodeGen): | ||
codegen.gen_load_const(paddle.to_tensor(self.value)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里好像不太行?这样的话这个 value 是固定的吧,应该生成代码将其 load 到栈上,然后生成代码将其转化为 tensor,这些都是通过字节码实现的~
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py
Outdated
Show resolved
Hide resolved
if ENV_SOT_ALLOW_DYNAMIC_SHAPE.get() and isinstance(value, int): | ||
self._locals[name] = SymbolicIntVariable( | ||
value, self._graph, tracker | ||
) | ||
else: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
诶?所有 locals 里的 int 都是 SymbolicIntVariable
?之后通过 var.symbolic
来确定是否真的 symbolic?感觉有点奇怪
另外,是否 symbolic 是在什么时候变化的呢?按我理解,在同一次模拟过程中不应该有非 symbolic 向 symbolic 的转化,一个 var 是否是 symbolic 应该是模拟最开始就决定了的
96ab682
to
382aedf
Compare
python/paddle/jit/sot/opcode_translator/executor/function_graph.py
Outdated
Show resolved
Hide resolved
python/paddle/jit/sot/opcode_translator/executor/variable_dispatch.py
Outdated
Show resolved
Hide resolved
if self.value in symbolic_input: | ||
symbolic_input[self.value] += 1 | ||
else: | ||
symbolic_input[self.value] = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里也可以 setdefault(0)
一下
if value in symbolic_input: | ||
symbolic_input[value] += 1 | ||
else: | ||
symbolic_input[value] = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上,可以利用 setdefault
python/paddle/jit/sot/opcode_translator/executor/variables/iter.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以再测下 symbolic int 在传入 paddle API 时候能否正常触发组网(如 paddle.reshape(x, [n, 1])
、paddle.add(x, n)
),感觉应该也是可以的~(但如果有比较麻烦的问题建议下一个 PR)
python/paddle/jit/sot/opcode_translator/executor/variable_dispatch.py
Outdated
Show resolved
Hide resolved
python/paddle/jit/sot/opcode_translator/executor/variable_dispatch.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Category
Others
PR Types
Others
Description
Support dynamic int input
TODO:
-n
这种 unary 操作会被转为Tensor