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

[Datasets] Can't return ragged array in UDF #30406

Closed
bveeramani opened this issue Nov 17, 2022 · 0 comments · Fixed by #30514
Closed

[Datasets] Can't return ragged array in UDF #30406

bveeramani opened this issue Nov 17, 2022 · 0 comments · Fixed by #30514
Assignees
Labels
bug Something that is supposed to be working; but isn't data Ray Data-related issues P1 Issue that should be fixed within a few weeks

Comments

@bveeramani
Copy link
Member

What happened + What you expected to happen

I tried to apply a function to a batch of ragged images, but I got ValueError: could not broadcast input array from shape (3,300,400) into shape (3,).

Versions / Dependencies

Ray: b0efdb8
Dependencies: https://gist.github.com/bveeramani/2b8678c289ae2faf19d00b7371ddfeba
OS: Linux
Python: 3.7

Reproduction script

import numpy as np
import ray
from torchvision.transforms import Compose, ToTensor, Normalize

dataset = ray.data.read_images("s3://air-example-data-2/imagenet-sample-images/")

transform = Compose([
    ToTensor(), 
    Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) 
])

def map_fn(batch):
    return {"image": np.array([transform(image).numpy() for image in batch], dtype=object)}

dataset.map_batches(map_fn, batch_format="numpy")
RayTaskError(ValueError): ray::_map_block_nosplit() (pid=297, ip=172.28.0.2)
  File "/usr/local/lib/python3.7/dist-packages/ray/data/_internal/compute.py", line 484, in _map_block_nosplit
    for new_block in block_fn(blocks, *fn_args, **fn_kwargs):
  File "/usr/local/lib/python3.7/dist-packages/ray/data/dataset.py", line 597, in transform
    yield from process_next_batch(batch)
  File "/usr/local/lib/python3.7/dist-packages/ray/data/dataset.py", line 579, in process_next_batch
    batch = batch_fn(batch, *fn_args, **fn_kwargs)
  File "<ipython-input-7-2658550a83d0>", line 14, in map_fn
ValueError: could not broadcast input array from shape (3,300,400) into shape (3,)

Issue Severity

Medium: It is a significant difficulty but I can work around it.

@bveeramani bveeramani added bug Something that is supposed to be working; but isn't triage Needs triage (eg: priority, bug/not-bug, and owning component) data Ray Data-related issues labels Nov 17, 2022
@bveeramani bveeramani self-assigned this Nov 17, 2022
@clarkzinzow clarkzinzow added P1 Issue that should be fixed within a few weeks air and removed triage Needs triage (eg: priority, bug/not-bug, and owning component) labels Nov 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something that is supposed to be working; but isn't data Ray Data-related issues P1 Issue that should be fixed within a few weeks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants