-
Notifications
You must be signed in to change notification settings - Fork 51
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
Speed improvement #218
base: master
Are you sure you want to change the base?
Speed improvement #218
Conversation
Hi! |
@moinfar sorry for being slow on this. Have you rerun the scpoli tutorials with this PR to check that everything is fine? |
@@ -76,27 +76,31 @@ def __init__(self, | |||
self.cell_types = np.stack(self.cell_types).T | |||
self.cell_types = torch.tensor(self.cell_types, dtype=torch.long) | |||
|
|||
def __getitem__(self, index): | |||
def __getitems__(self, indices): |
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.
Why introduce a new name here? __getitem__
in this implementation simply calls this method. Maybe it is better not to duplicate it in such case. indices
can simply be a Union[int, Collection[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.
The core implementation is not duplicated. __getitem__
now calls __getitems__
which accepts both list indices and single indices.
The reason that we have to maintain both interfaces is that pytorch data loader originally uses __getitem__
. But if you also provide __getitems__
, then it will use it, and we benefit from the parallel fetching of samples. I am not sure about the newer versions of pytorch but the one scArches is using does not automatically fetch multiple samples if __getitems__
interface is not available.
You can also check this issue in pytorch repo.
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.
I see, thanks! Didn't know it about pytorch
Speed improvement in:
MultiConditionAnnotatedDataset
rather than cell-by-cell and then combining them incustom_collate
. This may result in significant dataloader speedup, especially when loading sparse data.