Add step-aware LTDETR scale jitter control#675
Merged
yutong-xiang-97 merged 7 commits intomainfrom Mar 30, 2026
Merged
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces step-aware hooks for transforms/collate functions to enable step-windowed augmentations (notably LTDETR scale jitter) and safely refresh DataLoader workers when step-dependent worker state changes during training.
Changes:
- Add step-control hooks (
set_step,uses_step_dependent_worker_state,requires_dataloader_reinitialization) for task transforms and collate functions, and propagate the training step into them. - Add
InfiniteCycleIterator.reset()and restart the DataLoader iterator mid-training when a step boundary requires refreshing worker state. - Make LTDETR
scale_jitterstop-aware viastop_step, gate collate-time application by step, and forcepersistent_workers=Falsefor step-aware training dataloaders (with warning/log).
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/_transforms/test_object_detection_transform.py | Adds coverage for step-windowed scale-jitter behavior triggering dataloader reinit. |
| tests/_data/test_infinite_cycle_iterator.py | Adds reset-behavior test for InfiniteCycleIterator. |
| src/lightly_train/_transforms/task_transform.py | Introduces step-aware hook methods on base transform/collate interfaces. |
| src/lightly_train/_transforms/object_detection_transform.py | Implements step-gated scale jitter in the object-detection collate function plus reinit detection. |
| src/lightly_train/_task_models/dinov3_ltdetr_object_detection/transforms.py | Adds stop_step to scale-jitter args and types the model’s scale_jitter accordingly. |
| src/lightly_train/_task_models/dinov2_ltdetr_object_detection/transforms.py | Same as above for DINOv2 LTDETR. |
| src/lightly_train/_data/infinite_cycle_iterator.py | Adds reset() to restart iteration over the wrapped iterable. |
| src/lightly_train/_commands/train_task_helpers.py | Detects step-aware worker state and forces persistent_workers=False (with warning/log). |
| src/lightly_train/_commands/train_task.py | Propagates step into transform/collate each step and resets the infinite dataloader iterator when needed. |
3aa3b2c to
9aca65a
Compare
Contributor
Author
|
/review |
guarin
reviewed
Mar 30, 2026
…ion-with-step-based-control
0eca2ca to
f08694a
Compare
guarin
approved these changes
Mar 30, 2026
3f8bcd5 to
e06df53
Compare
…ion-with-step-based-control
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What has been changed and why?
Enable step-based augmentation control for LTDETR object detection with the following methods:
"Keep all LTDETR augmentations inside the regular transform and collate path, and
propagate the current training step by updating the main-process transform/collate
objects before each batch. When a worker-visible schedule change crosses an augmentation boundary, restart the dataloader iterator so the worker processes receive fresh copies of the transform and collate objects with the new step value."
As a start, this PR applies this approach to the existing
ScaleJitteraugmentation. We use astop_stepto control where this augmentations should be stopped. It is achieved by:ScaleJitterArgs, making LTDETRscale_jitterstop-aware viastop_stepset_step: sets the current optimizer stepuses_step_dependent_worker_statedetermine whether the step-based control is enabledrequires_dataloader_reinitializationflags if dataloader reinit is neededObjectDetectionCollateFunctionto determine if dataloader reset is needed.InfiniteCycleIterator.reset()and restart dataloader iteration when step-dependent worker state changesstop_stepis reached in the main loop.Note that:
persistent_workers=Falsefor step-aware train dataloaders even if the users specifyTrueand emit both a warning and log message when overriding user input.cyclesin theInfiniteCycleIterator.TaskTransformas a placeholder forMosaicTransform.How has it been tested?
Did you update CHANGELOG.md?
Did you update the documentation?