-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Enabled configurable auto Tensor Parallelism (TP) for the inference of diverse models #6553
Open
gyou2021
wants to merge
4
commits into
microsoft:master
Choose a base branch
from
gyou2021:configurable_autoTP
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
08f728d
Enabled Qwen2-MoE Tensor Parallism (TP) inference
gyou2021 f6e8637
Enabled configurable auto Tensor Parallelism (TP) for inference of di…
gyou2021 f45a7a9
Merge branch 'master' into configurable_autoTP
loadams 397402e
Merge branch 'master' into configurable_autoTP
loadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ | |
from deepspeed.accelerator import get_accelerator | ||
from .fusedqkv_utils import require_tp_fused_qkvw, prepare_tp_fused_qkvw, shard_value_with_share_qk, shard_chunk_mlp | ||
from deepspeed.module_inject.tp_shard import get_shard_size, get_shard_size_list | ||
import os | ||
import ast | ||
|
||
|
||
def move(tensor, device): | ||
|
@@ -270,6 +272,7 @@ def kernel_supported(module_list): | |
return True | ||
return False | ||
|
||
## tp parser based on autoTP config in environment | ||
def tp_parser(model): | ||
policy_list = [] | ||
module_list = [] | ||
|
@@ -279,40 +282,27 @@ def tp_parser(model): | |
module_list = AutoTP.get_module_list(model) | ||
assert AutoTP.supported(model), "AutoTP not supported for model. Please use kernel injection since container policy for model exists." \ | ||
if AutoTP.kernel_supported(module_list) else "AutoTP not supported for model. Please provide policy." | ||
norm_layer_name_list = ['LayerNorm', 'layer_norm', 'ln_1', 'ln_2'] | ||
#ln_1 , ln_2 for Qwen | ||
|
||
allReduceLinearItems = os.environ['allReduceLinearItems'] | ||
allReduceLinearItems = ast.literal_eval(allReduceLinearItems) | ||
|
||
for module in module_list: | ||
for key, submodule in module._modules.items(): | ||
if isinstance(submodule, nn.Linear): | ||
layer_list = layer_list + ["." + key] | ||
elif isinstance(submodule, nn.LayerNorm) or key in norm_layer_name_list: | ||
elif isinstance(submodule, nn.LayerNorm) or key == 'LayerNorm' or key == 'layer_norm': | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be replaced equivalently? |
||
layer_list = layer_list + ["ln"] | ||
else: | ||
layer_list = layer_list + AutoTP.get_layers(key, submodule) | ||
|
||
for i, layer in enumerate(layer_list): | ||
if layer == 'ln': | ||
if layer_list[i - 1] != 'ln': | ||
gem_list = gem_list + [layer_list[i - 1]] | ||
elif 'out_proj' in layer: | ||
gem_list = gem_list + [layer] | ||
elif 'o_proj' in layer: | ||
gem_list = gem_list + [layer] | ||
elif 'down_proj' in layer: | ||
gem_list = gem_list + [layer] | ||
elif 'attention.dense' in layer and 'GPTNeoX' in str(model): | ||
gem_list = gem_list + [layer] | ||
elif 'self_attention.dense' in layer and 'falcon' in str( | ||
type(module)): # this is a hack to get the right linear layer for this model! | ||
gem_list = gem_list + [layer] | ||
# Mixtral-7x8b used w2*act(w1*w3) linear. need to replace w2 to linearallreduce. | ||
elif 'w2' in layer and 'Mixtral' in str(type(module)): | ||
gem_list = gem_list + [layer] | ||
elif 'self_attn.dense' in layer and 'Phi' in str(type(module)): | ||
gem_list = gem_list + [layer] | ||
elif 'self_attention.dense' in layer and 'ChatGLM' in str(model): | ||
gem_list = gem_list + [layer] | ||
elif 'dense_4h_to_h' in layer and 'ChatGLM' in str(model): | ||
gem_list = gem_list + [layer] | ||
continue | ||
for item in allReduceLinearItems: | ||
if item in layer: | ||
gem_list = gem_list + [layer] | ||
|
||
layer_list = [] | ||
if gem_list != []: | ||
|
@@ -473,7 +463,12 @@ def _replace_module(self, r_module, prev_name='', prev_class_name=''): | |
if len(child._buffers) != 0 and self.state_dict is not None: | ||
Loading.load_buffer(child, self.state_dict, checking_key) | ||
if child.__class__ in self.linear_policies: | ||
setattr(r_module, name, self.linear_policies[child.__class__](child, prev_name + '.' + name, | ||
keepLinearItems = os.environ['keepLinearItems'] | ||
keepLinearItems = ast.literal_eval(keepLinearItems) | ||
|
||
if any(item not in checking_key for item in keepLinearItems): | ||
setattr( | ||
r_module, name, self.linear_policies[child.__class__](child, prev_name + '.' + name, | ||
self.conv_linear_layer)) | ||
elif any(isinstance(child, lp) for lp in self.linear_policies): | ||
# Added for falcon model support | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the environment keep DeepSpeed as
DS_ALL_REDUCE_LINEAR_ITEMS
? This will make the naming more consistent with existing DeepSpeed knobs.