graph_weather icon indicating copy to clipboard operation
graph_weather copied to clipboard

About Runing the Example Code with different lat and lon resolution.

Open SauryChen opened this issue 1 year ago • 4 comments

Describe the bug

Hi, I have installed the package and run the first example in README (by changing the features.shape[-1] from 78 to 102), and this can work without any bugs. However, when I changed the lat and lon to another resolution, say 5.625deg, the error occurs:

Traceback (most recent call last):
  File "keisler22.py", line 18, in <module>
    out = model(features)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/graph_weather/models/forecast.py", line 109, in forward
    x, edge_idx, edge_attr = self.encoder(features)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/graph_weather/models/layers/encoder.py", line 183, in forward
    out, _ = self.graph_processor(out, edge_index, edge_attr)  # Message Passing
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/graph_weather/models/layers/graph_net_block.py", line 287, in forward
    x, edge_attr, _ = block(x, edge_index, edge_attr)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/torch_geometric/nn/models/meta.py", line 146, in forward
    x = self.node_model(x, edge_index, edge_attr, u, batch)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl
    return forward_call(*input, **kwargs)
  File "/ceph-data/cmx/anaconda3/envs/PyG/lib/python3.8/site-packages/graph_weather/models/layers/graph_net_block.py", line 185, in forward
    out = cat([x, out], dim=-1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 15860 but got size 15858 for tensor number 1 in the list.
srun: error: 10-10-10-16: task 0: Exited with exit code 1

To Reproduce

Steps to reproduce the behavior: Please run the following code:

lat_lons = []
for lat in np.arange(-87.1875, 90, 5.625):
# for lat in range(-90, 90, 1):
    # for lon in range(0, 360, 1):
    for lon in np.arange(0, 360, 5.625):
        lat_lons.append((lat, lon))
print(len(lat_lons))
model = GraphWeatherForecaster(lat_lons=lat_lons, feature_dim=78, aux_dim=24, output_dim=78)

features = torch.randn((2, len(lat_lons), 102))
labels = torch.randn((2, len(lat_lons), 78))

out = model(features)
print(out.shape)
criterion = NormalizedMSELoss(lat_lons=lat_lons, feature_variance=torch.randn((78,)))
loss = criterion(out, labels)
loss.backward()

Expected behavior

I am wondering whether there are other parameters needed to be modified? Thanks a lot!

Additional context

No additional context. And thanks again :)

SauryChen avatar Jan 18 '24 12:01 SauryChen

Oh, I have figured out the solution by changing the for lat in np.arange(-87.1875, 90, 5.625): to for lat in np.arange(-90, 90, 5.625):. However, I am not quite sure about the reasons... Is it related to some settings in the h3 package?

SauryChen avatar Jan 18 '24 13:01 SauryChen

Hi, I am having a look at your first request, and I can't seem to be able to reproduce this bug. I gave it the same input to the encoder (which I assume is the problem from these stack traces). image Could you double-check these? I am primarily following the shapes of inputs as you go through each of the stages of encoding

aavashsubedi avatar Mar 10 '24 11:03 aavashsubedi

Nevermind! I think this got fixed by the other PR see #83

aavashsubedi avatar Mar 10 '24 11:03 aavashsubedi

@aavashsubedi Thank you. It seems to be the same problem in #83 .

SauryChen avatar Mar 10 '24 11:03 SauryChen