feat: Implemented CaFA model architecture #105 #174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request
Description
This PR introduces a modular and well-tested implementation of the CaFA (Climate-Aware Factorized Attention) model architecture, as requested in issue #105. In addition to adding support for h3-py 4.x and a Feature manager
The core innovation of the paper, the
FactorizedTransformerBlock
, has been implemented as a standalone component. The model also internally handles input tensors with odd spatial dimensions via padding and cropping, making it robust and user-friendly.This contribution adds the following key components:
FactorizedTransformerBlock
: A standalone, reusable Transformer block implementing Axial Attention, located in graph_weather/models/cafa/factorize.py.Encoder
: A convolutional encoder for channel projection and spatial downsampling.Processor
: A processor that stacks multiple FactorizedTransformerBlock modules.Decoder
: A transposed convolutional decoder for spatial upsampling and output projection.CaFAForecaster
: The final, assembled end-to-end model that combines the above components.No new external dependencies are required for this change.
Fixes #105
How Has This Been Tested?
A comprehensive suite of unit tests has been added in
tests/models/cafa/test_cafa.py
. These tests can be run viapytest
and validate:Encoder
,Processor
,Decoder
).CaFAForecaster
model works end-to-end.That the model correctly handles inputs with odd spatial dimensions.
Additionally, the model was interactively tested in a Jupyter notebook against both randomly generated tensors and a real, single-level ERA5 dataset (
2m_temperature
) to ensure correctness and GPU compatibility.If your changes affect data processing, have you plotted any changes? i.e. have you done a quick sanity check?
Checklist: