diff --git a/src/h3_blackwell_runtime/qwen3vl_vision.py b/src/h3_blackwell_runtime/qwen3vl_vision.py index 90eebb5..05eae4c 100644 --- a/src/h3_blackwell_runtime/qwen3vl_vision.py +++ b/src/h3_blackwell_runtime/qwen3vl_vision.py @@ -340,7 +340,16 @@ def resize_keyframe(image: torch.Tensor, width: int, height: int, *, crop: str = elif old_aspect < new_aspect: y = round((old_h - old_h * (old_aspect / new_aspect)) / 2) samples = samples.narrow(-2, y, old_h - 2 * y).narrow(-1, x, old_w - 2 * x) - samples = F.interpolate(samples, size=(height, width), mode="lanczos") + # F.interpolate(4D, lanczos) is not supported by PyTorch; emulate via + # upsample-then-downsample with nearest + a small Lanczos-3 kernel. + # (Simpler: just use PIL's LANCZOS via numpy for the single image.) + import numpy as np + from PIL import Image as PILImage + arr = samples[0].permute(1, 2, 0).cpu().numpy() # [H, W, 3] + arr = (arr * 255.0).astype(np.uint8) + img = PILImage.fromarray(arr, mode="RGB") + img = img.resize((width, height), PILImage.LANCZOS) + samples = torch.from_numpy(np.asarray(img).astype(np.float32) / 255.0).permute(2, 0, 1).unsqueeze(0) return samples.clamp(0.0, 1.0).movedim(1, -1) # [1, H, W, 3]