# \[SGD\] \[Tune\] Issue with ray.util.sgd.data.Dataset API

**URL:** <https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383>\
**Category:** Ray Tune\
**Created:** [March 24, 2021, 5:15pm UTC](https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383 "2021-03-24T17:15:23Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![SumanthDatta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sumanthdatta/32/476_2.png) [@SumanthDatta](https://discuss.ray.io/u/SumanthDatta)\
**Post date:** [March 24, 2021, 5:15pm UTC](https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383/1 "2021-03-24T17:15:23Z")

</div>

Hi ,

I have been using ray.util.sgd.data.Dataset with pytorch . The sole purpose of this API is to ingest huge data into ray and train it.

In my case when trying to train the data .It displays

{‘num\_samples’: 351, ‘epoch’: 1.0, ‘batch\_count’: 1.0, ‘train\_loss’: 1.201025366783142, ‘last\_train\_loss’: 1.201025366783142}  
{‘num\_samples’: 0, ‘epoch’: 2.0, ‘batch\_count’: 0.0}  
{‘num\_samples’: 0, ‘epoch’: 3.0, ‘batch\_count’: 0.0}

All the samples are loaded into the first epoch always. The other epochs are all empty.

My code snippet

```
   MyTrainingOperator = TrainingOperator.from_creators(
   model_creator= model_creator, optimizer_creator=optimizer_creator,
   loss_creator= torch.nn.CrossEntropyLoss, scheduler_creator=scheduler_creator,
   data_creator=None)

  trainer = TorchTrainer(
  training_operator_cls=MyTrainingOperator,
  scheduler_step_freq="epoch",
  config={"batch_size": 64}
  )

 # fetching values from database using Dataset.
db_dataset = fetch_values_from_database()

for i in range(500):
   # Train for another epoch using the dataset
    stats = trainer.train(dataset=db_dataset , num_steps=200)
    print(stats)

```

I can share more details on the dataset. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![amogkam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amogkam/32/17_2.png) [@amogkam](https://discuss.ray.io/u/amogkam)\
**Post date:** [March 24, 2021, 5:29pm UTC](https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383/2 "2021-03-24T17:29:07Z")

</div>

@SumanthDatta hmm this is odd. could you provide a small reproducible example so I can try it out? Thanks.

---

<div class="post-metadata">

**Author:** ![SumanthDatta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sumanthdatta/32/476_2.png) [@SumanthDatta](https://discuss.ray.io/u/SumanthDatta)\
**Post date:** [March 24, 2021, 6:13pm UTC](https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383/3 "2021-03-24T18:13:39Z")

</div>

Sure I will try to provide an example, in my case the data is fetched from a database. The fetching part is done using parallel iterator. Parallel iterator is passed to a dataset class.

---

<div class="post-metadata">

**Author:** ![amogkam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amogkam/32/17_2.png) [@amogkam](https://discuss.ray.io/u/amogkam)\
**Post date:** [March 24, 2021, 6:14pm UTC](https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383/4 "2021-03-24T18:14:48Z")

</div>

Does the same problem happen for you with the basic example on the docs? It would really help to debug if there is a small, reproducible example I can try out.

---

<div class="post-metadata">

**Author:** ![SumanthDatta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sumanthdatta/32/476_2.png) [@SumanthDatta](https://discuss.ray.io/u/SumanthDatta)\
**Post date:** [March 25, 2021, 4:34pm UTC](https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383/5 "2021-03-25T16:34:31Z")

</div>

@amogkam , i am sharing the code in the below link. I was able to replicate the issue. I might be dong some thing wrong here. Please help in identifying the issue.

[https://codeshare.io/29o7R8](https://codeshare.io/29o7R8)

The dataset used is

[https://raw.githubusercontent.com/jbrownlee/Datasets/master/ionosphere.csv](https://raw.githubusercontent.com/jbrownlee/Datasets/master/ionosphere.csv)

Download the csv and provide path in the code. Thanks in advance. If this problem is solved. It will be great help to me.

---

<div class="post-metadata">

**Author:** ![SumanthDatta](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/sumanthdatta/32/476_2.png) [@SumanthDatta](https://discuss.ray.io/u/SumanthDatta)\
**Post date:** [March 26, 2021, 1:37am UTC](https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383/6 "2021-03-26T01:37:35Z")

</div>

@amogkam , any findings till now?

---

<div class="post-metadata">

**Author:** ![amogkam](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ray.io/amogkam/32/17_2.png) [@amogkam](https://discuss.ray.io/u/amogkam)\
**Post date:** [April 23, 2021, 6:22pm UTC](https://discuss.ray.io/t/sgd-tune-issue-with-ray-util-sgd-data-dataset-api/1383/7 "2021-04-23T18:22:50Z")

</div>

Hey @SumanthDatta apologies for the late response here. Can you try with this change: `it = ray.util.iter.from_items(rows_list)` → `it = ray.util.iter.from_items(rows_list, repeat=True)`
