From 8fe5a9d8455142b7fc1dc4c427d9ad0ab7d9386e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B0=A2=E7=BF=8A=E5=87=A1?= Date: Sat, 22 Aug 2026 11:17:01 +0800 Subject: [PATCH] Replace deprecated torch.range with torch.arange (#153) torch.range emits an unconditional UserWarning on every call (any torch version) and is scheduled for removal. All three call sites pass an explicit dtype=torch.int64, so the closed-to-half-open switch (range(0, N-1) -> arange(0, N)) is lossless: same elements, same dtype. - gnnguard.py: GCN4GNNGuard.add_loop_sparse (active in fit) and GCN4GNNGuard_attack.add_loop_sparse (dead code) - nas/space/grna.py: GNNGuard.add_loop_sparse (dead code) Verified on torch 2.11.0: arange path warning-free under warnings-as-errors, results element-wise identical to the old path. Co-Authored-By: Claude --- autogl/module/model/pyg/robust/gnnguard.py | 4 ++-- autogl/module/nas/space/grna.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/autogl/module/model/pyg/robust/gnnguard.py b/autogl/module/model/pyg/robust/gnnguard.py index 3ccc969..8e83525 100644 --- a/autogl/module/model/pyg/robust/gnnguard.py +++ b/autogl/module/model/pyg/robust/gnnguard.py @@ -164,7 +164,7 @@ def att_coef(self, fea, edge_index, is_lil=False, i=0): def add_loop_sparse(self, adj, fill_value=1): # make identify sparse tensor - row = torch.range(0, int(adj.shape[0]-1), dtype=torch.int64) + row = torch.arange(0, adj.shape[0], dtype=torch.int64) i = torch.stack((row, row), dim=0) v = torch.ones(adj.shape[0], dtype=torch.float32) shape = adj.shape @@ -388,7 +388,7 @@ def forward(self, x, adj_lil): def add_loop_sparse(self, adj, fill_value=1): # make identify sparse tensor - row = torch.range(0, int(adj.shape[0]-1), dtype=torch.int64) + row = torch.arange(0, adj.shape[0], dtype=torch.int64) i = torch.stack((row, row), dim=0) v = torch.ones(adj.shape[0], dtype=torch.float32) shape = adj.shape diff --git a/autogl/module/nas/space/grna.py b/autogl/module/nas/space/grna.py index 919c666..ea5c116 100644 --- a/autogl/module/nas/space/grna.py +++ b/autogl/module/nas/space/grna.py @@ -390,7 +390,7 @@ def att_coef(self, fea, edge_index, is_lil=False, i=0): def add_loop_sparse(self, adj, fill_value=1): # make identify sparse tensor - row = torch.range(0, int(adj.shape[0]-1), dtype=torch.int64) + row = torch.arange(0, adj.shape[0], dtype=torch.int64) i = torch.stack((row, row), dim=0) v = torch.ones(adj.shape[0], dtype=torch.float32) shape = adj.shape