Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

batch_dims seems not to be respected for 0.2.0? #131

Closed
arbennett opened this issue Dec 1, 2022 · 2 comments · Fixed by #132
Closed

batch_dims seems not to be respected for 0.2.0? #131

arbennett opened this issue Dec 1, 2022 · 2 comments · Fixed by #132
Labels
bug Something isn't working

Comments

@arbennett
Copy link

arbennett commented Dec 1, 2022

What happened?

I believe this is somewhat related to #121 where up front computation is slowed down due to ignoring the batch_dims keyword argument, meaning that batches are essentially duplicated, and very large to compute. This is reproducible in a google colab notebook just by changing the installed version between 0.1.0 and 0.2.0.

Minimal Complete Verifiable Example

import xbatcher
import xarray as xr
import numpy as np
shape = (30, 4, 2)
dims = ('z', 'y', 'x')

ds = xr.Dataset()
ds['v1'] = xr.DataArray(data=np.random.random(shape), dims=dims )
ds['v2'] = xr.DataArray(data=np.random.random(shape), dims=dims )
bgen1 =  xbatcher.BatchGenerator(
    ds=ds, input_dims={'z': 10}
)
bgen2 =  xbatcher.BatchGenerator(
    ds=ds, input_dims={'z': 10}, batch_dims={'y': 2, 'x': 1},
)

print('No batch_dims:   ', next(iter(bgen1)).dims)
print('With batch_dims: ', next(iter(bgen2)).dims)

Environment

On version 0.1.0 I get the output:

No batch_dims:    Frozen({'z': 10, 'sample': 8})
With batch_dims:  Frozen({'z': 10, 'sample': 2})

On version 0.2.0 I get the output:

No batch_dims:    Frozen({'z': 10, 'sample': 8})
With batch_dims:  Frozen({'z': 10, 'sample': 8})
@arbennett arbennett added the bug Something isn't working label Dec 1, 2022
@maxrjones
Copy link
Member

Thanks for the bug report and MVCE @arbennett.

Yes, this is connected to #121, with an explanation of the problem in #121 (comment). In summary, batch_dims in v0.2.0 erroneously only controls the number of batches but not their size. I'm aiming to open a proposed fix today.

@maxrjones
Copy link
Member

As a stopgap measure, if needed you could install the last pre-regression commit using:

python -m pip install git+https://github.com/xarray-contrib/xbatcher.git@4d8e2c84a2d405e237f60f1df5286dd766e06ff0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants