mosaicml / llm-foundry

LLM training code for Databricks foundation models
https://www.databricks.com/blog/introducing-dbrx-new-state-art-open-llm
Apache License 2.0
3.84k stars 503 forks source link

Fix packing + streaming + resumption #1277

Closed dakinggg closed 3 weeks ago

dakinggg commented 3 weeks ago

There was a long standing bug when resuming a streaming, finetuning dataset with packing enabled. The issue would only occur if you resumed not on an epoch boundary. The issue would be fairly significant, in that resumption would resume at an earlier sample than it should have, so data would be unexpectedly repeated. The root cause of the issue is that, when packing, the num samples recorded for streaming resumption needed to be multiplied by the packing ratio.

Manual test, with PR, resumption is deterministic:

Screenshot 2024-06-14 at 2 42 55 AM

Before this PR (note, loss is lower upon resumption because its repeating samples, and then it reverts to the same general loss curve once its through the repeats):

Screenshot 2024-06-14 at 11 24 59 AM

The above plots were with num_workers=0, when setting num_workers=8, we discovered a second deterministic resumption bug, where the wrong batch size was passed to streaming. This has now also been fixed, and here is a manual test with num_workers=8.

Screenshot 2024-06-14 at 2 33 17 PM

Note: There will still be some non determinism if max_leftover_bins_to_keep is not set to zero, because we don't save the reservoir. This will just be slight non determinism, as opposed to the current bug which would repeat samples.