Li_Bin
1
ds = ray.data.from_items([
{“food”: “spam”, “price”: 9.34},
{“food”: “ham”, “price”: 5.37},
{“food”: “eggs”, “price”: 0.94}
])
Now ray supports for loop in batches as below:
for batch in ds.iter_batches().
Suppose I want to iterate the batches manually with next() , is it possbile ?
sjl
2
Yes, it should be possible. Something like:
iterator = iter(ds.iter_batches(...))
next(iterator)
should work.
Li_Bin
4
No, it doesn’t work. I have tried it .
sjl
5
This worked for me:
import ray
>>> ds = ray.data.from_items([
... {"food": "spam", "price": 9.34},
... {"food": "ham", "price": 5.37},
... {"food": "eggs", "price": 0.94}
... ])
>>> iterator = iter(ds.iter_batches(batch_size=1))
>>> next(iterator)
{'food': array(['spam'], dtype=object), 'price': array([9.34])}
Li_Bin
6
My falut. I have tried
iterator = ds.iterator()
print(next(iterator))
it didn’t work. But your code works well. Thanks a lot.