Skip to content

Commit

Permalink
inductor: sort the reads buf by name (pytorch#89744)
Browse files Browse the repository at this point in the history
Sort `read_writes.reads` by name to make sure the same graph is generated for a fixed model. Otherwise, the buffer reuse may be different since the order of `read_writes.reads` is random.

Pull Request resolved: pytorch#89744
Approved by: https://github.com/jgong5, https://github.com/jansel
  • Loading branch information
chunyuan-w authored and pytorchmergebot committed Dec 15, 2022
1 parent 9fe050f commit 103029e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion torch/_inductor/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ def allocate(self):
from .codegen.triton_template import should_use_template
from .codegen.wrapper import buffer_reuse_key

for read in self.read_writes.reads:
ordered_reads = sorted(self.read_writes.reads, key=lambda x: x.name)

for read in ordered_reads:
input_node: BaseSchedulerNode = self.scheduler.name_to_node.get(
read.name
)
Expand Down

0 comments on commit 103029e

Please sign in to comment.