From 9b8413306bdac45a5bd1255d56904db0826f9f2b Mon Sep 17 00:00:00 2001 From: Joppe Geluykens Date: Wed, 3 Aug 2022 15:54:05 +0000 Subject: [PATCH 1/4] overwrite eval_batch_size on GBM schema Overwritten here to provide a default value. In many places, we fall back to eval_batch_size if batch_size is not specified. GBM does not have a value for batch_size, so we need to specify eval_batch_size here. --- ludwig/schema/trainer.py | 13 +++++++++++++ ludwig/trainers/trainer_lightgbm.py | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ludwig/schema/trainer.py b/ludwig/schema/trainer.py index 2932e775157..e025634be42 100644 --- a/ludwig/schema/trainer.py +++ b/ludwig/schema/trainer.py @@ -312,6 +312,19 @@ class GBMTrainerConfig(BaseTrainerConfig): allow_none=False, ) + # NOTE: Overwritten here to provide a default value. In many places, we fall back to eval_batch_size if batch_size + # is not specified. GBM does not have a value for batch_size, so we need to specify eval_batch_size here. + eval_batch_size: Union[None, int, str] = schema_utils.IntegerOrAutoField( + default=128, + allow_none=False, + min_exclusive=0, + description=( + "Size of batch to pass to the model for evaluation. " + "If ’auto’, the biggest batch size (power of 2) that can fit in memory will be used." + ), + parameter_metadata=TRAINER_METADATA["eval_batch_size"], + ) + # LightGBM core parameters (https://lightgbm.readthedocs.io/en/latest/Parameters.html) boosting_type: str = schema_utils.StringOptions( ["gbdt", "rf", "dart", "goss"], diff --git a/ludwig/trainers/trainer_lightgbm.py b/ludwig/trainers/trainer_lightgbm.py index 0a4c9add2e3..89f3bfc4fed 100644 --- a/ludwig/trainers/trainer_lightgbm.py +++ b/ludwig/trainers/trainer_lightgbm.py @@ -63,7 +63,7 @@ def __init__( self.skip_save_progress = skip_save_progress self.skip_save_model = skip_save_model - self.eval_batch_size = config.eval_batch_size or 128 + self.eval_batch_size = config.eval_batch_size self._validation_field = config.validation_field self._validation_metric = config.validation_metric self.evaluate_training_set = config.evaluate_training_set From 3fa6bdf637295c20aa9739562b81ca1d1b546bdd Mon Sep 17 00:00:00 2001 From: Joppe Geluykens Date: Wed, 3 Aug 2022 16:11:22 +0000 Subject: [PATCH 2/4] default to "auto" --- ludwig/schema/trainer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ludwig/schema/trainer.py b/ludwig/schema/trainer.py index e025634be42..eac756f8abe 100644 --- a/ludwig/schema/trainer.py +++ b/ludwig/schema/trainer.py @@ -3,7 +3,7 @@ from marshmallow_dataclass import dataclass -from ludwig.constants import COMBINED, LOSS, MODEL_ECD, MODEL_GBM, TRAINING, TYPE +from ludwig.constants import AUTO, COMBINED, LOSS, MODEL_ECD, MODEL_GBM, TRAINING, TYPE from ludwig.schema import utils as schema_utils from ludwig.schema.metadata.trainer_metadata import TRAINER_METADATA from ludwig.schema.optimizers import ( @@ -315,12 +315,12 @@ class GBMTrainerConfig(BaseTrainerConfig): # NOTE: Overwritten here to provide a default value. In many places, we fall back to eval_batch_size if batch_size # is not specified. GBM does not have a value for batch_size, so we need to specify eval_batch_size here. eval_batch_size: Union[None, int, str] = schema_utils.IntegerOrAutoField( - default=128, + default=AUTO, allow_none=False, min_exclusive=0, description=( "Size of batch to pass to the model for evaluation. " - "If ’auto’, the biggest batch size (power of 2) that can fit in memory will be used." + "Defaults to 'auto': the biggest batch size (power of 2) that can fit in memory will be used." ), parameter_metadata=TRAINER_METADATA["eval_batch_size"], ) From 3e5745a0f53b51ee3a8524c9bd68bee4cc8644bd Mon Sep 17 00:00:00 2001 From: Joppe Geluykens Date: Wed, 3 Aug 2022 19:38:45 +0000 Subject: [PATCH 3/4] revert to 128 since auto is not implemented for GBM --- ludwig/schema/trainer.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/ludwig/schema/trainer.py b/ludwig/schema/trainer.py index eac756f8abe..cd1e2d4a7bf 100644 --- a/ludwig/schema/trainer.py +++ b/ludwig/schema/trainer.py @@ -3,7 +3,7 @@ from marshmallow_dataclass import dataclass -from ludwig.constants import AUTO, COMBINED, LOSS, MODEL_ECD, MODEL_GBM, TRAINING, TYPE +from ludwig.constants import COMBINED, LOSS, MODEL_ECD, MODEL_GBM, TRAINING, TYPE from ludwig.schema import utils as schema_utils from ludwig.schema.metadata.trainer_metadata import TRAINER_METADATA from ludwig.schema.optimizers import ( @@ -315,13 +315,10 @@ class GBMTrainerConfig(BaseTrainerConfig): # NOTE: Overwritten here to provide a default value. In many places, we fall back to eval_batch_size if batch_size # is not specified. GBM does not have a value for batch_size, so we need to specify eval_batch_size here. eval_batch_size: Union[None, int, str] = schema_utils.IntegerOrAutoField( - default=AUTO, + default=128, allow_none=False, min_exclusive=0, - description=( - "Size of batch to pass to the model for evaluation. " - "Defaults to 'auto': the biggest batch size (power of 2) that can fit in memory will be used." - ), + description=("Size of batch to pass to the model for evaluation."), parameter_metadata=TRAINER_METADATA["eval_batch_size"], ) From 8a74c300152c804c9e25cc75fa03ff4a29982ab5 Mon Sep 17 00:00:00 2001 From: Justin Zhao Date: Wed, 3 Aug 2022 14:18:44 -0700 Subject: [PATCH 4/4] Set allow_none=True. --- ludwig/schema/trainer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ludwig/schema/trainer.py b/ludwig/schema/trainer.py index cd1e2d4a7bf..934a4838731 100644 --- a/ludwig/schema/trainer.py +++ b/ludwig/schema/trainer.py @@ -316,7 +316,7 @@ class GBMTrainerConfig(BaseTrainerConfig): # is not specified. GBM does not have a value for batch_size, so we need to specify eval_batch_size here. eval_batch_size: Union[None, int, str] = schema_utils.IntegerOrAutoField( default=128, - allow_none=False, + allow_none=True, min_exclusive=0, description=("Size of batch to pass to the model for evaluation."), parameter_metadata=TRAINER_METADATA["eval_batch_size"],