-
Notifications
You must be signed in to change notification settings - Fork 7
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 #98 from helicalAI/fix-scGPT-fine-tuning
Fix Weight Scrambling in scGPT
- Loading branch information
Showing
9 changed files
with
306 additions
and
191 deletions.
There are no files selected for viewing
File renamed without changes.
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,52 @@ | ||
import pytest | ||
import numpy as np | ||
from datasets import Dataset, Features, Value, Sequence | ||
from helical.utils import get_anndata_from_hf_dataset | ||
|
||
def create_mock_dataset(gene_names: str): | ||
data = { | ||
'raw_counts': [ | ||
[1, 2, 3, 2], | ||
[98], | ||
[72, 19] | ||
], | ||
'rows': [ | ||
[0, 1, 2, 3], | ||
[0], | ||
[1, 3] | ||
], | ||
'obs1': [10, 20, 30], | ||
'obs2': [40, 50, 60], | ||
'size': [4, 4, 4] | ||
} | ||
features = Features({ | ||
'raw_counts': Sequence(Value('uint32'), -1, gene_names), | ||
'rows': Sequence(Value('uint32')), | ||
'obs1': Value('int64'), | ||
'obs2': Value('int64'), | ||
'size': Value('uint32') | ||
}) | ||
dataset = Dataset.from_dict(data, features=features) | ||
return dataset | ||
|
||
def test_get_anndata_from_hf_dataset(): | ||
dataset = create_mock_dataset("gene1,gene2,gene3,gene4") | ||
ann_data = get_anndata_from_hf_dataset(dataset) | ||
|
||
assert ann_data.shape == (3, 4) | ||
|
||
# assert that observation names are correct (ie. no 'rows', 'raw_counts', or 'size') | ||
assert list(ann_data.obs.columns) == ['obs1', 'obs2'] | ||
|
||
# assert that gene names are converted to uppercase | ||
assert list(ann_data.var_names) == ['GENE1', 'GENE2', 'GENE3', 'GENE4'] | ||
assert list(ann_data.var['gene_name']) == ['GENE1', 'GENE2', 'GENE3', 'GENE4'] | ||
|
||
# assert that counts are placed in the correct positions | ||
assert np.array_equal(ann_data.X.toarray(), np.array([[1, 2, 3, 2], [98, 0, 0, 0], [0, 72, 0, 19]])) | ||
|
||
def test_get_anndata_from_hf_dataset_mismatched_gene_names(): | ||
dataset = create_mock_dataset("gene1,gene2") | ||
|
||
with pytest.raises(ValueError): | ||
get_anndata_from_hf_dataset(dataset) |
File renamed without changes.
328 changes: 191 additions & 137 deletions
328
examples/notebooks/Cell-Type-Classification-Fine-Tuning.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -163,4 +163,8 @@ def forward(): | |
|
||
@abstractmethod | ||
def train(): | ||
pass | ||
|
||
@abstractmethod | ||
def get_outputs(): | ||
pass |
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
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