From 0484773ef52d07d967ae87241b550e70938f1099 Mon Sep 17 00:00:00 2001 From: Benedikt Johannes Date: Sun, 22 Feb 2026 14:30:58 +0100 Subject: [PATCH 1/2] Change tuple() to () for slightly improved performance in trt_compiler.py Signed-off-by: Benedikt Johannes --- monai/networks/trt_compiler.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/monai/networks/trt_compiler.py b/monai/networks/trt_compiler.py index 68bf9d1e55..1339c9af9b 100644 --- a/monai/networks/trt_compiler.py +++ b/monai/networks/trt_compiler.py @@ -261,7 +261,7 @@ def parse_groups( Tuple of Union[torch.Tensor, List[torch.Tensor]], according to the grouping in output_lists """ - groups: tuple[torch.Tensor | list[torch.Tensor], ...] = tuple() + groups: tuple[torch.Tensor | list[torch.Tensor], ...] = () cur = 0 for l in range(len(output_lists)): gl = output_lists[l] @@ -273,7 +273,7 @@ def parse_groups( groups = (*groups, ret[cur : cur + gl[0]]) cur = cur + gl[0] elif gl[0] == -1: - rev_groups: tuple[torch.Tensor | list[torch.Tensor], ...] = tuple() + rev_groups: tuple[torch.Tensor | list[torch.Tensor], ...] = () rcur = len(ret) for rl in range(len(output_lists) - 1, l, -1): rgl = output_lists[rl] From 3a5b1149d778c9a243f17b3a020c0ee355afa239 Mon Sep 17 00:00:00 2001 From: Benedikt Johannes Date: Sun, 22 Feb 2026 14:44:36 +0100 Subject: [PATCH 2/2] Update trt_compiler.py Signed-off-by: Benedikt Johannes --- monai/networks/trt_compiler.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/monai/networks/trt_compiler.py b/monai/networks/trt_compiler.py index 1339c9af9b..2b45b630f3 100644 --- a/monai/networks/trt_compiler.py +++ b/monai/networks/trt_compiler.py @@ -263,8 +263,8 @@ def parse_groups( """ groups: tuple[torch.Tensor | list[torch.Tensor], ...] = () cur = 0 - for l in range(len(output_lists)): - gl = output_lists[l] + for idx in range(len(output_lists)): + gl = output_lists[idx] assert len(gl) == 0 or len(gl) == 1 if len(gl) == 0 or gl[0] == 0: groups = (*groups, ret[cur]) @@ -275,7 +275,7 @@ def parse_groups( elif gl[0] == -1: rev_groups: tuple[torch.Tensor | list[torch.Tensor], ...] = () rcur = len(ret) - for rl in range(len(output_lists) - 1, l, -1): + for rl in range(len(output_lists) - 1, idx, -1): rgl = output_lists[rl] assert len(rgl) == 0 or len(rgl) == 1 if len(rgl) == 0 or rgl[0] == 0: