Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions deepspeed/ops/transformer/inference/triton/matmul_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ def is_nfs_path(path):
break
path = parent

# Use the 'df' command to find the file system type for the given path
# POSIX output keeps long device names from wrapping onto a separate line.
try:
output = subprocess.check_output(['df', '-T', path], encoding='utf-8', stderr=subprocess.DEVNULL)
output = subprocess.check_output(['df', '-PT', path], encoding='utf-8', stderr=subprocess.DEVNULL)
except (subprocess.CalledProcessError, FileNotFoundError):
return False # Command failed or 'df' not available

# Process the output of 'df -T' to check for 'nfs' in the filesystem type column
# Process the output of 'df -PT' to check for 'nfs' in the filesystem type column.
lines = output.strip().split('\n')
if len(lines) > 1: # The first line is headers
fs_type = lines[1].split()[1].lower() # File system type is the second column
return 'nfs' in fs_type
fields = lines[1].split()
if len(fields) > 1:
return 'nfs' in fields[1].lower()
return False


Expand Down
36 changes: 36 additions & 0 deletions tests/unit/ops/transformer/inference/test_matmul_ext.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: Apache-2.0

# DeepSpeed Team

import ast
import os
import subprocess
from pathlib import Path
from typing import Callable, cast
from unittest.mock import patch

MATMUL_EXT_PATH = Path(
__file__).resolve().parents[5] / "deepspeed" / "ops" / "transformer" / "inference" / "triton" / "matmul_ext.py"


def load_is_nfs_path() -> Callable[[Path], bool]:
tree = ast.parse(MATMUL_EXT_PATH.read_text(), filename=str(MATMUL_EXT_PATH))
function = next(node for node in tree.body if isinstance(node, ast.FunctionDef) and node.name == "is_nfs_path")
module = ast.Module(body=[function], type_ignores=[])
namespace = {"os": os, "subprocess": subprocess}
exec(compile(module, str(MATMUL_EXT_PATH), "exec"), namespace)
return cast(Callable[[Path], bool], namespace["is_nfs_path"])


def test_is_nfs_path_handles_wrapped_device_name(tmp_path):
is_nfs_path = load_is_nfs_path()
busybox_output = """Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/dvol0123456789abcdef0
ext4 2112647088 3439616 2109191088 0% /mount
"""

with patch.object(subprocess, "check_output", return_value=busybox_output) as check_output:
assert not is_nfs_path(tmp_path)

check_output.assert_called_once_with(['df', '-PT', str(tmp_path)], encoding='utf-8', stderr=subprocess.DEVNULL)
Loading