Definition · AI basics
Data loader
A data loader is software that reads data from a source, prepares it and gives it to an AI system. In model training, a data loader makes ordered batches of samples. In LLM applications, the same name frequently means software that reads documents.
Last reviewed
Key points
- A training data loader reads samples, changes them, sets their sequence and gives batches to the model.
- A slow data loader makes the GPU wait. In one study, preprocessing used as much as 65% of epoch time.
- In a benchmark, a change to batch sequence alone cut CIFAR-10 test accuracy from 90.51% to 26.13%.
- A document loader that reads web pages is a network client. CVE-2026-26019 shows the risk.
- The name varies. TensorFlow says input pipeline, LangChain says document loader, and LlamaIndex says Reader.
How a training data loader works
A training data loader does five tasks between storage and the model.
| Task | PyTorch DataLoader (docs v2.15) |
TensorFlow tf.data |
|---|---|---|
| Read | Dataset, num_workers |
Dataset.interleave |
| Change | Transforms in the dataset | Dataset.map |
| Set sequence | Sampler, shuffle=True |
Dataset.shuffle |
| Group | batch_size, collate_fn |
Dataset.batch |
| Give to the model | pin_memory=True |
Dataset.prefetch |
3 risks of a data loader
1. GPU wait time. Without prefetch, TensorFlow says that “your model is sitting idle” while the pipeline fetches data.
| Study | Population | Result |
|---|---|---|
| Murray et al. | Millions of tf.data jobs, Google fleet, one month in 2020 |
20% of jobs spent more than a third of compute time in the input pipeline |
| Mohan et al. | Nine vision and audio models, four datasets | As much as 65% of epoch time in preprocessing |
| Mohan et al. | Same study, language models | Bert-Large and GNMT showed no data stalls |
2. Damage to the model with no change to the data. Shumailov and colleagues attacked only batch sequence, so this differs from data poisoning. On CIFAR-10 with ResNet-18, test accuracy fell from 90.51% to 26.13%. This is a benchmark result, not a reported incident.
3. Unwanted network connections. A document loader that crawls web pages acts on links that it finds. In CVE-2026-26019, a crawled page could point one LangChain loader at cloud metadata services. This is a form of server side request forgery.
In practice
Four checks for security teams follow. They are our synthesis, and no source gives them as one list.
- Examine dataset classes as code. In PyTorch, dataset access, file reads and transforms run in the worker process.
- Show how batches were selected. Shumailov and colleagues say that this randomness “is rarely tested or enforced”. They tell developers to show its provenance.
- Check the files. The Hugging Face
load_datasetfunction has SHA256 checks of downloaded files, but they are off by default. - Update the loaders. Use
@langchain/community1.1.14 or a subsequent version. Hugging Facedatasets4.0.0 removed dataset scripts and trust_remote_code support.
Three facts can surprise a team:
- PyTorch
shuffleis off by default. - Each PyTorch worker gets a copy of an iterable dataset. The copies need different settings, or the workers give duplicate data.
- Mohan and colleagues found a need for 3 to 24 CPU cores for each GPU. Light models such as ResNet18 needed the most.
Where definitions disagree
“Data loader” has no single meaning. Examine the context before you compare two tools.
| Term | Source | What it does | Output |
|---|---|---|---|
DataLoader |
PyTorch | Gives samples to training code | Batches |
| Input pipeline | TensorFlow | Reads and changes data for training | Dataset elements |
| Document loader | LangChain | Reads data from different sources | Document objects |
Data connector, or Reader |
LlamaIndex | Takes data from sources and formats | Document objects |
A document loader is one part of an application such as retrieval-augmented generation. It does not make training batches.
Questions and answers
What does a data loader do in machine learning?
A data loader reads training samples from storage and changes them for the model. It sets their sequence and gives the model one batch at a time. The PyTorch DataLoader and the TensorFlow tf.data API are two examples.
What is the difference between a data loader and a document loader?
A training data loader gives batches of samples to a model during training. A document loader reads files or web pages into Document objects for an LLM application. LangChain uses the term document loader.
Can a data loader be a security risk?
Yes. In a benchmark, researchers cut model accuracy with only a change to batch sequence. Document loaders can also fetch addresses that an attacker chooses, as CVE-2026-26019 showed in a LangChain web loader.
Sources
- torch.utils.data documentation, PyTorch 2.15PyTorch
- tf.data: Build TensorFlow input pipelinesTensorFlow
- Better performance with the tf.data APITensorFlow
- tf.data: A Machine Learning Data Processing FrameworkarXiv (Murray et al.), 23 Feb 2021
- Analyzing and Mitigating Data Stalls in DNN TrainingarXiv (Mohan et al.), 19 Jan 2021
- Manipulating SGD with Data Ordering AttacksarXiv (Shumailov et al., NeurIPS 2021), 5 Jun 2021
- Document loadersLangChain
- Data connectorsLlamaIndex
- GHSA-gf3v-fwqg-4vh7GitHub Advisory Database, 11 Feb 2026
- datasets 4.0.0 release notesHugging Face
- Build and loadHugging Face