Skip to content
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

feat: add model.json to package data #72

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -182,3 +182,6 @@ lightning_logs/

# Test resources
tests/instanovo_test_resources*

# Notebook output
notebooks/predictions_kbs.csv
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
recursive-include instanovo/configs *.yaml
include instanovo/models.json
2 changes: 1 addition & 1 deletion instanovo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from __future__ import annotations

__version__ = "1.0.1"
__version__ = "1.0.2"
6 changes: 3 additions & 3 deletions instanovo/transformer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from omegaconf import DictConfig
from torch import nn
from torch import Tensor
from importlib import resources

from instanovo.constants import MAX_SEQUENCE_LENGTH
from instanovo.transformer.layers import ConvPeakEmbedding
Expand All @@ -33,7 +34,6 @@
from instanovo.types import SpectrumMask
from instanovo.utils import ResidueSet

MODELS_PATH = Path(__file__).parent.parent / "models.json"
MODEL_TYPE = "transformer"


Expand Down Expand Up @@ -126,7 +126,7 @@ def _get_causal_mask(seq_len: int, return_float: bool = False) -> PeptideMask:
def get_pretrained() -> list[str]:
"""Get a list of pretrained model ids."""
# Load the models.json file
with open(MODELS_PATH, "r") as f:
with resources.open_text("instanovo", "models.json") as f:
models_config = json.load(f)

if MODEL_TYPE not in models_config:
Expand Down Expand Up @@ -177,7 +177,7 @@ def from_pretrained(cls, model_id: str) -> Tuple["InstaNovo", "DictConfig"]:
raise FileNotFoundError(f"No file found at path: {model_id}")

# Load the models.json file
with open(MODELS_PATH, "r") as f:
with resources.open_text("instanovo", "models.json") as f:
models_config = json.load(f)

# Find the model in the config
Expand Down
16 changes: 10 additions & 6 deletions notebooks/getting_started_with_instanovo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
},
"outputs": [],
"source": [
"!pip install instanovo"
"!pip install instanovo \"torch<2.5\""
]
},
{
Expand All @@ -110,7 +110,9 @@
"import numpy as np\n",
"import pandas as pd\n",
"import urllib.request\n",
"import zipfile"
"import zipfile\n",
"\n",
"os.environ[\"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION\"] = \"python\""
]
},
{
Expand Down Expand Up @@ -698,7 +700,8 @@
"metadata": {},
"outputs": [],
"source": [
"!pip uninstall -y instanovo && pip install instanovo==0.1.7"
"!pip uninstall -y instanovo && pip install \"instanovo==0.1.7\"\n",
"!pip install 'protobuf<3.20' tensorboard --force-reinstall"
]
},
{
Expand All @@ -711,7 +714,8 @@
"from datasets import load_dataset\n",
"\n",
"# Only evaluate on a subset of the data for demo\n",
"dataset = load_dataset(\"InstaDeepAI/ms_ninespecies_benchmark\", split=\"test[:1%]\")"
"dataset = load_dataset(\"InstaDeepAI/ms_ninespecies_benchmark\", split=\"test[:1%]\")\n",
"dataset"
]
},
{
Expand Down Expand Up @@ -922,7 +926,7 @@
"provenance": []
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "instanovo",
"language": "python",
"name": "python3"
},
Expand All @@ -936,7 +940,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.10.14"
}
},
"nbformat": 4,
Expand Down
Loading