From 15e360c569084b991acf69d2e203e858efdc8bc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Sat, 10 Oct 2020 14:14:29 +0200 Subject: [PATCH 1/4] Fix compatibility with different versions of wandb when sweeping. --- .../classification/classification_model.py | 3 ++- .../classification/multi_label_classification_model.py | 3 ++- .../classification/multi_modal_classification_model.py | 3 ++- simpletransformers/config/utils.py | 9 +++++++++ simpletransformers/conv_ai/conv_ai_model.py | 3 ++- .../language_generation/language_generation_model.py | 3 ++- .../language_modeling/language_modeling_model.py | 3 ++- .../language_representation/representation_model.py | 3 ++- simpletransformers/ner/ner_model.py | 3 ++- .../question_answering/question_answering_model.py | 3 ++- simpletransformers/seq2seq/seq2seq_model.py | 3 ++- simpletransformers/t5/t5_model.py | 3 ++- 12 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 simpletransformers/config/utils.py diff --git a/simpletransformers/classification/classification_model.py b/simpletransformers/classification/classification_model.py index 7a1497c8..d104c887 100755 --- a/simpletransformers/classification/classification_model.py +++ b/simpletransformers/classification/classification_model.py @@ -80,6 +80,7 @@ from simpletransformers.classification.transformer_models.xlnet_model import XLNetForSequenceClassification from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import ClassificationArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.custom_models.models import ElectraForSequenceClassification try: @@ -149,7 +150,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/classification/multi_label_classification_model.py b/simpletransformers/classification/multi_label_classification_model.py index d14a7bbe..90b6169d 100755 --- a/simpletransformers/classification/multi_label_classification_model.py +++ b/simpletransformers/classification/multi_label_classification_model.py @@ -33,6 +33,7 @@ from simpletransformers.classification import ClassificationModel from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import MultiLabelClassificationArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.custom_models.models import ( AlbertForMultiLabelSequenceClassification, BertForMultiLabelSequenceClassification, @@ -108,7 +109,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/classification/multi_modal_classification_model.py b/simpletransformers/classification/multi_modal_classification_model.py index 2f88ffd1..10d6e6ac 100644 --- a/simpletransformers/classification/multi_modal_classification_model.py +++ b/simpletransformers/classification/multi_modal_classification_model.py @@ -49,6 +49,7 @@ from simpletransformers.classification.transformer_models.mmbt_model import MMBTForClassification from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import MultiModalClassificationArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values try: import wandb @@ -105,7 +106,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/config/utils.py b/simpletransformers/config/utils.py new file mode 100644 index 00000000..a00f8d0b --- /dev/null +++ b/simpletransformers/config/utils.py @@ -0,0 +1,9 @@ +def sweep_config_to_sweep_values(sweep_config): + """ + Converts an instance of wandb.Config to plain values map. + + wandb.Config varies across versions quite significantly, + so we use the `keys` method that works consistently. + """ + + return {key: sweep_config[key] for key in sweep_config.keys()} diff --git a/simpletransformers/conv_ai/conv_ai_model.py b/simpletransformers/conv_ai/conv_ai_model.py index 4b0becbe..e45a36e0 100644 --- a/simpletransformers/conv_ai/conv_ai_model.py +++ b/simpletransformers/conv_ai/conv_ai_model.py @@ -47,6 +47,7 @@ from simpletransformers.classification.classification_utils import InputExample, convert_examples_to_features from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import ConvAIArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.conv_ai.conv_ai_utils import get_dataset try: @@ -100,7 +101,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/language_generation/language_generation_model.py b/simpletransformers/language_generation/language_generation_model.py index 67f3865b..08fb5841 100644 --- a/simpletransformers/language_generation/language_generation_model.py +++ b/simpletransformers/language_generation/language_generation_model.py @@ -29,6 +29,7 @@ from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import LanguageGenerationArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.language_generation.language_generation_utils import PREPROCESSING_FUNCTIONS logger = logging.getLogger(__name__) @@ -71,7 +72,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/language_modeling/language_modeling_model.py b/simpletransformers/language_modeling/language_modeling_model.py index c411f3b7..3ae66ec8 100755 --- a/simpletransformers/language_modeling/language_modeling_model.py +++ b/simpletransformers/language_modeling/language_modeling_model.py @@ -69,6 +69,7 @@ from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import LanguageModelingArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.custom_models.models import ElectraForLanguageModelingModel from simpletransformers.language_modeling.language_modeling_utils import SimpleDataset, mask_tokens @@ -132,7 +133,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/language_representation/representation_model.py b/simpletransformers/language_representation/representation_model.py index 7452f6e5..d6cf1b3e 100644 --- a/simpletransformers/language_representation/representation_model.py +++ b/simpletransformers/language_representation/representation_model.py @@ -13,6 +13,7 @@ from transformers import BertConfig, BertTokenizer, GPT2Config, GPT2Tokenizer, RobertaConfig, RobertaTokenizer from simpletransformers.config.model_args import ModelArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.language_representation.transformer_models.bert_model import BertForTextRepresentation from simpletransformers.language_representation.transformer_models.gpt2_model import GPT2ForTextRepresentation @@ -73,7 +74,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/ner/ner_model.py b/simpletransformers/ner/ner_model.py index 03f11b27..04cbee2d 100755 --- a/simpletransformers/ner/ner_model.py +++ b/simpletransformers/ner/ner_model.py @@ -60,6 +60,7 @@ from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import NERArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.ner.ner_utils import ( InputExample, LazyNERDataset, @@ -125,7 +126,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/question_answering/question_answering_model.py b/simpletransformers/question_answering/question_answering_model.py index 0be38d4b..582e6c1c 100755 --- a/simpletransformers/question_answering/question_answering_model.py +++ b/simpletransformers/question_answering/question_answering_model.py @@ -65,6 +65,7 @@ from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import QuestionAnsweringArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.custom_models.models import ElectraForQuestionAnswering, XLMRobertaForQuestionAnswering from simpletransformers.question_answering.question_answering_utils import ( LazyQuestionAnsweringDataset, @@ -131,7 +132,7 @@ def __init__(self, model_type, model_name, args=None, use_cuda=True, cuda_device if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/seq2seq/seq2seq_model.py b/simpletransformers/seq2seq/seq2seq_model.py index 33846a10..d22f5c9b 100644 --- a/simpletransformers/seq2seq/seq2seq_model.py +++ b/simpletransformers/seq2seq/seq2seq_model.py @@ -58,6 +58,7 @@ from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import Seq2SeqArgs +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.seq2seq.seq2seq_utils import Seq2SeqDataset, SimpleSummarizationDataset try: @@ -139,7 +140,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: diff --git a/simpletransformers/t5/t5_model.py b/simpletransformers/t5/t5_model.py index b23cee5c..9696ede0 100644 --- a/simpletransformers/t5/t5_model.py +++ b/simpletransformers/t5/t5_model.py @@ -21,6 +21,7 @@ from simpletransformers.config.global_args import global_args from simpletransformers.config.model_args import T5Args +from simpletransformers.config.utils import sweep_config_to_sweep_values from simpletransformers.t5.t5_utils import T5Dataset try: @@ -64,7 +65,7 @@ def __init__( if "sweep_config" in kwargs: sweep_config = kwargs.pop("sweep_config") - sweep_values = {key: value["value"] for key, value in sweep_config.as_dict().items() if key != "_wandb"} + sweep_values = sweep_config_to_sweep_values(sweep_config) self.args.update_from_dict(sweep_values) if self.args.manual_seed: From 771b41b20f1a46b1fc4d54fd1fb984629de062ac Mon Sep 17 00:00:00 2001 From: Thilina Rajapakse Date: Mon, 12 Oct 2020 14:26:15 +0530 Subject: [PATCH 2/4] Fixed compatibility issues with W&B Sweeps --- CHANGELOG.md | 10 +++++++++- setup.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb234d09..c5c0ecb5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.48.12] - 2020-10-11 + +### Fixed + +- Fixed compatibility issues with W&B Sweeps. [jonatanklosko](https://github.com/jonatanklosko) + ## [0.48.11] - 2020-10-11 ### Changed @@ -1180,7 +1186,9 @@ Model checkpoint is now saved for all epochs again. - This CHANGELOG file to hopefully serve as an evolving example of a standardized open source project CHANGELOG. -[0.48.11]: https://github.com/ThilinaRajapakse/simpletransformers/compare/1b59118...HEAD +[0.48.12]: https://github.com/ThilinaRajapakse/simpletransformers/compare/b908bb5...HEAD + +[0.48.11]: https://github.com/ThilinaRajapakse/simpletransformers/compare/1b59118...b908bb5 [0.48.10]: https://github.com/ThilinaRajapakse/simpletransformers/compare/6370a1b...1b59118 diff --git a/setup.py b/setup.py index 89e33bd3..e7f3efcf 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="simpletransformers", - version="0.48.11", + version="0.48.12", author="Thilina Rajapakse", author_email="chaturangarajapakshe@gmail.com", description="An easy-to-use wrapper library for the Transformers library.", From 564d9f80cea4cd39be9c8bc294e318a8686c079e Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 08:56:58 +0000 Subject: [PATCH 3/4] docs: update README.md [skip ci] --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 565826f6..900d98a6 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) [![Downloads](https://pepy.tech/badge/simpletransformers)](https://pepy.tech/project/simpletransformers) -[![All Contributors](https://img.shields.io/badge/all_contributors-48-orange.svg?style=flat-square)](#contributors-) +[![All Contributors](https://img.shields.io/badge/all_contributors-49-orange.svg?style=flat-square)](#contributors-) # Simple Transformers @@ -3348,7 +3348,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Yann Defretin

💻 📖 💬 🤔 -
Manuel

📖 💻 +
Manuel

📖 💻
Gilles Jacobs

📖
shasha79

💻
Mercedes Garcia

💻 @@ -3399,6 +3399,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Alex

💻
Karthik Ganesan

💻
Zhylko Dima

💻 +
Jonatan KÅ‚osko

💻 From 87d5a7c4e6b393991d0eccb8b0298e4e54054727 Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 08:56:59 +0000 Subject: [PATCH 4/4] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index b6a151e6..adf45231 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -451,6 +451,15 @@ "contributions": [ "code" ] + }, + { + "login": "jonatanklosko", + "name": "Jonatan Kłosko", + "avatar_url": "https://avatars1.githubusercontent.com/u/17034772?v=4", + "profile": "https://jonatanklosko.com", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7,