Skip to content

Conversation

@neerajk
Copy link

@neerajk neerajk commented Oct 6, 2025

RuntimeError: The size of tensor a (1024) must match the size of tensor b (1020) at non-singleton dimension 2

Root Cause
The error was caused by incorrect dimensionality in the positional metadata encoding. Specifically:

The time and latlon tensors were incorrectly shaped as [B, 2] instead of [B, 4], resulting in a combined metadata tensor of shape [B, L, 8] instead of the expected [B, L, 12].

This led to a mismatch when adding positional encodings to the patch embeddings, which are shaped [B, L, 1024].

Fixes Applied
Corrected the normalize_timestamp() and normalize_latlon() functions to return 4 components each: sin/cos(week/hour) and sin/cos(lat/lon) respectively.

Ensured the metadata tensors are properly stacked and repeated to match the patch sequence length (L).

Verified that the final positional encoding tensor matches the expected shape [B, L, 1024] before addition.

Validation
Encoder now runs successfully with wall-to-wall Sentinel-2 inputs.

@neerajk neerajk force-pushed the main branch 2 times, most recently from 6cd081d to 201dde7 Compare November 16, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants