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

Simplify broadcast logic for control messages #2501

Merged
merged 8 commits into from
Jan 19, 2024

Conversation

zhuohan123
Copy link
Collaborator

@zhuohan123 zhuohan123 commented Jan 19, 2024

In this PR, we simplify and unify the previous nasty control message broadcast logic.

@njhill
Copy link
Member

njhill commented Jan 19, 2024

@zhuohan123 looks much cleaner! But since most of the tensors share a dtype and are the same shape apart from size of one dimension, I was those could be concatenated and just pass the offsets. So that the number of broadcasts done can be minimized. This wouldn't be quite as nice and generic as what you've done but might not look too bad?

Copy link
Collaborator

@WoosukKwon WoosukKwon left a comment

Choose a reason for hiding this comment

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

@zhuohan123 Thanks for cleaning this up! It looks much nicer to me. Please take a look at my minor comments.

class TensorMetadata:
"""A simple class to hold tensor metadata."""

def __init__(self, tensor):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
def __init__(self, tensor):
def __init__(self, tensor: torch.Tensor):

self.size = tensor.size()

def __repr__(self):
return (f"TensorMetadata(dtype={self.dtype}, size={self.size})")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
return (f"TensorMetadata(dtype={self.dtype}, size={self.size})")
return f"TensorMetadata(dtype={self.dtype}, size={self.size})"

Comment on lines 125 to 126
def broadcast_tensor_dict(tensor_dict: Dict[Any, Union[torch.Tensor,
Any]] = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The tensor_dict type is a bit weird: Shouldn't it be Optional[Dict]? Also, how Union[torch.Tensor, Any] is different from Any?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks I indeed missed an Optional. I use Union[torch.Tensor, Any] to explicitly emphasize that we treat torch.Tensor and other types differently in this function.

@@ -104,3 +109,67 @@ def broadcast_object_list(obj_list, src=0):
# Broadcast.
torch.distributed.broadcast_object_list(obj_list, src=src)
return obj_list


class TensorMetadata:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can using a class instead of raw data type incur any additional overhead? If so, can we use named tuple instead?

@zhuohan123
Copy link
Collaborator Author

zhuohan123 commented Jan 19, 2024

@zhuohan123 looks much cleaner! But since most of the tensors share a dtype and are the same shape apart from size of one dimension, I was those could be concatenated and just pass the offsets. So that the number of broadcasts done can be minimized. This wouldn't be quite as nice and generic as what you've done but might not look too bad?

Yeah some of the tensors are int and some are float, and also some tensor's shapes can be different. Also, concatenating and splitting tensors themselves have overheads.

@zhuohan123 zhuohan123 merged commit ef9b636 into main Jan 19, 2024
16 checks passed
hongxiayang pushed a commit to hongxiayang/vllm that referenced this pull request Feb 13, 2024
@zhuohan123 zhuohan123 deleted the simplify-control-broadcast branch February 22, 2024 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants