This repository was archived by the owner on Oct 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 353
task 801 - launch physical meshes after compilation #938
Open
haifaksh
wants to merge
2
commits into
alpa-projects:main
Choose a base branch
from
haifaksh:haifa-task-801
base: main
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 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2305,6 +2305,78 @@ def profile_all(self, *args, **kwargs): | |
| return mesh_profiling.profile_all(self, *args, **kwargs) | ||
|
|
||
|
|
||
| #TODO Github Task - CustomVirtualMesh for interfaces | ||
| class VirtualWorker: | ||
| def __init__(self, index): | ||
| self.index = index | ||
| # Additional attributes or methods of virtual workers | ||
|
|
||
| class CustomVirtualMesh(VirtualPhysicalMesh): | ||
| def __init__(self, | ||
| host_ids: Sequence[int], | ||
| host_info: Sequence[dict], | ||
| num_devices_per_host, | ||
| parent: "VirtualPhysicalMesh" = None, | ||
| devices: Sequence[Sequence[int]] = None, | ||
| mesh_id: int = None | ||
| ): | ||
| super().__init__(host_ids, host_info, num_devices_per_host, parent, devices) | ||
| self.host_ips = [] | ||
|
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. This member seems never used. If so, please remove it |
||
| self.workers = [] # Virtual workers | ||
| self.mesh_id = mesh_id | ||
|
|
||
| for host_id in host_ids: | ||
| self.host_ips.append(host_info[host_id]['NodeName']) | ||
| self.workers.append(VirtualWorker(mesh_id)) | ||
|
|
||
|
|
||
| #TODO Github Task - VirtualMeshGroup for interfaces | ||
| class VirtualMeshGroup: | ||
| def __init__(self, sliced_virtual_meshes: List[VirtualPhysicalMesh]): | ||
| self.sliced_virtual_meshes = self.get_virtual_meshes(sliced_virtual_meshes) | ||
| self.collective_groups: List[List[Any]] = [ | ||
| [None for _ in range(len(self))] for _ in range(len(self)) | ||
| ] | ||
| self.launched_nccl = False | ||
|
|
||
| def __getitem__(self, index): | ||
| return self.sliced_virtual_meshes[index] | ||
|
|
||
| def __len__(self): | ||
| return len(self.sliced_virtual_meshes) | ||
|
|
||
| def index(self, *args, **kwargs): | ||
| return self.sliced_virtual_meshes.index(*args, **kwargs) | ||
|
|
||
| def get_virtual_meshes(self, sliced_virtual_meshes): | ||
| custom_sliced_virtual_meshes = [] | ||
| for mesh_idx, mesh in enumerate(sliced_virtual_meshes): | ||
| custom_mesh = CustomVirtualMesh(mesh.host_ids, mesh.host_info, mesh.num_devices_per_host, mesh.parent, mesh.devices, mesh_idx) | ||
| custom_sliced_virtual_meshes.append(custom_mesh) | ||
| return custom_sliced_virtual_meshes | ||
|
|
||
| def establish_nccl_group(self, | ||
| src_mesh_id: int, | ||
| dst_mesh_id: int, | ||
| instantiate=False | ||
| ): | ||
| """Establish NCCL group between two meshes.""" | ||
| # pylint: disable=import-outside-toplevel | ||
| from alpa.pipeline_parallel.cross_mesh_resharding import CollectiveGroup | ||
|
|
||
| assert src_mesh_id < dst_mesh_id | ||
| if self.collective_groups[src_mesh_id][dst_mesh_id] is not None: | ||
| # Already established | ||
| return | ||
| src_mesh = self.sliced_virtual_meshes[src_mesh_id] | ||
| dst_mesh = self.sliced_virtual_meshes[dst_mesh_id] | ||
| device_strs = OrderedSet(src_mesh.device_strs + dst_mesh.device_strs) | ||
| cg = CollectiveGroup(device_strs, src_mesh, dst_mesh) | ||
| self.collective_groups[src_mesh_id][dst_mesh_id] = cg | ||
| self.collective_groups[dst_mesh_id][src_mesh_id] = cg | ||
|
|
||
|
|
||
|
|
||
| # Global runtime objects | ||
| global_cluster: DeviceCluster = None | ||
| global_physical_mesh: PhysicalDeviceMesh = None | ||
|
|
||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| from alpa.device_mesh import (DistributedArray, RemoteArrayRef, | ||
| ReshardingRecvSpec, ReshardingSendSpec, | ||
| ReshardingTileSpec, ReshardingBroadcastSpec, | ||
| _device_mesh_put_dummy, device_id_to_str) | ||
| _device_mesh_put_dummy, device_id_to_str, VirtualWorker) | ||
| from alpa.global_env import global_config | ||
| from alpa.mesh_executable import (UtilMeshWorkerExecutable, | ||
| next_mesh_executable_uuid) | ||
|
|
@@ -195,6 +195,8 @@ def __init__(self, task_spec, collective_group, src_mesh, dst_mesh): | |
| self.send_worker_task_ids = {} | ||
| self.recv_worker_task_ids = {} | ||
|
|
||
| self.task_dones = [] | ||
|
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. remove unused code. For a series of tasks, we always create a tmp task dones instead of keeping using the same one |
||
|
|
||
| # generate the above states | ||
| self._compile() | ||
| # print(self.__str__()+"\n") | ||
|
|
@@ -220,6 +222,7 @@ def _compile(self): | |
| """ | ||
| self._compile_send_recv_tasks() | ||
|
|
||
| #TODO Github task - moving this to pipeshard_executable | ||
| if not global_config.debug_with_pipeshard_runtime: | ||
| self.put_all_tasks() | ||
|
|
||
|
|
@@ -229,19 +232,34 @@ def put_all_tasks(self): | |
| """ | ||
| # put send and recv tasks | ||
| task_dones = [] | ||
| temp_worker = None | ||
| for worker, task in self.sender_tasks.items(): | ||
| uuid = next_resharding_task_uuid() | ||
| if isinstance(worker, VirtualWorker): | ||
| for actor, idx in self.collective_group.worker_to_rank_map.items(): | ||
| if idx == worker.index: | ||
| temp_worker = actor | ||
| worker = temp_worker | ||
| self.send_worker_task_ids[worker] = uuid | ||
| task_dones.append( | ||
| worker.put_resharding_send_task.remote( | ||
| uuid, task, self.collective_group.group_name)) | ||
|
|
||
| if not isinstance(worker, VirtualWorker): | ||
| task_dones.append( | ||
| worker.put_resharding_send_task.remote( | ||
| uuid, task, self.collective_group.group_name)) | ||
| for worker, task in self.receiver_tasks.items(): | ||
| uuid = next_resharding_task_uuid() | ||
| if isinstance(worker, VirtualWorker): | ||
| for actor, idx in self.collective_group.worker_to_rank_map.items(): | ||
| if idx == worker.index: | ||
| temp_worker = actor | ||
| worker = temp_worker | ||
| self.recv_worker_task_ids[worker] = uuid | ||
| task_dones.append( | ||
| worker.put_resharding_recv_task.remote( | ||
| uuid, task, self.collective_group.group_name)) | ||
| ray.get(task_dones) | ||
| if not isinstance(worker, VirtualWorker): | ||
| task_dones.append( | ||
| worker.put_resharding_recv_task.remote( | ||
| uuid, task, self.collective_group.group_name)) | ||
| if len(task_dones) > 0: | ||
| ray.get(task_dones) | ||
|
|
||
| # put allgather tasks | ||
| task_dones = [] | ||
|
|
@@ -252,17 +270,28 @@ def put_all_tasks(self): | |
| task_spec.dst_sharding_spec, | ||
| task_spec.final_dst_spec, | ||
| np.prod(self.dst_mesh.shape)) | ||
|
|
||
| for worker in self.dst_mesh.workers: | ||
| task_dones.append( | ||
| worker.put_executable.remote(uuid, UtilMeshWorkerExecutable, | ||
| hlo)) | ||
| ray.get(task_dones) | ||
| if isinstance(worker, VirtualWorker): | ||
| for actor, idx in self.collective_group.worker_to_rank_map.items(): | ||
| if idx == worker.index: | ||
| temp_worker = actor | ||
| worker = temp_worker | ||
| if not isinstance(worker, VirtualWorker): | ||
| task_dones.append( | ||
| worker.put_executable.remote(uuid, UtilMeshWorkerExecutable, | ||
| hlo)) | ||
| if len(task_dones) > 0: | ||
| ray.get(task_dones) | ||
|
|
||
| def create_resharding_communicators(self): | ||
| """Create the NCCL communicators in advance.""" | ||
| communicator_params = set() | ||
| for worker, recv_tasks in self.receiver_tasks.items(): | ||
| dst_rank = self.collective_group.worker_to_rank_map[worker] | ||
| if isinstance(worker, VirtualWorker): | ||
| dst_rank = worker.index | ||
| else: | ||
| dst_rank = self.collective_group.worker_to_rank_map[worker] | ||
| for recv_task in recv_tasks: | ||
| dst_gpu_idx = recv_task.device_id | ||
| tile_specs = recv_task.tile_specs | ||
|
|
@@ -456,11 +485,18 @@ def put_all_tasks(self): | |
| task_dones = [] | ||
| for worker, task in self._broadcast_tasks.items(): | ||
| uuid = next_resharding_task_uuid() | ||
| if isinstance(worker, VirtualWorker): | ||
| for actor, idx in self.collective_group.worker_to_rank_map.items(): | ||
| if idx == worker.index: | ||
| temp_worker = actor | ||
| worker = temp_worker | ||
| self.broadcast_worker_task_ids[worker] = uuid | ||
| # print(worker, uuid, task) | ||
| task_dones.append( | ||
| worker.put_resharding_broadcast_task.remote( | ||
| uuid, task, self.collective_group.group_name)) | ||
| if not isinstance(worker, VirtualWorker): | ||
| task_dones.append( | ||
| worker.put_resharding_broadcast_task.remote( | ||
| uuid, task, self.collective_group.group_name)) | ||
|
|
||
| ray.get(task_dones) | ||
|
|
||
| def _compile_broadcast_tasks(self): | ||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.