From 7050fcbfe574737e07e2832b9f67cbcc49c741c7 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 19 Nov 2025 08:50:10 +0000 Subject: [PATCH] fix: update torch.amp.autocast to use modern API Replace deprecated device_type parameter usage with positional argument in amp.autocast calls to fix FutureWarning: - compressai/models/video/google.py:362 - compressai/utils/video/eval_model/__main__.py:373 Changed from: amp.autocast(device_type=device.type, enabled=...) To: amp.autocast(device.type, enabled=...) This uses the modern torch.amp.autocast API and improves compatibility with various device types including potential future CANN/NPU support. --- compressai/models/video/google.py | 2 +- compressai/utils/video/eval_model/__main__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compressai/models/video/google.py b/compressai/models/video/google.py index b978af8d..1dee5044 100644 --- a/compressai/models/video/google.py +++ b/compressai/models/video/google.py @@ -359,7 +359,7 @@ def warp_volume(self, volume, flow, scale_field, padding_mode: str = "border"): N, C, _, H, W = volume.size() - with amp.autocast(device_type=volume.device.type, enabled=False): + with amp.autocast(volume.device.type, enabled=False): grid = meshgrid2d(N, C, H, W, volume.device) update_grid = grid + flow.permute(0, 2, 3, 1).float() update_scale = scale_field.permute(0, 2, 3, 1).float() diff --git a/compressai/utils/video/eval_model/__main__.py b/compressai/utils/video/eval_model/__main__.py index 768ae197..295eda5a 100644 --- a/compressai/utils/video/eval_model/__main__.py +++ b/compressai/utils/video/eval_model/__main__.py @@ -371,7 +371,7 @@ def run_inference( continue with amp.autocast( - device_type=next(net.parameters()).device.type, enabled=args["half"] + next(net.parameters()).device.type, enabled=args["half"] ): with torch.no_grad(): if entropy_estimation: