Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
9e54fb0
dynamic=True, mods to PredictTokenizer
mbabadi Dec 4, 2024
39f41a3
misc
mbabadi Dec 7, 2024
aa02254
wip
Dec 11, 2024
c0c1d27
Add `ComputeNorm` callback (#276)
Dec 11, 2024
89af997
PyTreeDataset
Dec 12, 2024
f22c3a6
fixes
Dec 12, 2024
6829b91
Merge branch 'main' into cellarium-gpt-model
Dec 12, 2024
a3c055b
merge pytree-dataset
Dec 12, 2024
ff5321a
pass the test
Dec 12, 2024
f85850c
Merge branch 'main' into pytree-dataset
Dec 12, 2024
a43f2b1
Merge branch 'pytree-dataset' into cellarium-gpt-model
Dec 12, 2024
f471934
fixes
Dec 12, 2024
b44407e
inference
mbabadi Dec 12, 2024
7277d76
Fix issue with mypy in lightning 2.5.0.post0 (#282)
sjfleming Jan 3, 2025
3677c22
PredictWriter can choose predict() key (#267)
sjfleming Jan 3, 2025
2f580e6
Merge branch 'main' into pytree-dataset
Jan 8, 2025
1ca6113
Merge branch 'pytree-dataset' into cellarium-gpt-model
Jan 8, 2025
4055010
`PyTreeDataset` (#278)
Jan 9, 2025
982692d
Merge branch 'main' into cellarium-gpt-model
Jan 9, 2025
a854767
Ruff upgrade to v0.9.1 slightly changed assertions and f-strings (#284)
sjfleming Jan 10, 2025
fa01308
token_type_nc
Jan 14, 2025
ced25c3
Merge branch 'main' into cellarium-gpt-model
Jan 14, 2025
78eb7b1
clean up
Jan 14, 2025
2c0e560
rename
Jan 14, 2025
ad665dd
fix docstring
Jan 14, 2025
71ee806
fix test
Jan 14, 2025
a80538e
TrainTokenizer
Jan 15, 2025
699956d
token_mask
Jan 15, 2025
ab6e5a2
remove matmul precision
Jan 15, 2025
090161e
Update README.rst (#287)
mbabadi Jan 17, 2025
143e17a
predict
Jan 19, 2025
8e7c817
`PredictionWriter`: optional gzip, use ThreadPoolExecutor (#286)
sjfleming Jan 23, 2025
b3009d1
Address flaky mup test (#292)
sjfleming Jan 23, 2025
41f82a3
more inference code
mbabadi Jan 24, 2025
0531e87
predict keys
mbabadi Jan 24, 2025
a8400d3
gene network inference code
mbabadi Feb 1, 2025
2d4abb1
notebooks
mbabadi Feb 1, 2025
d11b7a1
Fix recent mypy errors (#298)
sjfleming Feb 4, 2025
ef5cdc8
Add to gitignore (#299)
sjfleming Feb 4, 2025
df6ae47
Merge branch 'cellarium-gpt-model' into cellarium-gpt-tokenizer
Feb 5, 2025
9a3fdf8
remove gradient clipping
Feb 5, 2025
e2bf797
Fix ipca (#289)
Feb 5, 2025
d031809
Cellarium gpt model (#279)
Feb 6, 2025
770a157
Add FSDP support (#301)
Feb 6, 2025
e4cdc46
merge main
Feb 7, 2025
d058d3d
refactoring + new notebook for linear response analysis
mbabadi Feb 7, 2025
db4ff02
bugfixes
mbabadi Feb 10, 2025
cf869af
linear response
mbabadi Feb 11, 2025
77d0900
a_qq -> a_pp
mbabadi Feb 13, 2025
15d9744
updated notebooks, new script
mbabadi Feb 15, 2025
75f98fe
tqdm auto
mbabadi Feb 15, 2025
ebb29aa
remove unused imports
mbabadi Feb 15, 2025
d606c6a
bash script for linear response analysis
mbabadi Feb 15, 2025
b369dc7
metadata benchmarking intro
mbabadi Feb 20, 2025
1701b63
metadata prediction CLI tool and script
mbabadi Feb 21, 2025
bf74d04
updated metadata prediction to support random prompt genes
mbabadi Feb 24, 2025
a998bb1
Add `CellariumModule.test_step` method for any custom inference (#304)
Feb 26, 2025
6bd85b7
test step
Feb 27, 2025
4300112
merge main
Feb 28, 2025
7c725df
fix stage
Feb 28, 2025
f737368
updates all around
mbabadi Feb 28, 2025
be707a0
new
mbabadi Feb 28, 2025
c7c5e54
updates to metadata prediction to include fixed genes
mbabadi Mar 2, 2025
6a4b5d0
foundry changes
mbabadi Mar 2, 2025
e1e2d00
Merge branch 'mb-cellarium-gpt-predict' of https://github.com/cellari…
mbabadi Mar 2, 2025
24d7a9f
foundry scripts
mbabadi Mar 2, 2025
f31534f
foundry scripts
mbabadi Mar 3, 2025
73a9d7d
prediction writer
Mar 9, 2025
6c08fb2
ontology notebooks
Mar 9, 2025
e79fe04
checkin activations work
nmallinar Mar 10, 2025
7296e06
bugfix in assay code
mbabadi Mar 11, 2025
2208279
update cellarium gpt inference context with assay id fix
nmallinar Mar 11, 2025
05e59af
latest
mbabadi Mar 12, 2025
add2cb7
post merge
mbabadi Mar 12, 2025
a7b215a
checkin
nmallinar Mar 12, 2025
33acecd
Merge branch 'nm-embeddings-sandbox' into mb-cellarium-gpt-predict
nmallinar Mar 12, 2025
5e0554f
updates for linear response analysis
mbabadi Mar 12, 2025
07896ed
small things
mbabadi Mar 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
strategy:
matrix:
python-version: ["3.10"]
devices: ["1", "2"]
devices: ["1", "2", "3"]

env:
TEST_DEVICES: ${{ matrix.devices }}
Expand All @@ -95,6 +95,30 @@ jobs:
- name: Test with pytest
run: make test

test-dataloader:

needs: [lint, mypy, docs]
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
devices: ["1", "2"]

env:
TEST_DEVICES: ${{ matrix.devices }}
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install .[test]
- name: Test dataloader
run: make test-dataloader

test-examples:

needs: [lint, mypy, docs]
Expand Down
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
__pycache__/
runs/
configs/
.ipynb_checkpoints
.mypy_cache/
.ruff_cache/
Expand All @@ -14,4 +15,10 @@ lightning_logs/
.idea/
build/
notebooks/.ipynb_checkpoints/
output/
output/
*.h5ad
*.csv
*.csv.gz
*.tsv
*.tsv.gz
*.ckpt
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,22 @@ typecheck: FORCE

test: FORCE
ifeq (${TEST_DEVICES}, 2)
pytest -v -k multi_device
pytest -v -k multi_device --ignore=tests/dataloader
else ifeq (${TEST_DEVICES}, 3)
pytest -v -k multi_device --ignore=tests/dataloader
else
# default
pytest -v
pytest -v --ignore=tests/dataloader
endif

test-dataloader: FORCE
ifeq (${TEST_DEVICES}, 2)
pytest -v -k multi_device tests/dataloader
else ifeq (${TEST_DEVICES}, 3)
pytest -v -k multi_device tests/dataloader
else
# default
pytest -v tests/dataloader
endif

test-examples: FORCE
Expand Down
142 changes: 99 additions & 43 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,67 +1,123 @@
*Cellarium ML: distributed single-cell data analysis.*
.. image:: https://cellarium.ai/wp-content/uploads/2024/07/cellarium-logo-medium.png
:alt: Cellarium Logo
:width: 180
:align: center

---------
**Cellarium ML: a machine learning framework for single-cell biology**
======================================================================

Cellarium ML is a PyTorch Lightning-based library for distributed single-cell data analysis.
It provides a set of tools for training deep learning models on large-scale single-cell datasets,
including distributed data loading, model training, and evaluation. Cellarium ML is designed to be
modular and extensible, allowing users to easily define custom models, data transformations,
It provides tools for training deep learning models on large-scale single-cell datasets,
including distributed data loading, model training, and evaluation. Designed to be modular
and extensible, Cellarium ML allows users to easily define custom models, data transformations,
and training pipelines.

Code organization
-----------------
-------------------------------------------------------------------------------

**Code Organization**
----------------------

The code is organized as follows:

- ``cellarium/ml/callbacks``: Contains custom PyTorch Lightning callbacks.
- ``cellarium/ml/core``: Includes essential Cellarium ML components:
- ``CellariumModule``: A PyTorch Lightning Module tasked with defining and configuring the model, training step, and optimizer.
- ``CellariumAnnDataDataModule``: A PyTorch Lightning DataModule designed for setting up a multi-GPU DataLoader for a collection of AnnData objects.
- ``CellariumPipeline``: A Module List that pipes the input data through a series of transforms and a model.
- ``cellarium/ml/data``: Contains Distributed AnnData Collection and multi-GPU Iterable Dataset implementations.
- ``cellarium/ml/lr_schedulers``: Contains custom learning rate schedulers.
- ``cellarium/ml/models``: Features Cellarium ML models:
- Models must subclass ``CellariumModel`` and implement the ``.reset_parameters`` method.
- The ``.forward`` method should return a dictionary containing the computed loss under the ``loss`` key.
- Optionally, hooks such as ``.on_train_start``, ``.on_train_epoch_end``, and ``.on_train_batch_end`` can be implemented to be triggered by the ``CellariumModule`` during training phases.
- ``cellarium/ml/preprocessing``: Provides pre-processing functions.
- ``cellarium/ml/transforms``: Contains data transformation modules:
- Each transform is a subclass of ``torch.nn.Module``.
- The ``.forward`` method should output a dictionary where the keys correspond to the input arguments of subsequent transforms and the model.
- ``cellarium/ml/utilities``: Contains utility functions for various submodules.
- ``cellarium/ml/cli.py``: Implements the ``cellarium-ml`` CLI. Models must be registered here to be accessible via the CLI.
.. code-block:: text

cellarium/
└── ml/
├── "callbacks" # Custom PyTorch Lightning callbacks
├── "core" # Essential components
│ ├── "CellariumModule" # PyTorch Lightning Module for model, training step, and optimizer
│ ├── "CellariumAnnDataDataModule" # DataModule for multi-GPU DataLoader for AnnData objects
│ └── "CellariumPipeline" # Pipeline for data transformations and model inference
├── "data" # Distributed AnnData Collection and multi-GPU Iterable Datasets
├── "lr_schedulers" # Custom learning rate schedulers
├── "models" # Cellarium ML models
├── "preprocessing" # Pre-processing functions
├── "transforms" # Data transformation modules
├── "utilities" # Utility functions for various submodules
└── "cli.py" # Implements the "cellarium-ml" CLI. Models must be registered here

Important Notes
~~~~~~~~~~~~~~~

``cellarium/ml/models/*``
~~~~~~~~~~~~~~~~~~~~~~~~~

- Models must subclass ``CellariumModel`` and implement the following:
- ``reset_parameters``: Initializes model parameters.
- ``forward``: Returns a dictionary containing the computed loss under the ``loss`` key.

Optional hooks for training include:

- ``on_train_start``: Called at the start of training.
- ``on_train_epoch_end``: Triggered at the end of each epoch.
- ``on_train_batch_end``: Triggered at the end of each batch.

``cellarium/ml/transforms/*``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- All transforms must subclass ``torch.nn.Module``.
- The ``forward`` method must output a dictionary where keys correspond to the input arguments for subsequent transforms or the model.

``cellarium/ml/cli.py``
~~~~~~~~~~~~~~~~~~~~~~~
- Models must be registered here to be accessible via the command-line interface (``cellarium-ml`` CLI).



-------------------------------------------------------------------------------

**Installation**
-----------------

To install via pip:

.. code-block:: bash

pip install cellarium-ml

To install the developer version from source:

.. code-block:: bash

git clone https://github.com/cellarium-ai/cellarium-ml.git
cd cellarium-ml
make install # runs pip install -e .[dev]

Installation
------------
**API Documentation and Tutorials**
-----------------------------------

To install from the pip::
For detailed API documentation and tutorials, visit:
`Cellarium ML Documentation <https://cellarium-ai.github.io/cellarium-ml/>`_

$ pip install cellarium-ml
-------------------------------------------------------------------------------

To install the developer version from the source::
**For Developers**
-------------------

$ git clone https://github.com/cellarium-ai/cellarium-ml.git
$ cd cellarium-ml
$ make install # runs pip install -e .[dev]
To run the tests:

For developers
--------------
.. code-block:: bash

To run the tests::
make test-examples # runs single-device cli example tests
make test-dataloader # runs single-device dataloader related tests
TEST_DEVICES=2 make test-dataloader # runs multi-device dataloader related test
make test # runs single-device (all other) tests
TEST_DEVICES=2 make test # runs multi-device (all other) tests

$ make test # runs single-device tests
$ TEST_DEVICES=2 make test # runs multi-device tests
To format the code automatically:

To automatically format the code::
.. code-block:: bash

$ make format # runs ruff formatter and fixes linter errors
make format # runs ruff formatter and fixes linter errors

To run the linters::
To run the linters:

$ make lint # runs ruff linter and checks for formatter errors
.. code-block:: bash

To build the documentation::
make lint # runs ruff linter and checks for formatter errors

$ make docs # builds the documentation at docs/build/html
To build the documentation:

.. code-block:: bash

make docs # builds the documentation at docs/build/html
4 changes: 3 additions & 1 deletion cellarium/ml/callbacks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Copyright Contributors to the Cellarium project.
# SPDX-License-Identifier: BSD-3-Clause

from cellarium.ml.callbacks.compute_norm import ComputeNorm
from cellarium.ml.callbacks.get_coord_data import GetCoordData
from cellarium.ml.callbacks.loss_scale_monitor import LossScaleMonitor
from cellarium.ml.callbacks.prediction_writer import PredictionWriter
from cellarium.ml.callbacks.variance_monitor import VarianceMonitor

__all__ = ["LossScaleMonitor", "PredictionWriter", "VarianceMonitor"]
__all__ = ["ComputeNorm", "GetCoordData", "LossScaleMonitor", "PredictionWriter", "VarianceMonitor"]
Loading