trl icon indicating copy to clipboard operation
trl copied to clipboard

🐛 [Bug] get_dataset raises ZeroDivisionError for zero-sum fractions

Open YZJF opened this issue 3 months ago • 2 comments

Reproduction

trl/scripts/utils.py is unchanged between the observed failing base 6630e17 and current main (f341a51). The following configuration reproduces the problem with two zero target shares:

from trl import DatasetMixtureConfig, get_dataset
from trl.scripts.utils import DatasetConfig

mixture = DatasetMixtureConfig(
    datasets=[
        DatasetConfig(
            path="trl-internal-testing/zen",
            name="standard_language_modeling",
            fraction=0.0,
        ),
        DatasetConfig(
            path="trl-internal-testing/zen",
            name="standard_language_modeling",
            fraction=0.0,
        ),
    ]
)
get_dataset(mixture)

The fraction normalization currently divides by sum(fractions) after loading the datasets, producing ZeroDivisionError: float division by zero for this configuration.

Negative fractions are also accepted and can produce negative selection sizes instead of an actionable configuration error.

Expected behavior

Validate configured fractions before loading datasets: reject negative values and require their sum to be positive with a clear ValueError. Individual zero fractions should remain supported when at least one dataset has a positive share.

System Info

  • Platform: macOS-26.5.2-arm64-arm-64bit-Mach-O
  • Python version: 3.13.5
  • TRL version: 1.13.0.dev0+f341a51
  • PyTorch version: 2.13.0
  • accelerator(s): cpu
  • Transformers version: 5.16.1
  • Accelerate version: 1.14.0
  • Accelerate config: not found
  • Datasets version: 5.0.1
  • HF Hub version: 1.29.0
  • bitsandbytes version: not installed
  • DeepSpeed version: not installed
  • Liger-Kernel version: not installed
  • PEFT version: not installed
  • vLLM version: not installed

Checklist

  • [x] I have checked that this issue is not already filed.
  • [x] I have included system information.
  • [x] The code sample is minimal, complete, and reproducible.
  • [x] The code sample is formatted in code blocks.
  • [x] No traceback is included; the exception and minimal reproduction are provided above.

YZJF avatar Aug 31 '26 05:08 YZJF

Why would someone use a 0 or negative fraction?

qgallouedec avatar Sep 15 '26 16:09 qgallouedec

Hey @YZJF, closing this one since the question above didn't get a follow-up. A mixture where every fraction is 0 asks to train on nothing, so failing at startup is a reasonable outcome, and negative fractions have no meaning.

qgallouedec avatar Oct 14 '26 03:10 qgallouedec