add sequential sampling#42265
Conversation
|
cc @SunMarc |
|
Hey @jiosephlee, I don't mind adding this but did you manage to do an experiment where this leads to better training overall ? |
|
Hey @SunMarc ! Sequential sampling in and of itself wouldn't improve training, but yes, I'm doing research currently where a well-designed curriculum can lead to better performance. There are also prior works that support this e.g. https://arxiv.org/abs/2405.07490. A common way of organizing data in this field is from easy to hard: https://dl.acm.org/doi/abs/10.1145/3589335.3641257 |
|
Maybe we can first gauge the interest from the community before merging this ? TrainingArgs is already super bloated so I prefer to not add any args that have low usage. Could you create an issue so that we see if folks are interested in ? |
|
@SunMarc, that totally makes sense. I just created an issue, and I can re-bump this PR once it's garnered some interest. I know folks like @qgallouedec have wanted this as well, if this helps clarify the need for this feature (correct me if I'm wrong, Quentin!) |
|
Thznks! Yes, to give more context: Currently, if I want to sample my data in order, I can't. The PR in the current state is a solution, but in my opinion, sequential sampling should be the default. If we agree on this, I see two options
In both cases it would change the default behavior of the trainer |
|
@qgallouedec I will +1 on the default behavior change. The default behavior is likely unexpected for many, especially for those coming from PyTorch, which also has the shuffle off as default https://docs.pytorch.org/docs/stable/data.html#torch.utils.data.DataLoader Concerning (2), there is an issue that would arise from forgoing RandomSampler. RandomSampler has a nice property where you can reset the shuffle at each epoch, and it appears to be used in Trainer. transformers/src/transformers/trainer.py Line 2465 in d6a6c82 Otherwise, it seems difficult to implement epoch-level shuffling outside of Trainer. |
Can you explain why ? For the training dataset, it should be better to have have random sampling in general no ? Maybe as a first set, we can create a new arg called Happy new year btw ;) |
|
@SunMarc happy new year :) And that's a pretty clean suggestion! I took a stab at refactoring it based on what you said. I took the liberty of changing one of the ValueErrors to a warning because the IterableDataset incompatibility seems to be an issue for any Sampler, afaik, which is why samplers are entirely skipped in line 1037. |
|
Yes, that sounds good to me too. With one small reservation about the name. Because this argument would not take a sampler, but rather a strategy. So maybe |
Yes indeed. The motivation was mainly to avoid the surprise caused by the fact that the PyTorch loader is sequential by default, but shuffling by default is also a good default. |
| logger.warning( | ||
| f"The `train_sampler='{args.train_sampler}'` option is ignored when using an `IterableDataset`. " | ||
| "Samplers cannot be used with IterableDataset as they require indexed access to the dataset." | ||
| ) |
There was a problem hiding this comment.
This is indeed true. sampler field will be ignored when using IterableDataset. Since this behavior is silently ignored by torch, maybe we can just throw logger.info instead of a warning.
| train_sampler (`str`, *optional*, defaults to `"random"`): | ||
| The sampler to use for the training dataloader. Possible values are: |
There was a problem hiding this comment.
maybe specify here instead that it only works when the dataset is not an interabledataset
| group_by_length (`bool`, *optional*, defaults to `False`): | ||
| Whether or not to group together samples of roughly the same length in the training dataset (to minimize | ||
| padding applied and be more efficient). Only useful if applying dynamic padding. | ||
| train_sampler (`str`, *optional*, defaults to `"random"`): |
There was a problem hiding this comment.
as quentin suggested, maybe we should switch to train_sampling_strategy
|
Moved this to new PR #43138 |
What does this PR do?
Adds Sequential Sampling! All huggingface trainers default to random sampling, and there is no way to allow a sequential sampling, which is valuable when the user has a custom data curriculum, for instance.
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.