Skip to content

Add SGLang MACA runtime preload path handling - #2

Open
ghangz wants to merge 3 commits into
MetaX-MACA:mainfrom
ghangz:mengz/maca-runtime-preload-paths
Open

Add SGLang MACA runtime preload path handling#2
ghangz wants to merge 3 commits into
MetaX-MACA:mainfrom
ghangz:mengz/maca-runtime-preload-paths

Conversation

@ghangz

@ghangz ghangz commented Jun 25, 2026

Copy link
Copy Markdown

Summary

  • This change improves MACA runtime preload path handling for SGLang kernel loading, making missing or duplicate runtime library paths easier to diagnose in MetaX GPU validation containers.
  • The implementation is scoped to diagnostics and runtime setup paths used by MetaX MACA validation, so existing non-MACA behavior remains compatible.
  • Main files: sgl-kernel/python/sgl_kernel/load_utils.py, test/registered/unit/kernels/test_load_utils_maca.py

Validation

  • Verified on Gitee.AI MetaX GPU resources in the SGLang/PyTorch MACA validation batch.
  • Branch validation command: python -m pytest test/registered/unit/kernels/test_load_utils_maca.py
  • Pull request text is ASCII-only to avoid encoding issues on web forms and API clients.

Review notes

  • Source branch: ghangz:mengz/maca-runtime-preload-paths
  • Target branch: MetaX-MACA/sglang:main
  • Maintainers can modify this branch if follow-up adjustments are needed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request cleans up debug log messages by removing unicode checkmarks and crosses, and introduces support for the MACA architecture (via the MACA_PATH environment variable) in CUDA home detection and runtime library preloading. It also adds unit tests to verify these new MACA-specific paths. The review feedback suggests converting cuda_home to a Path object internally within _candidate_runtime_library_dirs for robustness, and avoiding the use of clear=True in patch.dict during unit tests to prevent clearing essential environment variables like PATH and PYTHONPATH.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +220 to 225
def _candidate_runtime_library_dirs(cuda_home: Path):
maca_home = os.environ.get("MACA_PATH")
candidate_dirs = [
cuda_home / "lib",
cuda_home / "lib64",
Path("/usr/lib/x86_64-linux-gnu"),
Path("/usr/lib/aarch64-linux-gnu"),
Path("/usr/lib64"),
Path("/usr/lib"),
]

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To make the function more robust and adhere to defensive programming practices, convert cuda_home to a Path object internally. This prevents potential runtime TypeErrors if a string is passed instead of a Path object.

def _candidate_runtime_library_dirs(cuda_home: Path):
    maca_home = os.environ.get("MACA_PATH")
    cuda_home = Path(cuda_home)
    candidate_dirs = [
        cuda_home / "lib",
        cuda_home / "lib64",
    ]

def test_find_cuda_home_uses_maca_cu_bridge(self):
with TemporaryDirectory() as tmp_dir:
maca_path = Path(tmp_dir) / "maca"
with patch.dict(os.environ, {"MACA_PATH": str(maca_path)}, clear=True):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using clear=True in patch.dict clears the entire environment, including essential variables like PATH and PYTHONPATH. This can cause unexpected side effects or failures in some test environments. A safer approach is to copy os.environ, explicitly remove CUDA_HOME and CUDA_PATH, set MACA_PATH, and then patch with clear=True using this complete dictionary.

Suggested change
with patch.dict(os.environ, {"MACA_PATH": str(maca_path)}, clear=True):
test_env = os.environ.copy()
test_env.pop("CUDA_HOME", None)
test_env.pop("CUDA_PATH", None)
test_env["MACA_PATH"] = str(maca_path)
with patch.dict(os.environ, test_env, clear=True):

with TemporaryDirectory() as tmp_dir:
maca_path = Path(tmp_dir) / "maca"
cuda_home = maca_path / "tools" / "cu-bridge"
with patch.dict(os.environ, {"MACA_PATH": str(maca_path)}, clear=True):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using clear=True in patch.dict clears the entire environment, including essential variables like PATH and PYTHONPATH. This can cause unexpected side effects or failures in some test environments. A safer approach is to copy os.environ, explicitly remove CUDA_HOME and CUDA_PATH, set MACA_PATH, and then patch with clear=True using this complete dictionary.

Suggested change
with patch.dict(os.environ, {"MACA_PATH": str(maca_path)}, clear=True):
test_env = os.environ.copy()
test_env.pop("CUDA_HOME", None)
test_env.pop("CUDA_PATH", None)
test_env["MACA_PATH"] = str(maca_path)
with patch.dict(os.environ, test_env, clear=True):

@ghangz ghangz changed the title 支持配置 MACA 运行时预加载路径 ?? MACA ?????????? Jun 26, 2026
@ghangz ghangz changed the title ?? MACA ?????????? 强化 MACA 运行时预加载路径解析 Jun 26, 2026
@ghangz ghangz changed the title 强化 MACA 运行时预加载路径解析 Add SGLang MACA runtime preload path handling Jul 1, 2026
- Support MACA runtime preload paths
- harden MACA runtime preload helpers
- Preserve environment in MACA load utils tests
- Isolate MACA load utils environment tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant