Skip to content

Commit 20379ad

Browse files
Add route to modify megatron fused kernel build path (#1383)
* Add arg to configure build path * cleanup and formatting --------- Co-authored-by: Quentin Anthony <qganthony@yahoo.com>
1 parent 8b18e28 commit 20379ad

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

configs/neox_arguments.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,14 @@ Model Arguments
684684
685685
686686
687+
- **fused_kernels_build_path**: typing.Optional[str]
688+
689+
Default = None
690+
691+
Optional override for the fused kernels build directory. If unset, defaults to `megatron/fused_kernels/build` relative to the package.
692+
693+
694+
687695
- **fp16_lm_cross_entropy**: bool
688696
689697
Default = False
@@ -2615,4 +2623,3 @@ Args for deepspeed runner (deepspeed.launcher.runner).
26152623
Default = None
26162624
26172625
Adds a `--account` to the DeepSpeed launch command. In DeeperSpeed this is passed on to the SlurmLauncher as well. Sometimes necessary for cluster rules, or so I've heard.
2618-

megatron/fused_kernels/__init__.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def load(neox_args=None):
5858

5959
# Build path
6060
srcpath = pathlib.Path(__file__).parent.absolute()
61-
buildpath = srcpath / "build"
61+
buildpath = _get_build_path(neox_args=neox_args)
6262
_create_build_dir(buildpath)
6363

6464
# Determine verbosity
@@ -156,12 +156,23 @@ def _get_cuda_bare_metal_version(cuda_dir):
156156
return raw_output, bare_metal_major, bare_metal_minor
157157

158158

159+
def _get_build_path(neox_args=None):
160+
if neox_args is not None:
161+
fused_kernels_build_path = getattr(neox_args, "fused_kernels_build_path", None)
162+
if fused_kernels_build_path is not None:
163+
return pathlib.Path(fused_kernels_build_path).expanduser().resolve()
164+
165+
srcpath = pathlib.Path(__file__).parent.absolute()
166+
return srcpath / "build"
167+
168+
159169
def _create_build_dir(buildpath):
160170
try:
161-
os.mkdir(buildpath)
162-
except OSError:
163-
if not os.path.isdir(buildpath):
164-
print(f"Creation of the build directory {buildpath} failed")
171+
pathlib.Path(buildpath).mkdir(parents=True, exist_ok=True)
172+
except OSError as e:
173+
raise RuntimeError(
174+
f"Creation of the build directory {buildpath} failed: {e}"
175+
) from e
165176

166177

167178
def load_fused_kernels():

megatron/neox_arguments/neox_args.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ class NeoXArgsModel(NeoXArgsTemplate):
339339
Enable rotary embedding fusion.
340340
"""
341341

342+
fused_kernels_build_path: Optional[str] = None
343+
"""
344+
Optional override for the fused kernels build directory. If unset, defaults to `megatron/fused_kernels/build` relative to the package.
345+
"""
346+
342347
fp16_lm_cross_entropy: bool = False
343348
"""
344349
Move the cross entropy unreduced loss calculation for lm head to fp16.

0 commit comments

Comments
 (0)