Remove unused parameters and improve add_tensor_parallel_hooks_t…#44768
Merged
michaelbenayoun merged 4 commits intohuggingface:mainfrom Apr 9, 2026
Merged
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. |
3outeille
reviewed
Mar 24, 2026
| except NotImplementedError as e: | ||
| print( | ||
| f"Trying to prepare {layer_name}, but it's not supported. Corresponding module: {module} Fix it's TP plan: {e}" | ||
| modules2names = {v: k for k, v in dict(model.named_modules()).items()} |
Member
There was a problem hiding this comment.
add_tensor_parallel_hooks_to_module is called for name, module in model.named_modules(): in def distribute_model() so that's a bit costly no to create a dict at every iteration?
Member
Author
There was a problem hiding this comment.
It's ok imo, it is called only when we have a broken TP plan, not at every call.
We can also have a cache for this if you prefer.
Member
Author
There was a problem hiding this comment.
Addressed it by caching
3outeille
approved these changes
Apr 9, 2026
sirzechs66
pushed a commit
to sirzechs66/transformers
that referenced
this pull request
Apr 18, 2026
…ggingface#44768) * fix: remove unused parameters and improve add_tensor_parallel_hooks_to_module * feat: cache module -> name mappings in hooks * fix: do not use cache, use explicit parameter --------- Co-authored-by: Ferdinand Mom <47445085+3outeille@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function
add_tensor_parallel_hooks_to_modulehas unused parameters, in this PR we:tp_plan, which is not used.parameter_namewhich is not usedlayer_name. This parameter is only used for logging purposes, and we can infer it when it does happen. It is a bit more costly, but since it is not supposed to happen, it is ok to proceed like that imo