Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,21 @@ def BINARY_OP(self, instr: Instruction):
def BINARY_SUBSCR(self, instr: Instruction):
key = self.stack.pop()
container = self.stack.pop()
self.binary_subscr_operation(key, container, instr.opname)

@call_break_graph_decorator(push_n=1)
def BINARY_SLICE(self, instr: Instruction):
end = self.stack.pop()
start = self.stack.pop()
container = self.stack.pop()
key = SliceVariable(
slice(start, end),
graph=self._graph,
tracker=DummyTracker([start, end]),
)
self.binary_subscr_operation(key, container, instr.opname)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BINARY_SLICE 看起来是 BUILD_SLICEBINARY_SUBSCR 的结合,那么是否需要考虑 BUILD_SLICE 里的 step 的情况呢?还是说有 step 的情况不会编译成 BINARY_SLICE 呢?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def foo(x):
    return x[1:3]
    return x[1:3:2]

我测了一下有step的话(比如 x[1:3:2]),不会编译成BINARY_SLICE

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的那我觉得没问题


def binary_subscr_operation(self, key, container, opname):
assert isinstance(key, VariableBase)
# TODO(xiongkun): getitem / getattr support key and attr as variable.
if isinstance(key, TensorVariable) and isinstance(
Expand All @@ -690,7 +705,7 @@ def BINARY_SUBSCR(self, instr: Instruction):

if isinstance(key, TensorVariable):
raise BreakGraphError(
f"Key is a TensorVariable in BINARY_SUBSCR, {container}[{key}]"
f"Key is a TensorVariable in {opname}, {container}[{key}]"
)

result = BuiltinVariable(
Expand Down Expand Up @@ -864,11 +879,28 @@ def STORE_SUBSCR(self, instr: Instruction):
key = self.stack.pop()
container = self.stack.pop()
value = self.stack.pop()
self.store_subscr_operation(key, container, value, instr.opname)

@call_break_graph_decorator(push_n=0)
def STORE_SLICE(self, instr: Instruction):
end = self.stack.pop()
start = self.stack.pop()
container = self.stack.pop()
value = self.stack.pop()

key = SliceVariable(
slice(start, end),
graph=self._graph,
tracker=DummyTracker([start, end]),
)
self.store_subscr_operation(key, container, value, instr.opname)

def store_subscr_operation(self, key, container, value, opname):
assert isinstance(key, VariableBase)
self._graph.add_global_guarded_variable(key)
if isinstance(key, TensorVariable):
raise BreakGraphError(
f"Key is a TensorVariable in STORE_SUBSCR, {container}[{key}] = {value}"
f"Key is a TensorVariable in {opname}, {container}[{key}] = {value}"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI覆盖率好像跑不到这里子图打断的情况(这里改了下打断报错输出的op名)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

仅 3.12 适配相关的可以豁免,非 3.12 的需要考虑覆盖率

)
# TODO(xiongkun): support tensor[tensor] = tensor, dy2static is not the same with dygraph.
container[key.get_py_value()] = value
Expand Down
1 change: 0 additions & 1 deletion test/sot/skip_files_py312
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
./test_11_jumps.py
./test_12_for_loop.py
./test_14_operators.py
./test_15_slice.py
./test_21_global.py
./test_analysis_inputs.py
./test_break_graph.py
Expand Down