[fx] Add unit test and fix bugs for transform_mlp_pass#1299
Merged
FrankLeeeee merged 3 commits intohpcaitech:mainfrom Jul 15, 2022
Merged
[fx] Add unit test and fix bugs for transform_mlp_pass#1299FrankLeeeee merged 3 commits intohpcaitech:mainfrom
FrankLeeeee merged 3 commits intohpcaitech:mainfrom
Conversation
FrankLeeeee
reviewed
Jul 15, 2022
| from torch.fx.passes.split_module import split_module | ||
|
|
||
| import colossalai | ||
| # from colossalai.tensor import ColoTensor, TensorSpec, distspec, ProcessGroup, ComputeSpec, ComputePattern |
FrankLeeeee
reviewed
Jul 15, 2022
Comment on lines
+24
to
+37
| #TODO: This func temporarily works with no materialization | ||
| # Append a Tensor spec to target_module.weight.shard | ||
| # Convert to ColoTensor: colo_tensor = ColoTensor.from_torch_tensor(tensor, spec) | ||
| assert isinstance(weight, torch.Tensor), \ | ||
| f'The type of the input tensor should be torch.nn.parameter' \ | ||
| f'Your Input tensor is {type(weight)}' | ||
| # assert isinstance(weight, torch.nn.parameter.Parameter), \ | ||
| # f'The type of the input tensor should be torch.nn.parameter' \ | ||
| # f'Your Input tensor is {type(weight)}' | ||
|
|
||
| # FIXME() I initialized a PG for this tensor. Only has TP comm group. | ||
| # we only consider the TP-only caes. | ||
| world_size = torch.distributed.get_world_size() | ||
| pg = ProcessGroup(tp_degree=world_size) | ||
| # world_size = torch.distributed.get_world_size() | ||
| # pg = ProcessGroup(tp_degree=world_size) | ||
|
|
||
| spec = ColoTensorSpec(pg, ShardSpec([dim], [pg.tp_world_size()]), ComputeSpec(ComputePattern.TP1D)) | ||
| # As you has constructed a Spec, why not directly convert the tensor to ColoTensor. | ||
| setattr(weight, "fx_attr", spec) | ||
| # spec = TensorSpec(distspec.shard(pg, [dim], [pg.tp_world_size()]), ComputeSpec(ComputePattern.TP1D)) | ||
| # # As you has constructed a Spec, why not directly convert the tensor to ColoTensor. |
Contributor
There was a problem hiding this comment.
Remove unnecessary comments and code.
FrankLeeeee
reviewed
Jul 15, 2022
| setattr(weight, "fx_attr", (dim, "SHARD", "TP", "col_normal")) | ||
| else: | ||
| setattr(weight, "fx_attr", (dim, "SHARD", "TP", "col_needs_many_outputs")) | ||
| # weight.data = ColoTensor(data=weight.data, spec=spec) |
FrankLeeeee
approved these changes
Jul 15, 2022
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.
Still needs to handle special cases.