Use google style to document properties (#6130)
* Use google style to document properties * Update src/transformers/configuration_utils.py Co-authored-by: Lysandre Debut <lysandre@huggingface.co> Co-authored-by: Lysandre Debut <lysandre@huggingface.co>
This commit is contained in:
@@ -194,12 +194,18 @@ class PretrainedConfig(object):
|
|||||||
raise err
|
raise err
|
||||||
|
|
||||||
@property
|
@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
|
# If torchscript is set, force return_tuple to avoid jit errors
|
||||||
return self.return_tuple or self.torchscript
|
return self.return_tuple or self.torchscript
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def num_labels(self) -> int:
|
def num_labels(self) -> int:
|
||||||
|
"""
|
||||||
|
:obj:`int`: The number of labels for classification models.
|
||||||
|
"""
|
||||||
return len(self.id2label)
|
return len(self.id2label)
|
||||||
|
|
||||||
@num_labels.setter
|
@num_labels.setter
|
||||||
|
|||||||
@@ -238,10 +238,7 @@ class TFPreTrainedModel(tf.keras.Model, TFModelUtilsMixin, TFGenerationMixin):
|
|||||||
@property
|
@property
|
||||||
def dummy_inputs(self) -> Dict[str, tf.Tensor]:
|
def dummy_inputs(self) -> Dict[str, tf.Tensor]:
|
||||||
"""
|
"""
|
||||||
Dummy inputs to build the network.
|
:obj:`Dict[str, tf.Tensor]`: Dummy inputs to build the network.
|
||||||
|
|
||||||
Returns:
|
|
||||||
:obj:`Dict[str, tf.Tensor]`: The dummy inputs.
|
|
||||||
"""
|
"""
|
||||||
return {"input_ids": tf.constant(DUMMY_INPUTS)}
|
return {"input_ids": tf.constant(DUMMY_INPUTS)}
|
||||||
|
|
||||||
|
|||||||
@@ -157,10 +157,8 @@ class ModuleUtilsMixin:
|
|||||||
@property
|
@property
|
||||||
def device(self) -> device:
|
def device(self) -> device:
|
||||||
"""
|
"""
|
||||||
The device on which the module is (assuming that all the module parameters are on the same device).
|
:obj:`torch.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.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return next(self.parameters()).device
|
return next(self.parameters()).device
|
||||||
@@ -178,10 +176,7 @@ class ModuleUtilsMixin:
|
|||||||
@property
|
@property
|
||||||
def dtype(self) -> dtype:
|
def dtype(self) -> dtype:
|
||||||
"""
|
"""
|
||||||
The dtype of the module (assuming that all the module parameters have the same dtype).
|
:obj:`torch.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.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
return next(self.parameters()).dtype
|
return next(self.parameters()).dtype
|
||||||
@@ -350,10 +345,8 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def dummy_inputs(self) -> Dict[str, torch.Tensor]:
|
def dummy_inputs(self) -> Dict[str, torch.Tensor]:
|
||||||
""" Dummy inputs to do a forward pass in the network.
|
"""
|
||||||
|
:obj:`Dict[str, torch.Tensor]`: Dummy inputs to do a forward pass in the network.
|
||||||
Returns:
|
|
||||||
:obj:`Dict[str, torch.Tensor]`: The dummy inputs.
|
|
||||||
"""
|
"""
|
||||||
return {"input_ids": torch.tensor(DUMMY_INPUTS)}
|
return {"input_ids": torch.tensor(DUMMY_INPUTS)}
|
||||||
|
|
||||||
@@ -371,7 +364,10 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin):
|
|||||||
self.config = config
|
self.config = config
|
||||||
|
|
||||||
@property
|
@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)
|
return getattr(self, self.base_model_prefix, self)
|
||||||
|
|
||||||
def get_input_embeddings(self) -> nn.Module:
|
def get_input_embeddings(self) -> nn.Module:
|
||||||
|
|||||||
Reference in New Issue
Block a user