From ef0f22b4a423211465ca2c8bc763d5e8d31eb681 Mon Sep 17 00:00:00 2001 From: vela Date: Sat, 2 Dec 2023 00:16:11 +0900 Subject: [PATCH 1/5] fix for transformers 4.35.2 --- detoxify/detoxify.py | 7 ++++--- setup.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/detoxify/detoxify.py b/detoxify/detoxify.py index 92fe0c9..d964b86 100644 --- a/detoxify/detoxify.py +++ b/detoxify/detoxify.py @@ -1,4 +1,5 @@ import torch +from transformers import PreTrainedModel, AutoConfig, BertForSequenceClassification import transformers DOWNLOAD_URL = "https://github.com/unitaryai/detoxify/releases/download/" @@ -12,15 +13,15 @@ PRETRAINED_MODEL = None - def get_model_and_tokenizer( model_type, model_name, tokenizer_name, num_classes, state_dict, huggingface_config_path=None ): model_class = getattr(transformers, model_name) + config = AutoConfig.from_pretrained(model_type) + config.num_labels = num_classes model = model_class.from_pretrained( pretrained_model_name_or_path=None, - config=huggingface_config_path or model_type, - num_labels=num_classes, + config=huggingface_config_path or config, state_dict=state_dict, local_files_only=huggingface_config_path is not None, ) diff --git a/setup.py b/setup.py index 722a8db..8dee5a1 100644 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ author_email="laura@unitary.ai", url="https://github.com/unitaryai/detoxify", install_requires=[ - "transformers == 4.30.0", + "transformers", "torch >= 1.7.0", "sentencepiece >= 0.1.94", ], From 0b3746ef1c56ce8eefa18b074ba86de11e21159f Mon Sep 17 00:00:00 2001 From: vela Date: Sat, 2 Dec 2023 00:17:37 +0900 Subject: [PATCH 2/5] remove useless import --- detoxify/detoxify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detoxify/detoxify.py b/detoxify/detoxify.py index d964b86..801b972 100644 --- a/detoxify/detoxify.py +++ b/detoxify/detoxify.py @@ -1,5 +1,5 @@ import torch -from transformers import PreTrainedModel, AutoConfig, BertForSequenceClassification +from transformers import AutoConfig import transformers DOWNLOAD_URL = "https://github.com/unitaryai/detoxify/releases/download/" From 4e654a50affb05d5a8de5ea8034ef23bc81ba26a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:19:33 +0000 Subject: [PATCH 3/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- detoxify/detoxify.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/detoxify/detoxify.py b/detoxify/detoxify.py index d964b86..4df3bd9 100644 --- a/detoxify/detoxify.py +++ b/detoxify/detoxify.py @@ -1,6 +1,6 @@ import torch -from transformers import PreTrainedModel, AutoConfig, BertForSequenceClassification import transformers +from transformers import AutoConfig, BertForSequenceClassification, PreTrainedModel DOWNLOAD_URL = "https://github.com/unitaryai/detoxify/releases/download/" MODEL_URLS = { @@ -13,6 +13,7 @@ PRETRAINED_MODEL = None + def get_model_and_tokenizer( model_type, model_name, tokenizer_name, num_classes, state_dict, huggingface_config_path=None ): From 82bee4e58a2014e7d85b1a1961daf35b1c492f5a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 1 Dec 2023 15:24:51 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- detoxify/detoxify.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/detoxify/detoxify.py b/detoxify/detoxify.py index db6d10e..4a25dca 100644 --- a/detoxify/detoxify.py +++ b/detoxify/detoxify.py @@ -1,6 +1,6 @@ import torch -from transformers import AutoConfig import transformers +from transformers import AutoConfig DOWNLOAD_URL = "https://github.com/unitaryai/detoxify/releases/download/" From febc4aaf82cad76685b17745823a553d1c7ff482 Mon Sep 17 00:00:00 2001 From: Vela-zz <59645193+Vela-zz@users.noreply.github.com> Date: Sat, 2 Dec 2023 02:08:04 +0900 Subject: [PATCH 5/5] Update detoxify.py align action with transformers --- detoxify/detoxify.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/detoxify/detoxify.py b/detoxify/detoxify.py index 4a25dca..5837348 100644 --- a/detoxify/detoxify.py +++ b/detoxify/detoxify.py @@ -1,6 +1,5 @@ import torch import transformers -from transformers import AutoConfig DOWNLOAD_URL = "https://github.com/unitaryai/detoxify/releases/download/" @@ -19,8 +18,7 @@ def get_model_and_tokenizer( model_type, model_name, tokenizer_name, num_classes, state_dict, huggingface_config_path=None ): model_class = getattr(transformers, model_name) - config = AutoConfig.from_pretrained(model_type) - config.num_labels = num_classes + config = model_class.config_class.from_pretrained(model_type, num_labels=num_classes) model = model_class.from_pretrained( pretrained_model_name_or_path=None, config=huggingface_config_path or config,