diff --git a/src/h3_blackwell_runtime/vae_encoder.py b/src/h3_blackwell_runtime/vae_encoder.py index e6dcd5d..29d0d64 100644 --- a/src/h3_blackwell_runtime/vae_encoder.py +++ b/src/h3_blackwell_runtime/vae_encoder.py @@ -56,11 +56,15 @@ def _causal_conv3d(x, weight, bias, *, kernel_size, stride, spatial_padding): # x = F.pad(x, (0, 0, 0, 0, (k-1), 0), mode="constant") -- temporal # return super().forward(x) if x.shape[2] == 1: - # Keyframe path (matches reference's `autopad="causal_zero"`): truncate - # the temporal taps to the center 1 and run as an effective 2D conv. + # Keyframe path (matches reference's `autopad="causal_zero"`): apply + # spatial-reflect pad, then truncate the temporal taps to the center 1 + # so the conv acts as a 2D op on the single frame. + if spatial_padding > 0: + # F.pad for 5D input (B,C,T,H,W) uses (W_l, W_r, H_l, H_r, T_l, T_r). + x = F.pad(x, (spatial_padding, spatial_padding, spatial_padding, spatial_padding, 0, 0), mode="reflect") half = (kernel_size - 1) // 2 kernel_5d = weight[:, :, half:half + 1, :, :] - return F.conv3d(x, kernel_5d, bias, (1, stride[1], stride[2]), (spatial_padding, spatial_padding, spatial_padding)) + return F.conv3d(x, kernel_5d, bias, (1, stride[1], stride[2]), (0, 0, 0)) if spatial_padding > 0: return _reflect_and_causal(x, weight, bias, kernel_size, stride, spatial_padding) return F.conv3d(x, weight, bias, stride, (0, 0, 0))