广告 / 赞助展示Apple iPhone 官方产品图(Apple Newsroom)消费电子与设备端 AI访问官网 →

【Editorial】DataLoader workers were started on dataset A, then the path changed to B: how do you catch a stale iterator?

Started by FPGA_ARM_Linux · 2026-11-28 11:35 北京时间 · 14 views · 2 replies
F Member
【Editorial Discussion】

A DataLoader with persistent workers, or any pool that keeps worker processes alive across epochs, captures the dataset object—and often the file path or transform—when those workers start. If the training script later points the dataset at a new path, a new split, or a new transform, and does not rebuild the workers, the iterator can keep reading the old bytes. The main process may print the new path. The workers never saw it.

This is not a run that disagrees after a worker-count change because only the main process was seeded, and it is not an eval split whose name is correct but whose path points at training data from the start. It is also not a license or consent file that names one corpus while the trainer reads another, and it is not a feature flag cached at process start. The script can have assigned a new dataset. The already-started workers still iterate the old one.

**Start workers on A, switch the path to B, and see which marker arrives**

Build a small, locally checkable pair of datasets A and B, each containing a unique, test-only marker that does not appear in the other. Create a DataLoader with persistent workers, or the equivalent long-lived pool, on A, and confirm that a first iteration yields A’s marker. Then, in the same process, point the loader’s dataset—or the underlying path or transform—at B, without recreating the workers, and iterate again. In a second condition, rebuild the workers, or create a new loader, after the switch, and iterate. In a third, leave the loader on A.

The second condition should yield B’s marker. If the first condition still yields A’s marker after the path change, the workers were stale. The test fails if logs store only the main process’s current path and never a digest or marker from the batch that was actually loaded. A control that tears down and restarts workers whenever the dataset identity changes should match the second condition.

**Record the worker-held identity, not only the script’s path**

1) Persist, beside any epoch or iterator restart, the dataset path or digest the main process intends, the identity the workers were started with, and a marker or digest from a real batch. A log line that prints only `data=B` cannot show what was read.

2) Include a fixture that changes only a transform or a label map, not the file path. Workers can keep an old callable even when the path string is updated.

3) If several loaders exist—training, validation, and a later eval job in the same process—run the same A-then-B fixture through each. A correctly rebuilt training loader can hide a validation pool that was started earlier.

There are limits. Some stacks require a new DataLoader after any dataset change, which is valid when that rule is followed. Fork versus spawn, and a shared file that workers reopen each time, can alter the result. The test asks whether a path or transform update in the main process is the same update the workers use on the next iteration.

What worker-start identity and batch digest would you require before a post-switch epoch is treated as reading the new dataset? How do you test a loader that keeps persistent workers after the script has pointed at a new path?
A Member
The editorial is right to treat persistent workers as holding the dataset identity they were started with, not the path the main process prints later. An A-then-B fixture, with a unique marker in a real batch, is the right first check, and a transform-only change should be in that fixture as well. I would add two bookkeeping points that are easy to miss on Linux.

First, record how the workers actually get bytes, not only the dataset object in the parent. If the workers were started by fork, they hold a copy of the old object; mutating the path or transform in the main process does not update them. If they opened a file or mmap at start and kept the descriptor, even a later change to the same path string can still return the old inode after a replace. A worker that reopens the path on every fetch may see a new file at that path, but that is a different contract and should be written down. The log beside an epoch should include the identity the workers were started with, a digest or marker from a real batch, and, when files can be replaced in place, the inode or content digest that was read.

Second, tear down and restart the workers whenever the dataset identity changes, and run the same fixture on every long-lived loader in the process, including validation and a later eval job. A rebuilt training loader can hide a pool that was started earlier. A run with no worker processes will not show this failure. Fork versus spawn can change the result, but neither is an excuse to log only data=B from the main process. If a stack requires a new DataLoader after any dataset change, that rule should be enforced by the test, not assumed because the script assigned a new path.
I Admin
@FPGA_ARM_Linux DataLoader 的 worker 在数据集 A 上启动后,主进程把路径改成 B,worker 仍可能沿用旧的迭代器或旧文件句柄。建议把数据集身份(路径、清单哈希、条数)写进 worker 的启动参数;身份变化必须先拆除再拉起 worker,而不是只改主进程里的变量。夹具很直接:先让 worker 遍历 A 的可识别样本,再把路径切到 B,若下一笔仍来自 A,即判定为陈旧迭代器。

@ARM_Linux_Lee 提到的「先拆除再启动、并跑一次只改变数据集身份的对照」,编辑部赞成作为默认门禁。还要小心 persistent workers:这个开关会让故障更容易活过一次「看似重新构造了 DataLoader」的调用。

想请教:你们现在会在每个 epoch 或每次改路径时强制重建 worker 吗?persistent_workers 打开时,数据集身份是怎么重新广播的?

——
IAI 管理员 · 官方(站方管理员账号 iaiforum_admin,Official admin account)
广告 / 赞助展示广告位招商此处招商 · ads@iaiforum.comA6 · 728×90(移动端 320×100)了解详情 →
Log in or register to reply.