Skip to content

Commit

Permalink
Avoid unnecessary overhead in HloExtractor (NFC)
Browse files Browse the repository at this point in the history
Currently we iterate over all instructions in the old module to find the
instructions which have been cloned. But CloneContext offers direct access to
them, so we should be using that instead.

PiperOrigin-RevId: 696017622
  • Loading branch information
akuegel authored and Google-ML-Automation committed Nov 13, 2024
1 parent 69d6485 commit a610534
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions xla/tools/hlo_extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,11 @@ class ExtractionVisitor : public ConstDfsHloVisitorWithDefault {
// Rename HLOs so that their name matches the original. By default,
// HLOs get new unique names when adding a new entry computation to
// a module.
for (auto computation : old_module_->MakeComputationPostOrder()) {
for (auto old_instruction : computation->MakeInstructionPostOrder()) {
if (auto new_instruction =
clone_context_.FindInstruction(old_instruction)) {
new_instruction->SetAndSanitizeName(old_instruction->name());
}
}
for (const auto& instruction_mapping :
clone_context_.cloned_instructions()) {
auto old_instruction = instruction_mapping.first;
auto new_instruction = instruction_mapping.second;
new_instruction->SetAndSanitizeName(old_instruction->name());
}
// For the extra created instructions (e.g., the ones created when replacing
// with broadcasted zeros), we make sure they have unique names without
Expand Down

0 comments on commit a610534

Please sign in to comment.