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

Transformers #82

Merged
merged 3 commits into from
Sep 23, 2023
Merged
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
22 changes: 15 additions & 7 deletions molfeat/trans/pretrained/hf_transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@

from dataclasses import dataclass
from loguru import logger
from transformers import EncoderDecoderModel
from transformers import AutoTokenizer
from transformers import AutoModel
from transformers import AutoConfig
from transformers import MODEL_MAPPING
from transformers import PreTrainedModel
from transformers import PreTrainedTokenizer, PreTrainedTokenizerFast
from molfeat.utils import requires
from molfeat.trans.pretrained.base import PretrainedMolTransformer
from molfeat.store.loader import PretrainedStoreModel
from molfeat.store import ModelStore
from molfeat.store import ModelInfo
from molfeat.utils.converters import SmilesConverter
from molfeat.utils.pooler import get_default_hgf_pooler

if requires.check("transformers"):
from transformers import EncoderDecoderModel
from transformers import AutoTokenizer
from transformers import AutoModel
from transformers import AutoConfig
from transformers import MODEL_MAPPING
from transformers import PreTrainedModel
from transformers import PreTrainedTokenizer, PreTrainedTokenizerFast


@dataclass
class HFExperiment:
Expand Down Expand Up @@ -260,6 +263,11 @@ def __init__(
random_seed: random seed to use for reproducibility whenever a DNN pooler is used (e.g bert/roberta)
"""

if not requires.check("transformers"):
raise ValueError(
"Cannot find transformers and/or tokenizers. It's required for this featurizer !"
)

super().__init__(
dtype=dtype,
device=device,
Expand Down
4 changes: 3 additions & 1 deletion tests/test_pretrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def test_dgl_pretrained_cache(self):
# add buffers
self.assertLessEqual(cached_run, ori_run + time_buffer)


@pytest.mark.xfail(
not requires.check("transformers"), reason="3rd party module transformers is missing"
)
class TestHGFTransformer(ut.TestCase):
r"""Test cases for FingerprintsTransformer"""
smiles = [
Expand Down
Loading