Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[trainer] --model_parallel hasn't been implemented for most models #9347

Merged
merged 6 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/transformers/modeling_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin):

- **base_model_prefix** (:obj:`str`) -- A string indicating the attribute associated to the base model in
derived classes of the same architecture adding modules on top of the base model.
- **_is_parallelizable** (:obj:`bool`) -- A flag indicating whether this model supports model parallelization.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A private flag should not appear in the public documentation.

Copy link
Contributor Author

@stas00 stas00 Jan 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, right! so put the doc for the property then?

this seems to be different from others - how should I document it then?

Or perhaps just make it into a public member? what is the standard?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not have just this class attribute be public and no property?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it was cleaner since it should be read-only, but it's fine as non-property. changed.

I don't think we have a "way" so that's why I'm never sure when something should be a property or a public attribute.

thank you for the feedback/ideas, @sgugger.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH base_model_prefix is the same, it should be read-only in theory but we have it as a simple class attribute, so let's stay simple for this new attribute too :-)

"""
config_class = None
base_model_prefix = ""
Expand All @@ -417,6 +418,12 @@ class PreTrainedModel(nn.Module, ModuleUtilsMixin, GenerationMixin):
# trained, but which are deterministic)
_keys_to_ignore_on_save = None

_is_parallelizable = False

@property
def is_parallelizable(self) -> bool:
return self._is_parallelizable

@property
def dummy_inputs(self) -> Dict[str, torch.Tensor]:
"""
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/gpt2/modeling_gpt2.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ class GPT2PreTrainedModel(PreTrainedModel):
config_class = GPT2Config
load_tf_weights = load_tf_weights_in_gpt2
base_model_prefix = "transformer"
_is_parallelizable = True

def __init__(self, *inputs, **kwargs):
super().__init__(*inputs, **kwargs)
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/t5/modeling_t5.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,7 @@ class T5PreTrainedModel(PreTrainedModel):
config_class = T5Config
load_tf_weights = load_tf_weights_in_t5
base_model_prefix = "transformer"
_is_parallelizable = True

@property
def dummy_inputs(self):
Expand Down
11 changes: 4 additions & 7 deletions src/transformers/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,10 @@ def __init__(
if model is None and model_init is not None:
model = self.call_model_init()

if self.args.model_parallel:
# XXX: ideally this register should be maintained elsewhere so that the trainer could just do
# if model.model_parallel_is_supported()
mp_supported = ["gpt2", "t5"]
assert (
model.config.model_type in mp_supported
), f"{model.config.model_type} implementation currently doesn't support model parallelism, therefore --model_parallel cl arg cannot be used"
if not model.is_parallelizable:
raise ValueError(
f"{model.__class__.__name__} implementation currently doesn't support model parallelism, therefore --model_parallel cl arg cannot be used"
)

# Model parallel
if model is not None and not self.args.model_parallel:
Expand Down