add compression to property files - #42
Draft
sfluegel05 wants to merge 2 commits into
Draft
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces a compression/decompression layer for cached molecular property tensors to substantially reduce on-disk storage, with special handling to avoid storing large dense one-hot matrices.
Changes:
- Add
compress()/decompress()hooks toPropertyEncoder, with concrete implementations for one-hot, boolean, and float “as-is” encoders. - Apply compression when saving processed property caches and decompression immediately after loading them in the ChEBI dataset pipeline.
- Store one-hot encodings as compact class-index vectors on disk and reconstruct one-hot tensors at load time.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
chebai_graph/preprocessing/property_encoder.py |
Adds encoder-level compression/decompression APIs and implements compact storage for one-hot/bool/float encodings. |
chebai_graph/preprocessing/datasets/chebi.py |
Integrates compression into property caching (torch.save) and decompression into property loading (torch.load). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+299
to
+300
| dtype = torch.uint8 if tensor.shape[1] + 1 < 256 else torch.int16 | ||
| return indices.to(dtype) |
Comment on lines
168
to
+176
| assert len(encoded_values) == len(idents) == len(features) | ||
| torch.save( | ||
| [ | ||
| {property.name: torch.cat(feat), "ident": id} | ||
| { | ||
| property.name: property.encoder.compress( | ||
| torch.cat(feat) | ||
| ), | ||
| "ident": id, | ||
| } |
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.
Property files take up an absurd amount of disk space.
For instance, for a ChEBI50 dataset (v244), the
graph_properties\propertiesfolder has nearly 10GB.AtomType_one_hot.ptalone has 6.4GB.This PR compresses data before saving it to a file (and decompresses when loading). Especially the one-hot encodings don't need to be saved as one-hot tensors. So they are now stored as 1-d and re-converted to one-hot when loading.
File sizes are reduced by a factor of up to 109: