Replace deprecated torch.range in hy3dgen/texgen/hunyuanpaint/pipeline.py with torch.arange
Summary
hy3dgen/texgen/hunyuanpaint/pipeline.py:598 calls torch.range, which is deprecated and emits a UserWarning on every call ("torch.range is deprecated and will be removed in a future release because its behavior is inconsistent with Python's range builtin. Instead, use torch.arange, which produces values in [start, end)." — verified on torch 2.11.0). It is the only torch.range usage in this repo:
if self.is_turbo:
bsz = 3
N_gen = 15
index = torch.range(29, 0, -bsz, device='cuda').long() # ← emits UserWarning on every call
timesteps = self.solver.ddim_timesteps[index]This runs in the turbo path of the paint pipeline on every generation.
Proposed fix
torch.range is end-inclusive: torch.range(29, 0, -3) produces [29, 26, 23, 20, 17, 14, 11, 8, 5, 2] (10 values; 0 is not reachable with step -3). The torch.arange equivalent (open interval, step excluded end) is:
index = torch.arange(29, -1, -bsz, device='cuda').long()(-1 = last included value 2 + step -3; torch.arange with integer inputs returns int64, so the explicit .long() is a no-op — kept to match the surrounding style.)
Validation (torch 2.11.0+cpu)
torch.equal(torch.range(29, 0, -3), torch.arange(29, -1, -3))→True(identical values, end-inclusive semantics preserved).- With
warnings.simplefilter("error", UserWarning): the current line raises the deprecationUserWarning;torch.arangeconstructs cleanly.
Impact
- No deprecation
UserWarningduring turbo inference on any supported torch version; identical timestep indices.
References
- Issue #270: "Hunyuan3D-2 Warnings and Issue Resolution Methods" — user already reported this exact
torch.rangewarning (2025-06-09) and patched it locally; no maintainer response, code still unfixed. - PyTorch docs: torch.arange — recommended replacement.
- PyTorch docs: torch.range (deprecated) — official deprecation note ("Instead, use torch.arange(), which produces values in [start, end).").
Source: Tencent-Hunyuan/Hunyuan3D-2