Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Speed improvement #218

wants to merge 2 commits into from

Conversation

moinfar
Copy link
Contributor

@moinfar moinfar commented Oct 27, 2023

Speed improvement in:

  1. Data Splitting (scPoli when cell_types are available)
  2. Ptorch data loader: Now we fetch cells in batches when using MultiConditionAnnotatedDataset rather than cell-by-cell and then combining them in custom_collate. This may result in significant dataloader speedup, especially when loading sparse data.

@jan-engelmann
Copy link

Hi!
what's the status here? can this be merged?

@Koncopd
Copy link
Member

Koncopd commented Apr 5, 2024

@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):

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]]

Copy link
Contributor Author

@moinfar moinfar May 29, 2024

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.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants