-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from kkovary/101-in-memory-model-loading
101 in memory model loading
- Loading branch information
Showing
6 changed files
with
178 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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,21 +1,21 @@ | ||
repos: | ||
- repo: https://github.com/psf/black | ||
rev: "24.8.0" # run `pre-commit autoupdate` | ||
hooks: | ||
- id: black | ||
- repo: https://github.com/psf/black | ||
rev: "24.8.0" # run `pre-commit autoupdate` | ||
hooks: | ||
- id: black | ||
name: black | ||
entry: black | ||
args: | ||
args: | ||
- --check | ||
language: system | ||
types: [python] | ||
|
||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: "v0.5.7" | ||
hooks: | ||
- id: ruff | ||
- repo: https://github.com/astral-sh/ruff-pre-commit | ||
rev: "v0.5.7" | ||
hooks: | ||
- id: ruff | ||
name: ruff | ||
entry: ruff | ||
args: ["check"] | ||
args: ["check"] | ||
language: system | ||
types: [python] | ||
types: [python] |
This file contains 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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Loading Models Without Disk Storage Using `InMemoryModelStore`\n", | ||
"\n", | ||
"## Introduction\n", | ||
"This tutorial introduces the `InMemoryModelStore` class, an alternative to `ModelStore` designed for environments with limited disk space. This approach is particularly beneficial when memory is more readily available than disk space or disk access is limited or slow.\n", | ||
"\n", | ||
"`InMemoryModelStore` enables model loading directly into memory, bypassing the need for local storage and disk I/O operations.\n", | ||
"\n", | ||
"## Using InMemoryModelStore\n", | ||
"Here's how to use `InMemoryModelStore`:" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from molfeat.store import InMemoryModelStore\n", | ||
"\n", | ||
"# Initialize the in-memory store\n", | ||
"store = InMemoryModelStore(model_store_bucket='s3://my-modelstore-bucket')\n", | ||
"\n", | ||
"# Load a model directly into memory\n", | ||
"model, model_info = store.load('My-Model')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The model is now ready for use without any disk I/O overhead" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import datamol as dm\n", | ||
"from molfeat.trans.pretrained.hf_transformers import PretrainedHFTransformer\n", | ||
"\n", | ||
"smiles = dm.freesolv().iloc[:100].smiles\n", | ||
"\n", | ||
"transformer = PretrainedHFTransformer(kind=model, notation=model_info.inputs, dtype=float)\n", | ||
"features = transformer(smiles)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Benefits and Considerations\n", | ||
"- **Reduced Latency**: By loading models directly into memory, you eliminate the time needed for disk reads.\n", | ||
"- **Efficient Resource Use**: Ideal for serverless environments where disk access might be limited or costly.\n", | ||
"\n", | ||
"However, keep in mind that this approach requires sufficient memory to hold the entire model. Ensure your deployment environment has adequate RAM for your model size." | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.11" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains 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
This file contains 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,3 +1,4 @@ | ||
from .modelcard import ModelInfo | ||
from .modelstore import ModelStore | ||
from .modelstore import InMemoryModelStore | ||
from .modelstore import ModelStoreError |
This file contains 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
This file contains 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