馃毃 Pass tp_plan from lm_heads - #47253
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
| config = self.model_tester.get_config() | ||
| text_config = config.get_text_config() | ||
| remainder = text_config.vocab_size % self.tensor_parallel_size | ||
| if remainder: | ||
| text_config.vocab_size += self.tensor_parallel_size - remainder | ||
| return config |
There was a problem hiding this comment.
this is because we have typically vocab size 99 on tiny tests, which can't be sharded on 2 ranks obviously
There was a problem hiding this comment.
I'm thinking wheter we should automatically extend an embedding if we notice this? So in from pretrained, if we notice
- TP
- Embeddings that get shared we resize the embeddings before
There was a problem hiding this comment.
ah auto-pad you mean? hmm we could ig, I feel like we are already doing it in a couple other places IIRC
There was a problem hiding this comment.
Yep, because users will complain I'm sure 馃槄 Maybe a warning but having users to think leads to problems
There was a problem hiding this comment.
but we should pad just before the gather and unpad right after, no?
There was a problem hiding this comment.
other idea (sorry for the noise): we should just validate, feels less magic. like if TP is provided with a wrong vocab size just raise from the get-go. Should be in another PR though because it could break existing setups
There was a problem hiding this comment.
I think this is already breaking in itself no? Users could have arbitrary vocab sizes before this
But yea, I can see the validation path - less magic and add how to properly do it
There was a problem hiding this comment.
ah yes, you're right... before it was silently replicating so of course this will raise. I'll add the validation logic then
There was a problem hiding this comment.
IMO, if it does not cost much and we can resize for the user, would be nice. People probably expect us to do so, and we are the ones setting the plan to default to colwise rep.
The main concern is for the gather to not take into account the padding, which is important
vasqu
left a comment
There was a problem hiding this comment.
Imo, this looks good but let's wait for @ArthurZucker and @3outeille for a final look 馃
CI recapDashboard: View test results in Grafana |
ArthurZucker
left a comment
There was a problem hiding this comment.
ty, not sure we need generic, and as pointed let's maybe pad by default?
we can isolate the 2 changes. let's also trace the blame on PR that regressed the init, it was I am certain working before
| def validate_module(self, module: nn.Module, device_mesh, layer_name: str = ""): | ||
| out_features = getattr(module, "out_features", None) | ||
| if self.gather_output and out_features is not None and out_features % device_mesh.size() != 0: | ||
| raise ValueError( | ||
| f"`{layer_name}` ({type(module).__name__} with out_features={out_features}) is sharded with " | ||
| f"'colwise_gather_output', which requires out_features to be divisible by the number of ranks " | ||
| f"({device_mesh.size()}) to all-gather equal-size shards. Resize the weight (e.g. " | ||
| f"`model.resize_token_embeddings` for LM heads) or override this module's entry in the tp_plan." | ||
| ) | ||
|
|
There was a problem hiding this comment.
since only this layer uses it, we can not make it generic for now
There was a problem hiding this comment.
yeah it's a bit awkward. Wdy suggest? move it the the layer?
| # easily available. | ||
| self._tp_plan, self._ep_plan, self._pp_plan, self._fsdp_plan = {}, {}, {}, {} | ||
| # Start from the class-level plans (e.g. `{"lm_head": "colwise_rep"}` on `...ForCausalLM` classes), copying | ||
| # them as they are mutated below and would otherwise contaminate the class attribute shared by all instances |
There was a problem hiding this comment.
absolutely, this was already the case.... do you know where the regression comes from?
There was a problem hiding this comment.
yeah wrote that mostly for review. Yes, it seems to be coming from a big Revert, likely an oversight #46246
There was a problem hiding this comment.
it's actually in #36677 and then we keep the pattern
There was a problem hiding this comment.
Are you sure @3outeille ? it doesn't seem to be there that we set
self._tp_plan, self._ep_plan, self._pp_plan, self._fsdp_plan = {}, {}, {}, {}
| # models, this attribute is currently defined in respective model code. For base models, it comes from | ||
| # `config.base_model_pp_plan` during `post_init`. | ||
| _pp_plan: dict[str, tuple[str, str]] = None | ||
| # An expert parallel plan used instead of `_tp_plan` when expert parallelism is enabled. For base models, it comes |
There was a problem hiding this comment.
can you elaborate? 馃榿
| config = self.model_tester.get_config() | ||
| text_config = config.get_text_config() | ||
| remainder = text_config.vocab_size % self.tensor_parallel_size | ||
| if remainder: | ||
| text_config.vocab_size += self.tensor_parallel_size - remainder | ||
| return config |
There was a problem hiding this comment.
IMO, if it does not cost much and we can resize for the user, would be nice. People probably expect us to do so, and we are the ones setting the plan to default to colwise rep.
The main concern is for the gather to not take into account the padding, which is important
|
Merging we need it for release |
* pass tp_plan from lm_heads * add a small test to avoid regressiosn on TP * world size must divide vocab size * early raise for incompatible vocabs * test our test
* pass tp_plan from lm_heads * add a small test to avoid regressiosn on TP * world size must divide vocab size * early raise for incompatible vocabs * test our test
What does this PR do?
Noticed currently the
lm_head-specific tp plans are wiped inPreTrainedModelpost-init (we just ignore them). This should fix it