Add explicit input validation and clearer error messages for model inputs
Description of the bug
Several model forward() methods in graph_weather assume that input tensors are provided in the shape [batch_size, num_nodes, num_features], but this assumption is not explicitly validated.
When inputs with incorrect shapes are passed, the code either raises cryptic PyTorch runtime errors or fails later during execution, making it difficult for users to identify the root cause of the problem.
This results in misleading error behavior rather than failing fast at the API boundary.
To Reproduce
- Steps to reproduce the behavior:
- Instantiate a model from graph_weather.models
- Pass an input tensor with an invalid shape (e.g. missing batch dimension)
import torch
x = torch.randn(100, 64) # invalid shape
model(x)
Observe that the resulting error is unclear or occurs deep inside the computation graph rather than at input validation.
Expected behavior
The model should explicitly validate input tensor shape and fail fast with a clear and informative error message, such as: ValueError: Expected input shape [batch, nodes, features], got torch.Size([100, 64])
Additional context
Adding lightweight input validation and corresponding unit tests would improve developer experience without changing model behavior or performance. This is particularly helpful for new contributors and users experimenting with the library.
Several forward() methods assume inputs are shaped [batch, nodes, features], but this isn’t validated.
Passing tensors with incorrect shapes (e.g. missing batch dimension) currently results in cryptic PyTorch errors later in execution.
I propose adding a lightweight input shape check (e.g. x.ndim == 3) to fail fast with a clear error like:
ValueError: Expected input shape [batch, nodes, features], got torch.Size([...])
Happy to open a small PR with this change and a unit test if this sounds reasonable.
Hi! I'd like to take this on. Input validation at the API boundary is important for developer experience - cryptic PyTorch errors are hard to debug. My approach:
- Add _validate_input() helper method to model classes
- Check tensor shape matches expected [batch, nodes, features]
- Raise clear ValueError with expected vs actual shape
- Add unit tests for invalid input scenarios
- Minimal performance overhead (validation only on forward()) I've been contributing to OCF projects and am comfortable with PyTorch model patterns. Can I be assigned this issue?