From 8a8ae27617e3c4dafb34bcbbaadf4ceee28583bd Mon Sep 17 00:00:00 2001 From: Sylvain Gugger <35901082+sgugger@users.noreply.github.com> Date: Wed, 29 Jul 2020 12:28:12 -0400 Subject: [PATCH] Use google style to document properties (#6130) * Use google style to document properties * Update src/transformers/configuration_utils.py Co-authored-by: Lysandre Debut Co-authored-by: Lysandre Debut --- src/transformers/configuration_utils.py | 8 +++++++- src/transformers/modeling_tf_utils.py | 5 +---- src/transformers/modeling_utils.py | 22 +++++++++------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/transformers/configuration_utils.py b/src/transformers/configuration_utils.py index 40efef2b3a..c8dd3572ae 100644 --- a/src/transformers/configuration_utils.py +++ b/src/transformers/configuration_utils.py @@ -194,12 +194,18 @@ class PretrainedConfig(object): raise err @property - def use_return_tuple(self): + def use_return_tuple(self) -> bool: + """ + :obj:`bool`: Whether or not the model should return a tuple. + """ # If torchscript is set, force return_tuple to avoid jit errors return self.return_tuple or self.torchscript @property def num_labels(self) -> int: + """ + :obj:`int`: The number of labels for classification models. + """ return len(self.id2label) @num_labels.setter diff --git a/src/transformers/modeling_tf_utils.py b/src/transformers/modeling_tf_utils.py index b2ff04741d..10b355f22a 100644 --- a/src/transformers/modeling_tf_utils.py +++ b/src/transformers/modeling_tf_utils.py @@ -238,10 +238,7 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin): @property def dummy_inputs(self) -> Dict[str, tf.Tensor]: """ - Dummy inputs to build the network. - - Returns: - :obj:`Dict[str, tf.Tensor]`: The dummy inputs. + :obj:`Dict[str, tf.Tensor]`: Dummy inputs to build the network. """ return {"input_ids": tf.constant(DUMMY_INPUTS)} diff --git a/src/transformers/modeling_utils.py b/src/transformers/modeling_utils.py index bd33f7a7a3..7296ba4ac4 100644 --- a/src/transformers/modeling_utils.py +++ b/src/transformers/modeling_utils.py @@ -157,10 +157,8 @@ class ModuleUtilsMixin: @property def device(self) -> device: """ - The device on which the module is (assuming that all the module parameters are on the same device). - - Returns: - :obj:`torch.device` The device of the module. + :obj:`torch.device`: The device on which the module is (assuming that all the module parameters are on the same + device). """ try: return next(self.parameters()).device @@ -178,10 +176,7 @@ class ModuleUtilsMixin: @property def dtype(self) -> dtype: """ - The dtype of the module (assuming that all the module parameters have the same dtype). - - Returns: - :obj:`torch.dtype` The dtype of the module. + :obj:`torch.dtype`: The dtype of the module (assuming that all the module parameters have the same dtype). """ try: return next(self.parameters()).dtype @@ -350,10 +345,8 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin): @property def dummy_inputs(self) -> Dict[str, torch.Tensor]: - """ Dummy inputs to do a forward pass in the network. - - Returns: - :obj:`Dict[str, torch.Tensor]`: The dummy inputs. + """ + :obj:`Dict[str, torch.Tensor]`: Dummy inputs to do a forward pass in the network. """ return {"input_ids": torch.tensor(DUMMY_INPUTS)} @@ -371,7 +364,10 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin): self.config = config @property - def base_model(self): + def base_model(self) -> nn.Module: + """ + :obj:`torch.nn.Module`: The main body of the model. + """ return getattr(self, self.base_model_prefix, self) def get_input_embeddings(self) -> nn.Module: