-
Notifications
You must be signed in to change notification settings - Fork 54
create classes for submitting and watching DDP jobs #70
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 all commits
Commits
Show all changes
4 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
openshift-client==1.0.18 | ||
rich==12.5.1 | ||
ray[default]==2.1.0 | ||
git+https://github.com/project-codeflare/torchx@6517d5b060e4fe32b9ad41019c3bef647095c35f#egg=torchx | ||
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
Empty file.
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,126 @@ | ||
# Copyright 2023 IBM, Red Hat | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
import abc | ||
from typing import TYPE_CHECKING, Optional, Dict, List | ||
from pathlib import Path | ||
|
||
from torchx.components.dist import ddp | ||
from torchx.runner import get_runner | ||
from torchx.specs import AppHandle, parse_app_handle, AppDryRunInfo | ||
|
||
if TYPE_CHECKING: | ||
from ..cluster.cluster import Cluster | ||
|
||
all_jobs: List["Job"] = [] | ||
torchx_runner = get_runner() | ||
|
||
|
||
class JobDefinition(metaclass=abc.ABCMeta): | ||
def _dry_run(self, cluster: "Cluster"): | ||
pass | ||
|
||
def submit(self, cluster: "Cluster"): | ||
pass | ||
|
||
|
||
class Job(metaclass=abc.ABCMeta): | ||
def status(self): | ||
pass | ||
|
||
def logs(self): | ||
pass | ||
|
||
|
||
class DDPJobDefinition(JobDefinition): | ||
def __init__( | ||
self, | ||
script: Optional[str] = None, | ||
m: Optional[str] = None, | ||
script_args: Optional[List[str]] = None, | ||
name: Optional[str] = None, | ||
cpu: Optional[int] = None, | ||
gpu: Optional[int] = None, | ||
memMB: Optional[int] = None, | ||
h: Optional[str] = None, | ||
j: Optional[str] = None, | ||
env: Optional[Dict[str, str]] = None, | ||
max_retries: int = 0, | ||
mounts: Optional[List[str]] = None, | ||
rdzv_port: int = 29500, | ||
scheduler_args: Optional[Dict[str, str]] = None, | ||
): | ||
if bool(script) == bool(m): # logical XOR | ||
raise ValueError( | ||
"Exactly one of the following arguments must be defined: [script, m]." | ||
) | ||
self.script = script | ||
self.m = m | ||
self.script_args: List[str] = script_args if script_args is not None else [] | ||
self.name = name | ||
self.cpu = cpu | ||
self.gpu = gpu | ||
self.memMB = memMB | ||
self.h = h | ||
self.j = j | ||
self.env: Dict[str, str] = env if env is not None else dict() | ||
self.max_retries = max_retries | ||
self.mounts: List[str] = mounts if mounts is not None else [] | ||
self.rdzv_port = rdzv_port | ||
self.scheduler_args: Dict[str, str] = ( | ||
scheduler_args if scheduler_args is not None else dict() | ||
) | ||
|
||
def _dry_run(self, cluster: "Cluster"): | ||
j = f"{cluster.config.max_worker}x{max(cluster.config.gpu, 1)}" # # of proc. = # of gpus | ||
return torchx_runner.dryrun( | ||
app=ddp( | ||
*self.script_args, | ||
script=self.script, | ||
m=self.m, | ||
name=self.name, | ||
h=self.h, | ||
cpu=self.cpu if self.cpu is not None else cluster.config.max_cpus, | ||
gpu=self.gpu if self.gpu is not None else cluster.config.gpu, | ||
memMB=self.memMB | ||
if self.memMB is not None | ||
else cluster.config.max_memory * 1024, | ||
j=self.j if self.j is not None else j, | ||
env=self.env, | ||
max_retries=self.max_retries, | ||
rdzv_port=self.rdzv_port, | ||
mounts=self.mounts, | ||
), | ||
scheduler=cluster.torchx_scheduler, | ||
cfg=cluster.torchx_config(**self.scheduler_args), | ||
workspace=f"file://{Path.cwd()}", | ||
) | ||
|
||
def submit(self, cluster: "Cluster") -> "Job": | ||
return DDPJob(self, cluster) | ||
|
||
|
||
class DDPJob(Job): | ||
def __init__(self, job_definition: "DDPJobDefinition", cluster: "Cluster"): | ||
self.job_definition = job_definition | ||
self.cluster = cluster | ||
self._app_handle = torchx_runner.schedule(job_definition._dry_run(cluster)) | ||
all_jobs.append(self) | ||
|
||
def status(self) -> str: | ||
return torchx_runner.status(self._app_handle) | ||
|
||
def logs(self) -> str: | ||
return "".join(torchx_runner.log_lines(self._app_handle, 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
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.