From f0855313519bb8859831097b363c5d0c401140b5 Mon Sep 17 00:00:00 2001 From: vkovinicTT Date: Mon, 6 Oct 2025 20:12:05 +0000 Subject: [PATCH 1/3] enabled renaming op name without adding stack frame locations --- torch_xla/csrc/lowering_context.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/torch_xla/csrc/lowering_context.cpp b/torch_xla/csrc/lowering_context.cpp index 4e9c2fd013b..a7e8c6e5c8e 100644 --- a/torch_xla/csrc/lowering_context.cpp +++ b/torch_xla/csrc/lowering_context.cpp @@ -84,9 +84,12 @@ class HloMetadataSetter { } metadata.set_op_name(absl::StrCat(op_name_prefix, op_type)); - // Sets file, line and stack_frame_id in metadata - lowering_context.stack_frame_index_builder()->AddStackFrameLocations( - nmeta.frame_info, static_cast(max_stack_depth), metadata); + // NOTE: if max_stack_depth is 0, we are just renaming the op, so we don't need to add stack frame locations + if (max_stack_depth > 0) { + // Sets file, line and stack_frame_id in metadata + lowering_context.stack_frame_index_builder()->AddStackFrameLocations( + nmeta.frame_info, static_cast(max_stack_depth), metadata); + } lowering_context.builder()->SetOpMetadata(std::move(metadata)); } From b901b9a3523a1718db528d8870002f14653b0a29 Mon Sep 17 00:00:00 2001 From: vkovinicTT Date: Thu, 9 Oct 2025 08:22:55 +0000 Subject: [PATCH 2/3] prevent scope from overwriting custom metadata --- torch_xla/csrc/lowering_context.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch_xla/csrc/lowering_context.cpp b/torch_xla/csrc/lowering_context.cpp index a7e8c6e5c8e..63a59a6833f 100644 --- a/torch_xla/csrc/lowering_context.cpp +++ b/torch_xla/csrc/lowering_context.cpp @@ -78,7 +78,7 @@ class HloMetadataSetter { max_stack_depth = custom_opname_meta->max_stack_depth; } - if (!nmeta.scope.empty()) { + else if (!nmeta.scope.empty()) { op_name_prefix = absl::StrCat(absl::StrReplaceAll(nmeta.scope, {{":", "_"}}), "/"); } From d61d277e42462e0e98ee89da306b3fe10bfb5a21 Mon Sep 17 00:00:00 2001 From: vkovinicTT Date: Mon, 13 Oct 2025 07:41:29 +0000 Subject: [PATCH 3/3] linting --- torch_xla/csrc/lowering_context.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/torch_xla/csrc/lowering_context.cpp b/torch_xla/csrc/lowering_context.cpp index 63a59a6833f..f73cc6c6ca8 100644 --- a/torch_xla/csrc/lowering_context.cpp +++ b/torch_xla/csrc/lowering_context.cpp @@ -84,11 +84,12 @@ class HloMetadataSetter { } metadata.set_op_name(absl::StrCat(op_name_prefix, op_type)); - // NOTE: if max_stack_depth is 0, we are just renaming the op, so we don't need to add stack frame locations + // NOTE: if max_stack_depth is 0, we are just renaming the op, so we don't + // need to add stack frame locations if (max_stack_depth > 0) { // Sets file, line and stack_frame_id in metadata lowering_context.stack_frame_index_builder()->AddStackFrameLocations( - nmeta.frame_info, static_cast(max_stack_depth), metadata); + nmeta.frame_info, static_cast(max_stack_depth), metadata); } lowering_context.builder()->SetOpMetadata(std::move(metadata));