-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/maharshi95/submitit-wrapper
- Loading branch information
Showing
8 changed files
with
214 additions
and
43 deletions.
There are no files selected for viewing
This file contains 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,40 @@ | ||
# This workflow will upload a Python Package using Twine when a release is created | ||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python#publishing-to-package-registries | ||
|
||
# This workflow uses actions that are not certified by GitHub. | ||
# They are provided by a third-party and are governed by | ||
# separate terms of service, privacy policy, and support | ||
# documentation. | ||
|
||
name: Upload Python Package | ||
|
||
on: | ||
release: | ||
types: [published] | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
deploy: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@main | ||
- name: Set up Python | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: '3.8' | ||
- name: Install pypa/setuptools | ||
run: >- | ||
python -m | ||
pip install wheel | ||
- name: Build a binary wheel | ||
run: >- | ||
python setup.py sdist bdist_wheel | ||
- name: Publish distribution 📦 to PyPI | ||
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains 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 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 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,4 @@ | ||
{ | ||
"slurm_profile": "clip", | ||
"slurm_gres": "gpu:1" | ||
} |
This file contains 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,34 @@ | ||
import argparse | ||
from typing import Optional | ||
import torch | ||
from tqdm import trange | ||
|
||
def add_arguments( | ||
parser: Optional[argparse.ArgumentParser] = None, | ||
) -> argparse.ArgumentParser: | ||
if parser is None: | ||
parser = argparse.ArgumentParser('Perform a matrix multiplication on a GPU') | ||
|
||
parser.add_argument("--matrix-size", type=int, default=1000) | ||
parser.add_argument("--n-iter", type=int, default=10) | ||
|
||
return parser | ||
|
||
|
||
def main(args: argparse.Namespace): | ||
# Set torch seed to | ||
torch.manual_seed(42) | ||
|
||
for i in trange(args.n_iter): | ||
M1 = torch.randn(args.matrix_size, args.matrix_size).cuda() | ||
M2 = torch.randn(args.matrix_size, args.matrix_size).cuda() | ||
|
||
result = M1 @ M2 | ||
norm = torch.norm(result, p="fro") | ||
print(f"Norm of result: {norm}") | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = add_arguments() | ||
args = parser.parse_args() | ||
main(args) |
This file contains 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 |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
setuptools.setup( | ||
name="submititnow", | ||
version="0.9.1", | ||
version="0.9.3", | ||
author="Maharshi Gor", | ||
author_email="[email protected]", | ||
description="A package to make submitit easier to use", | ||
|
@@ -26,6 +26,7 @@ | |
"typer[all]>=0.7.0", | ||
"rich-cli>=1.8.0", | ||
"rich>=12.6.0", | ||
"tqdm>=4.0.0", | ||
], | ||
python_requires=">=3.8", | ||
) |
This file contains 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 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,35 +1,128 @@ | ||
import argparse | ||
import json | ||
from typing import Dict, Any | ||
|
||
|
||
class SlurmAdditionalArgAction(argparse.Action): | ||
def __init__(self, check_func, *args, **kwargs): | ||
""" | ||
argparse custom action. | ||
:param check_func: callable to do the real check. | ||
""" | ||
self._check_func = check_func | ||
super(SlurmAdditionalArgAction, self).__init__(*args, **kwargs) | ||
|
||
def __call__(self, parser, namespace, values, option_string): | ||
if isinstance(values, list): | ||
values = [self._check_func(parser, v) for v in values] | ||
else: | ||
values = self._check_func(parser, values) | ||
if option_string.startswith("--"): | ||
option_string = option_string[2:] | ||
setattr(namespace, self.dest, {option_string: values}) | ||
|
||
|
||
def add_slurm_arguments(parser: argparse.ArgumentParser): | ||
slurm_group = parser.add_argument_group("SLURM parameters") | ||
slurm_group.add_argument( | ||
"--slurm_profile", default=None, help="SubmititNow profile for SLURM." | ||
"--config", | ||
default=None, | ||
help="SubmititNow config file for SLURM.", | ||
dest="slurm_config", | ||
) | ||
slurm_group.add_argument( | ||
"--profile", | ||
default=None, | ||
help="SubmititNow profile for SLURM.", | ||
dest="slurm_profile", | ||
) | ||
slurm_group.add_argument( | ||
"--account", default=None, help="SLURM account", dest="slurm_account" | ||
) | ||
slurm_group.add_argument( | ||
"--partition", default=None, help="SLURM partition", dest="slurm_partition" | ||
) | ||
slurm_group.add_argument("--qos", default=None, help="SLURM qos", dest="slurm_qos") | ||
slurm_group.add_argument( | ||
"--mem", default=None, help="SLURM memory requirement", dest="slurm_mem" | ||
) | ||
slurm_group.add_argument( | ||
"--gres", default=None, help="SLURM GPU Resource requirement", dest="slurm_gres" | ||
) | ||
slurm_group.add_argument( | ||
"--time", default=None, help="SLURM time requirement", dest="slurm_time" | ||
) | ||
slurm_group.add_argument( | ||
"--nodes", | ||
default=1, | ||
help="SLURM nodes requirement", | ||
dest="slurm_nodes", | ||
type=int, | ||
) | ||
slurm_group.add_argument( | ||
"--ntasks-per-node", | ||
default=None, | ||
help="SLURM ntasks per node", | ||
dest="slurm_ntasks_per_node", | ||
type=int, | ||
) | ||
slurm_group.add_argument( | ||
"--cpus-per-task", | ||
default=None, | ||
help="SLURM cpus per task", | ||
dest="slurm_cpus_per_task", | ||
type=int, | ||
) | ||
slurm_group.add_argument("--slurm_account", default=None, help="SLURM account") | ||
slurm_group.add_argument("--slurm_partition", default=None, help="SLURM partition") | ||
slurm_group.add_argument("--slurm_qos", default=None, help="SLURM qos") | ||
slurm_group.add_argument( | ||
"--slurm_mem", default=None, help="SLURM memory requirement" | ||
"--cpus-per-gpu", | ||
default=None, | ||
help="SLURM cpus per gpu", | ||
dest="slurm_cpus_per_gpu", | ||
type=int, | ||
) | ||
slurm_group.add_argument( | ||
"--slurm_gres", default=None, help="SLURM GPU Resource requirement" | ||
"--gpus-per-node", | ||
default=None, | ||
help="SLURM gpus per node", | ||
dest="slurm_gpus_per_node", | ||
type=int, | ||
) | ||
slurm_group.add_argument( | ||
"--slurm_time", default=None, help="SLURM time requirement" | ||
"--gpus-per-task", | ||
default=None, | ||
help="SLURM gpus per task", | ||
dest="slurm_gpus_per_task", | ||
type=int, | ||
) | ||
|
||
# Additional arguments | ||
slurm_group.add_argument( | ||
"--nodelist", | ||
default=None, | ||
help="SLURM nodelist", | ||
action=SlurmAdditionalArgAction, | ||
check_func=lambda parser, value: value, | ||
dest="slurm_additional_parameters", | ||
) | ||
return parser | ||
|
||
|
||
def add_submititnow_arguments(parser: argparse.ArgumentParser): | ||
submititnow_group = parser.add_argument_group("SubmititNow parameters") | ||
submititnow_group.add_argument("--exp_name", default=None, help="Experiment Name.") | ||
submititnow_group.add_argument("--exp-name", default=None, help="Experiment Name.") | ||
submititnow_group.add_argument( | ||
"--submititnow_dir", default=None, help="Root directory for submititnow." | ||
"--submititnow-dir", default=None, help="Root directory for submititnow." | ||
) | ||
return parser | ||
|
||
|
||
def get_slurm_params(args: argparse.Namespace) -> Dict[str, Any]: | ||
return {k: v for k, v in vars(args).items() if k.startswith("slurm_")} | ||
slurm_args = { | ||
k: v for k, v in vars(args).items() if k.startswith("slurm_") and v is not None | ||
} | ||
if slurm_args.get("slurm_config") is not None: | ||
config_filename = slurm_args.pop("slurm_config") | ||
with open(config_filename, "r") as f: | ||
default_args = json.load(f) | ||
slurm_args = {**default_args, **slurm_args} | ||
return slurm_args |