Skip to content

Commit

Permalink
fix circular data source
Browse files Browse the repository at this point in the history
  • Loading branch information
najielhachem committed Oct 2, 2023
1 parent 4d774dd commit 73e348f
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions fairseq2n/src/fairseq2n/data/circular_data_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,25 @@ circular_data_source::circular_data_source(std::vector<data_pipeline> &&pipeline
std::optional<data>
circular_data_source::next()
{
if (eod())
return {};
// One or more data pipelines might be empty, so we have to keep looping
std::optional<data> output{};
while (!output && !eod()) {
auto pipeline_idx = next_index_gen_();

auto pipeline_idx = next_index_gen_();
if (!buffer_[pipeline_idx]) // init buffer at index
buffer_[pipeline_idx] = next_in_pipeline(pipeline_idx);

if (!buffer_[pipeline_idx]) // init buffer at index
output = buffer_[pipeline_idx];
buffer_[pipeline_idx] = next_in_pipeline(pipeline_idx);

auto output = buffer_[pipeline_idx];
buffer_[pipeline_idx] = next_in_pipeline(pipeline_idx);
}

return output;
}

void
circular_data_source::reset()
{
buffer_.clear();
buffer_.assign(pipelines_.size(), std::nullopt);

is_epoch_done_.assign(pipelines_.size(), false);

Expand Down

0 comments on commit 73e348f

Please sign in to comment.