-
Notifications
You must be signed in to change notification settings - Fork 16
Enables dynamic GPU allocation for local workloads #91
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
befe538
initial commit
47aa7e0
Merge branch 'main' into dynamic_gpus
ea0cd09
add back spawn
ac50eba
stash
286e841
park
2ee010d
add gpu resource management
efb5661
add gpu resource management
8f0380c
update test apis
8b00bb2
Merge branch 'main' into dynamic_gpus
caa147a
stash
4aa8778
sft v2 works again
d1dce29
renames, adds stop capability
730365c
some updates
1ce8635
typo fix
97f04b6
fix test
4b83d16
missing import
d11dcae
no nested submodule
2ea4d3e
check
00c1a2b
num_gpus => with_gpus
2d30f2f
proc mesh update
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
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
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from .gpu_manager import get_gpu_ids, release_gpus | ||
|
||
__all__ = [ | ||
"get_gpu_ids", | ||
"release_gpus", | ||
] |
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
"""Implements an actor responsible for tracking and assigning GPU devices on HostMesh.""" | ||
|
||
import logging | ||
|
||
from monarch.actor import ActorError, endpoint, get_or_spawn_controller | ||
|
||
from forge.controller import ForgeActor | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.setLevel(logging.DEBUG) | ||
|
||
|
||
class GpuManager(ForgeActor): | ||
"""An actor that tracks and assigns GPU devices on given HostMeshes.""" | ||
|
||
def __init__(self): | ||
# TODO - extend this to support multiple HostMeshes too | ||
self.available_gpus = set(range(0, 8)) | ||
|
||
@endpoint | ||
def get_available_gpus(self) -> list[str]: | ||
"""Returns a list of available GPU devices.""" | ||
return [str(gpu) for gpu in self.available_gpus] | ||
|
||
@endpoint | ||
def get_gpus(self, num_gpus: int) -> list[str]: | ||
"""Assigns GPU devices.""" | ||
if num_gpus > len(self.available_gpus): | ||
raise RuntimeError("Not enough GPUs available") | ||
gpus = list(self.available_gpus)[:num_gpus] | ||
self.available_gpus -= set(gpus) | ||
return [str(gpu) for gpu in gpus] | ||
|
||
@endpoint | ||
def release_gpus(self, gpu_ids: list[str]) -> None: | ||
"""Releases the given GPU devices.""" | ||
for gpu_id in gpu_ids: | ||
self.available_gpus.add(int(gpu_id)) | ||
|
||
def __repr__(self) -> str: | ||
return "GpuManager" | ||
|
||
|
||
async def get_gpu_manager() -> GpuManager: | ||
"""Gets the singleton GPU manager actor.""" | ||
try: | ||
return await get_or_spawn_controller("gpu_manager", GpuManager) | ||
except ActorError as e: | ||
raise e.exception from e | ||
|
||
|
||
async def get_gpu_ids(num_gpus: int) -> list[str]: | ||
"""Gets GPU IDs for the given number of GPUs.""" | ||
try: | ||
gpu_manager = await get_or_spawn_controller("gpu_manager", GpuManager) | ||
return await gpu_manager.get_gpus.call_one(num_gpus) | ||
except ActorError as e: | ||
# Raise the underlying error instead of the Monarch error | ||
raise e.exception from e | ||
|
||
|
||
async def release_gpus(gpu_ids: list[str]) -> None: | ||
"""Releases the given GPU IDs.""" | ||
try: | ||
gpu_manager = await get_or_spawn_controller("gpu_manager", GpuManager) | ||
await gpu_manager.release_gpus.call_one(gpu_ids) | ||
except ActorError as e: | ||
# Raise the underlying error instead of the Monarch error | ||
raise e.exception from e |
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
"""Implements an actor that tracks all services runinng in the workload.""" | ||
allenwang28 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
from monarch.actor import endpoint | ||
|
||
from forge.controller import ForgeActor | ||
|
||
|
||
class ServiceRegistry(ForgeActor): | ||
def __init__(self): | ||
pass | ||
|
||
@endpoint | ||
def register(self): | ||
pass |
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright (c) Meta Platforms, Inc. and affiliates. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the BSD-style license found in the | ||
# LICENSE file in the root directory of this source tree. | ||
|
||
from .interface import ServiceInterface, Session, SessionContext | ||
from .metrics import ServiceMetrics | ||
from .replica import Replica, ReplicaMetrics | ||
from .service import Service, ServiceConfig | ||
from .spawn import spawn_service | ||
|
||
__all__ = [ | ||
"Service", | ||
"ServiceConfig", | ||
"spawn_service", | ||
"ServiceInterface", | ||
"Session", | ||
"SessionContext", | ||
"ServiceMetrics", | ||
"Replica", | ||
"ReplicaMetrics", | ||
] |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
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
Oops, something went wrong.
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.