Skip to content

Commit

Permalink
Adds PreTrainedModel.framework attribute (#13817)
Browse files Browse the repository at this point in the history
* Added `framework` attribute

* Update modeling_utils.py

* Update modeling_flax_utils.py

* Update modeling_tf_utils.py

* Update modeling_utils.py

* Update modeling_tf_utils.py

* Update modeling_tf_utils.py

* Update modeling_flax_utils.py

* Update modeling_tf_utils.py

* Update modeling_utils.py

* Update modeling_utils.py

* Update modeling_tf_utils.py

* Update modeling_flax_utils.py

* string -> str

* Update modeling_tf_utils.py

* string -> str

* fixup

* make flake happy

Co-authored-by: patil-suraj <surajp815@gmail.com>
  • Loading branch information
StellaAthena and patil-suraj authored Oct 8, 2021
1 parent d70919e commit de34481
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/transformers/modeling_flax_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ def _from_config(cls, config, **kwargs):
"""
return cls(config, **kwargs)

@property
def framework(self) -> str:
"""
:str: Identifies that this is a Flax model.
"""
return "flax"

@property
def config(self) -> PretrainedConfig:
return self._config
Expand Down
7 changes: 7 additions & 0 deletions src/transformers/modeling_tf_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,13 @@ def dummy_inputs(self) -> Dict[str, tf.Tensor]:
"input_ids": tf.constant(DUMMY_INPUTS),
}

@property
def framework(self) -> str:
"""
:str: Identifies that this is a TensorFlow model.
"""
return "tf"

def __init__(self, config, *inputs, **kwargs):
super().__init__(*inputs, **kwargs)
if not isinstance(config, PretrainedConfig):
Expand Down
7 changes: 7 additions & 0 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,13 @@ def dummy_inputs(self) -> Dict[str, torch.Tensor]:
"""
return {"input_ids": torch.tensor(DUMMY_INPUTS)}

@property
def framework(self) -> str:
"""
:str: Identifies that this is a PyTorch model.
"""
return "pt"

def __init__(self, config: PretrainedConfig, *inputs, **kwargs):
super().__init__()
if not isinstance(config, PretrainedConfig):
Expand Down

0 comments on commit de34481

Please sign in to comment.