-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataLoader] Improve typing and documentation of Sampler API for customization #97338
Conversation
removed init of _InfiniteConstantSampler
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/97338
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit 5585f89: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for opening this PR! These cleanups are helpful and are always welcomed. Small comments below:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! LGTM!
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually some changes are needed (primarily linting):
https://github.com/pytorch/pytorch/actions/runs/4498692677/jobs/7931055601
DataLoader typing fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Let me use CI to double check everything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the back-and-forth, but I'm unable to fix the remaining linting error through GitHub (i.e. remove Sequence
from import in dataloader.py
)
https://github.com/pytorch/pytorch/actions/runs/4515159665/jobs/7952316990?pr=97338
docstring fixed
import fixed |
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that we need a follow-up PR to make sure it's not BC-breaking as Sampler
might take indices other than integer
@@ -223,8 +217,8 @@ class DataLoader(Generic[T_co]): | |||
__initialized = False | |||
|
|||
def __init__(self, dataset: Dataset[T_co], batch_size: Optional[int] = 1, | |||
shuffle: Optional[bool] = None, sampler: Union[Sampler, Iterable, None] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Emmm. This is BC breaking. The given sampler
isn't necessarily yielding integers.
|
||
|
||
class DistributedSampler(Sampler[T_co]): | ||
class DistributedSampler(Sampler[int]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto
@@ -12,23 +12,57 @@ | |||
"WeightedRandomSampler", | |||
] | |||
|
|||
T_co = TypeVar('T_co', covariant=True) | |||
T_co = TypeVar('T_co', int, List[int], covariant=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is BC-breaking as adding restriction on the expected type for Sampler
.
API backward compatibility fixed: #97338 (comment) Mapped Dataset can accept noninteger indices from custom Samplers. Fixes #97338 Pull Request resolved: #100409 Approved by: https://github.com/ejguan, https://github.com/NivekT
The |
Explanation with examples of sampler customization added.
Fixes #92268