diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index e7df7e1..622cb32 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -5,38 +5,38 @@ name: Python package on: push: - branches: [ "main" ] + branches: ["main"] pull_request: - branches: [ "main" ] + branches: ["main"] jobs: build: - runs-on: ubuntu-latest strategy: fail-fast: false matrix: - python-version: ["3.9", "3.11", "3.13"] + python-version: ["3.10", "3.12", "3.13"] steps: - - uses: actions/checkout@v6 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v6 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install flake8 pytest sentencepiece rdkit - python -m pip install git+https://github.com/novonordisk-research/pepfunn.git - python -m pip install . - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - pytest + - uses: actions/checkout@v6 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v6 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install uv + uv pip install flake8 pytest sentencepiece rdkit --system + uv pip install git+https://github.com/novonordisk-research/pepfunn.git --system + uv pip install . "transformers<5" --system + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + # flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/autopeptideml/reps/lms.py b/autopeptideml/reps/lms.py index ee9b2a5..8bf9abe 100644 --- a/autopeptideml/reps/lms.py +++ b/autopeptideml/reps/lms.py @@ -4,9 +4,11 @@ os.environ['TOKENIZERS_PARALLELISM'] = 'False' import numpy as np +from packaging.version import parse as V import torch import transformers from transformers import AutoModel, AutoTokenizer, T5Tokenizer, T5EncoderModel + from typing import * from .engine import RepEngineBase @@ -200,7 +202,8 @@ def _load_model(self, model: str): elif 'ankh' in model.lower(): self.lab = 'ElnaggarLab' elif 'molformer' in model.lower(): - print("Warning: Molformer does not support transformers>=5.0.0, we recommend using an earlier version, e.g., transformers==4.41.2") + if V(transformers.__version__) >= V('5.0.0'): + print("Warning: Molformer does not support transformers>=5.0.0, we recommend using an earlier version, e.g., transformers==4.41.2") self.lab = 'ibm' elif 'chemberta' in model.lower(): self.lab = 'DeepChem' diff --git a/tests/test_reps.py b/tests/test_reps.py index d263045..0bab611 100644 --- a/tests/test_reps.py +++ b/tests/test_reps.py @@ -53,6 +53,13 @@ def test_rostlab_family(): assert np.array(a).shape == (1, re.dim()) +def test_molformer_family(): + re = RepEngineLM('molformer-xl') + a = re.compute_reps(['C[C@H](N)C(=O)N[C@@H](CCCNC(=N)N)C(=O)N[C@H]'], batch_size=12) + assert re.dim() == 768 + assert np.array(a).shape == (1, re.dim()) + + if __name__ == '__main__': test_esm_family() print('ESM OK')