Count source identities and sampler multiplicities across workers
Track clip provenance, rank/worker assignment, sampler padding, and repeated views so distributed training and evaluation consume the intended video cohort.
On this page
The question for today
What you’ll understand
- Separate stable clip identity from stochastic augmentation-view identity.
- Count padding and dropping under a pinned distributed sampler contract.
- Test rank/worker coverage and evaluation multiplicity explicitly.
Distributed loading can appear balanced while repeating the same videos or losing a tail of the dataset. Long sources also produce many correlated clips, so equal clip counts need not imply equal source exposure. Give every sampled interval a stable identity and make the intended multiplicity visible before discussing epoch speed or accuracy. The data contract includes rank and worker ownership, sampler padding, augmentation views, and resume behavior. Those choices determine which evidence reaches the model and how evaluation denominators should be interpreted.
Separate source, clip, and augmentation-view identity
A stable clip record can include a source-content/version identifier, selected stream, source timestamp interval, and sampling-policy version. A separate view identifier records augmentation parameters or their deterministic derivation. Two views of one clip are not two independent recordings, and two overlapping intervals are not necessarily independent examples. Assign source groups to splits before generating clips so adjacent windows, re-encodes, and crops cannot cross a prohibited group boundary merely by receiving different filenames.
An iterable loader must partition work across both distributed ranks and local worker processes. PyTorch 2.9 documents that each worker gets its own dataset copy, so an unsharded iterator can replay the same records in every worker. One simple deterministic assignment uses a global worker identifier when every rank has the same worker count. More elaborate load balancing is possible, but it must preserve the declared inclusion probabilities and identities rather than hiding repeats behind faster workers.
Sampler padding and loader batching are different operations
For a fixed-size dataset, PyTorch 2.9 DistributedSampler with drop_last=False adds indices so ranks receive equal-length lists; with drop_last=True it drops a tail to divide evenly. Its shuffle order also requires the documented set_epoch call before creating each epoch iterator. Every rank must use compatible dataset ordering, seed, and epoch settings. The sampler's tail policy differs from the DataLoader's batching drop_last option, which acts on batches and should be recorded independently.
Repeated indices may be intentional for training, but evaluation needs its own policy. If repeated occurrences of a clip have identical losses, known multiplicities allow a unique-clip average through inverse-multiplicity weighting. Deduplicating by stable clip ID is another option when predictions are identical and the task permits it. Stochastic views can produce different losses, so this algebra does not prove their gradients or metrics equal a single canonical view. Decide whether the estimand is over clips, sources, or augmented draws.
Audit one epoch and one recovery boundary
Emit an audit trace containing source/clip/view IDs, rank, worker, epoch, and whether an occurrence was introduced by padding. Compare its multiset with the intended manifest, checking missing records and multiplicities rather than only total counts. Include a tiny dataset smaller than or not divisible by the rank count. A resume test must specify whether it restores iterator position exactly or restarts an epoch with an accepted repeat policy; resetting the random seed alone may not restore prefetched worker state.
The modular lab makes ownership arithmetic visible. Reset, set both m=3,a=1, predict residues 0,1,2,0, then take three Steps. Reset and set both m=6,a=1 to represent six distinct worker slots and predict a six-step cycle. Edits retain elapsed time, so compare fresh runs. This counter has no DataLoader, distributed sampler padding, video costs, augmentation randomness, or recovery cursor. Use an actual ID trace to establish coverage and a measured cost trace to assess balance.
Work it through
Count a padded distributed epoch
A fictional fixed dataset has ten ordered clip indices and three distributed ranks. Use PyTorch 2.9 DistributedSampler semantics with shuffle disabled. Compare sampler drop_last=False and True; ignore DataLoader batching for this fixture.
With drop_last=False, each rank receives ceil(10/3)=4 indices. The global index multiset has twelve occurrences, so two are padding repeats of existing indices.
With drop_last=True, each rank receives floor(10/3)=3 indices. There are nine global occurrences, leaving one original clip absent from this epoch under the stated no-shuffle order.
An evaluation denominator of twelve would count the padded occurrences rather than ten unique clips unless the pipeline deduplicates or applies a justified multiplicity policy. The nine-occurrence run also cannot estimate a ten-clip average by simply pretending the missing clip was evaluated.
Equal rank lengths can mean repeated or missing clips. The correct epoch and evaluation interpretation requires stable identities and the actual sampler policy.
The living notebook
Explore the model
Interactive lab · modular
Distinguish rank slots from rank-and-worker slots
Reset → set both m=3,a=1 predicts 0,1,2,0 after three Steps. Reset → set both m=6,a=1 yields a six-step cycle. One Step is one addition. This index counter does not implement video loading, sampler padding, stochastic views, load balance, or iterator recovery.
- Residue r0
- 0
- Orbit period · m/gcd(m,a)
- 12
- Distinct residues visited
- 1 of 12
Addition modulo m starts at zero: rₙ = na mod m. Playback advances two additions per second. The orbit has period m/gcd(m,a), including period one for a = 0. This is not a cryptographic security test or a primality algorithm. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forCoverage needs an identity/multiplicity audit across every ownership dimension.
Pause & reason
Check your understanding
Your turn
Try it yourself
Two ranks each run two iterable-dataset workers over twelve records. Under ownership i mod 4=g, how many records belong to each global worker? What goes wrong if both workers in a rank independently use only i mod 2=rank?
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Count all rank/worker combinations, then check whether two local workers own the same indices.
Compare with the solution
There are four global workers and twelve records, so each owns three indices under i mod 4=g. If both local workers instead apply only the rank-based two-way rule, each worker on a given rank emits the same six indices, duplicating that rank's records. An ID/multiplicity trace exposes the overlap even though every rank appears busy. The exact partition may change for variable worker counts, but ownership must still be unambiguous.
Keep the idea
Take it with you
- Source, clip, and augmentation-view identities serve different accounting purposes.
- Distributed sampler padding, sampler dropping, and batch dropping have distinct effects.
- Audit the full epoch multiset and recovery policy instead of trusting equal rank counts.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.