-
Notifications
You must be signed in to change notification settings - Fork 1
📝 Added speed comparison to other data loaders #36
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
Open
felix0097
wants to merge
2
commits into
main
Choose a base branch
from
benchmarks
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,8 @@ | ||||||||
# arrayloaders | ||||||||
|
||||||||
> [!CAUTION] | ||||||||
> This pacakge does not have a stable API. However, we do not anticipate the on-disk format to change as it is simply an anndata file. | ||||||||
> This package does not have a stable API. However, we do not anticipate the on-disk format to change as it is simply an | ||||||||
> anndata file. | ||||||||
|
||||||||
[![Tests][badge-tests]][tests] | ||||||||
[![Documentation][badge-docs]][documentation] | ||||||||
|
@@ -53,7 +54,7 @@ create_store_from_h5ads( | |||||||
"path/to/your/file1.h5ad", | ||||||||
"path/to/your/file2.h5ad" | ||||||||
], | ||||||||
output_path="path/to/output/store", # a directory containing `chunk_{i}.zarr` | ||||||||
output_path="path/to/output/store", # a directory containing `chunk_{i}.zarr` | ||||||||
shuffle=True, # shuffling is needed if you want to use chunked access | ||||||||
) | ||||||||
``` | ||||||||
|
@@ -102,44 +103,62 @@ for batch in ds: | |||||||
... | ||||||||
``` | ||||||||
|
||||||||
For performance reasons, you should use our dataloader directly without wrapping it into a {class}`torch.utils.data.dataloader`. | ||||||||
For performance reasons, you should use our dataloader directly without wrapping it into a {class} | ||||||||
`torch.utils.data.dataloader`. | ||||||||
Comment on lines
+106
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
Your code will work the same way as with a {class}`torch.utils.data.dataloader`, but you will get better performance. | ||||||||
|
||||||||
#### User configurable sampling strategy | ||||||||
|
||||||||
At the moment we do not support user-configurable sampling strategies like weighting or sampling. | ||||||||
With a pre-shuffled store and blocked access, your model fit should not be affected by using chunked access. | ||||||||
|
||||||||
If you are interested in contributing this feature to the project or leaning more, please get in touch on [zulip](https://scverse.zulipchat.com/) or via the GitHub issues here. | ||||||||
If you are interested in contributing this feature to the project or leaning more, please get in touch | ||||||||
on [zulip](https://scverse.zulipchat.com/) or via the GitHub issues here. | ||||||||
Comment on lines
+115
to
+116
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please resolve all these linebreak issues |
||||||||
|
||||||||
## Speed comparison to other dataloaders | ||||||||
|
||||||||
We provide a quickstart notebook that gives both some boilerplate code and provides a speed comparison to other comparable dataloaders: | ||||||||
We provide a speed comparison to other comparable dataloaders below. | ||||||||
Notably, our data loader comes with a significant speedup compared to other dataloaders: | ||||||||
|
||||||||
TODO: figure and notebook | ||||||||
<img src="docs/_static/speed_comparision.png" alt="fit_time_vs_loading_speed" width="400"> | ||||||||
|
||||||||
We've run the above benchmark on an AWS `ml.m5.8xlarge` instance. | ||||||||
The code to reproduce the above results can be found on LaminHub: | ||||||||
|
||||||||
* [Benchmark results](https://lamin.ai/laminlabs/arrayloader-benchmarks/transform/e6Ry7noc4Y0d) | ||||||||
* [Arrayloaders code](https://lamin.ai/laminlabs/arrayloader-benchmarks/transform/yl0iTPhJjkqW) | ||||||||
* [MappedCollection code](https://lamin.ai/laminlabs/arrayloader-benchmarks/transform/YfzHfoomTkfu) | ||||||||
* [scDataset code](https://lamin.ai/laminlabs/arrayloader-benchmarks/transform/L6CAf9w0qdQj) | ||||||||
|
||||||||
## Why data loading speed matters? | ||||||||
|
||||||||
Most models for scRNA-seq data are pretty small in terms of model size compared to models in other domains like computer vision or natural language processing. | ||||||||
Most models for scRNA-seq data are pretty small in terms of model size compared to models in other domains like computer | ||||||||
vision or natural language processing. | ||||||||
This size differential puts significantly more pressure on the data loading pipeline to fully utilize a modern GPU. | ||||||||
Intuitively, if the model is small, doing the actual computation is relatively fast. | ||||||||
Hence, to keep the GPU fully utilized, the data loading needs to be a lot faster. | ||||||||
|
||||||||
As an illustrative, example let's train a logistic regression model ([notebook hosted on LaminHub](https://lamin.ai/laminlabs/arrayloader-benchmarks/transform/cV00NQStCAzA?filter%5Band%5D%5B0%5D%5Bor%5D%5B0%5D%5Bbranch.name%5D%5Beq%5D=main&filter%5Band%5D%5B1%5D%5Bor%5D%5B0%5D%5Bis_latest%5D%5Beq%5D=true)). | ||||||||
Our example model has 20.000 input features and 100 output classes. We can now look how the total fit time changes with data loading speed: | ||||||||
As an illustrative, example let's train a logistic regression | ||||||||
model ([notebook hosted on LaminHub](https://lamin.ai/laminlabs/arrayloader-benchmarks/transform/cV00NQStCAzA?filter%5Band%5D%5B0%5D%5Bor%5D%5B0%5D%5Bbranch.name%5D%5Beq%5D=main&filter%5Band%5D%5B1%5D%5Bor%5D%5B0%5D%5Bis_latest%5D%5Beq%5D=true)). | ||||||||
Our example model has 20.000 input features and 100 output classes. We can now look how the total fit time changes with | ||||||||
data loading speed: | ||||||||
|
||||||||
<img src="docs/_static/fit_time_vs_loading_speed.png" alt="fit_time_vs_loading_speed" width="400"> | ||||||||
|
||||||||
From the graph we can see that the fit time can be decreased substantially with faster data loading speeds (several orders of magnitude). | ||||||||
E.g. we are able to reduce the fit time from ~280s for a data loading speed of ~1000 samples/sec to ~1.5s for a data loading speed of ~1.000.000 samples/sec. | ||||||||
From the graph we can see that the fit time can be decreased substantially with faster data loading speeds (several | ||||||||
orders of magnitude). | ||||||||
E.g. we are able to reduce the fit time from ~280s for a data loading speed of ~1000 samples/sec to ~1.5s for a data | ||||||||
loading speed of ~1.000.000 samples/sec. | ||||||||
This speedup is more than 100x and shows the significant impact data loading has on total training time. | ||||||||
|
||||||||
## When would you use this data laoder? | ||||||||
|
||||||||
As we just showed, data loading speed matters for small models (e.g., on the order of an scVI model, but perhaps not a "foundation model"). | ||||||||
As we just showed, data loading speed matters for small models (e.g., on the order of an scVI model, but perhaps not a " | ||||||||
foundation model"). | ||||||||
But loading minibatches of bytes off disk will be almost certainly slower than loading them from an in-memory source. | ||||||||
Thus, as a first step to assessing your needs, if your data fits in memory, load it into memory. | ||||||||
However, once you have too much data to fit into memory, for whatever reason, the data loading functionality offered here can provide significant speedups over state of the art out-of-core dataloaders. | ||||||||
However, once you have too much data to fit into memory, for whatever reason, the data loading functionality offered | ||||||||
here can provide significant speedups over state of the art out-of-core dataloaders. | ||||||||
|
||||||||
## Release notes | ||||||||
|
||||||||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
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.
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 the change?