Skip to content

Replace deprecated torch.range in hy3dgen/texgen/hunyuanpaint/pipeline.py with torch.arange #374

Description

@xyf5432

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 deprecation UserWarning; torch.arange constructs cleanly.

Impact

  • No deprecation UserWarning during turbo inference on any supported torch version; identical timestep indices.

References

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions