-
Notifications
You must be signed in to change notification settings - Fork 4
增加算子库构建计划结构化输出 #35
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
Open
ghangz
wants to merge
2
commits into
MetaX-MACA:main
Choose a base branch
from
ghangz:mengz/mcoplib-build-plan-json
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+112
−0
Open
增加算子库构建计划结构化输出 #35
Changes from all commits
Commits
Show all changes
2 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
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,72 @@ | ||
| #!/usr/bin/env python3 | ||
| """Print a non-invasive mcoplib build plan as JSON.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
| import shutil | ||
| from pathlib import Path | ||
|
|
||
|
|
||
| SUBMODULE_FLAGS = [ | ||
| "BUILD_VLLM_SUBMODULE", | ||
| "BUILD_SGLANG_SUBMODULE", | ||
| "BUILD_LMDEPLOY_SUBMODULE", | ||
| "BUILD_DEFAULT_OP_SUBMODULE", | ||
| "BUILD_MOE_SUBMODULE", | ||
| "BUILD_SGL_KERNEL_SUBMODULE", | ||
| "BUILD_SGL_GROUPED_GEMM_SUBMODULE", | ||
| "BUILD_SGL_MOE_W4A16_SUBMODULE", | ||
| ] | ||
|
|
||
|
|
||
| def read_maca_version(maca_path: str | None) -> str | None: | ||
| if not maca_path: | ||
| return None | ||
| version_file = Path(maca_path) / "Version.txt" | ||
| if not version_file.is_file(): | ||
| return None | ||
| lines = version_file.read_text(encoding="utf-8").splitlines() | ||
| return lines[0].split(":")[-1].strip() if lines else None | ||
|
|
||
|
|
||
| def build_plan(root: Path) -> dict[str, object]: | ||
| maca_path = os.environ.get("MACA_PATH") | ||
| return { | ||
| "root": str(root), | ||
| "maca_path": maca_path, | ||
| "maca_version": read_maca_version(maca_path), | ||
| "tools": { | ||
| "cmake_maca": shutil.which("cmake_maca"), | ||
| "make_maca": shutil.which("make_maca"), | ||
| "mxcc": shutil.which("mxcc"), | ||
| "ninja": shutil.which("ninja"), | ||
| }, | ||
| "submodules": {flag: os.environ.get(flag, "ON") for flag in SUBMODULE_FLAGS}, | ||
| "cache": { | ||
| "FETCHCONTENT_BASE_DIR": os.environ.get( | ||
| "FETCHCONTENT_BASE_DIR", str(root / ".deps") | ||
| ) | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def main() -> int: | ||
| parser = argparse.ArgumentParser(description="Print mcoplib build plan JSON.") | ||
| parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[1]) | ||
| parser.add_argument("--output", type=Path) | ||
| args = parser.parse_args() | ||
|
|
||
| text = json.dumps(build_plan(args.root.resolve()), indent=2, sort_keys=True) | ||
| if args.output: | ||
| args.output.parent.mkdir(parents=True, exist_ok=True) | ||
| args.output.write_text(text + "\n", encoding="utf-8") | ||
| else: | ||
| print(text) | ||
| return 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| raise SystemExit(main()) | ||
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,40 @@ | ||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||
| import tempfile | ||||||||||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||||||||||
| from pathlib import Path | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| sys.path.insert(0, str(Path(__file__).resolve().parents[1])) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| from tools.build_plan import build_plan, read_maca_version | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| class BuildPlanTest(unittest.TestCase): | ||||||||||||||||||||||||||||||||||||
| def test_read_maca_version(self): | ||||||||||||||||||||||||||||||||||||
| with tempfile.TemporaryDirectory() as tmp: | ||||||||||||||||||||||||||||||||||||
| Path(tmp, "Version.txt").write_text("Version:3.5.3.20\n", encoding="utf-8") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(read_maca_version(tmp), "3.5.3.20") | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
+14
to
+17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议为
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Path(tmp, "Version.txt").write_text("", encoding="utf-8") | ||||||||||||||||||||||||||||||||||||
| self.assertIsNone(read_maca_version(tmp)) | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Path(tmp, "Version.txt").write_text("Version3.5.3.20\n", encoding="utf-8") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(read_maca_version(tmp), "Version3.5.3.20") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| def test_build_plan_uses_default_submodule_flags(self): | ||||||||||||||||||||||||||||||||||||
| root = Path.cwd() | ||||||||||||||||||||||||||||||||||||
| old = os.environ.pop("BUILD_DEFAULT_OP_SUBMODULE", None) | ||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||
| plan = build_plan(root) | ||||||||||||||||||||||||||||||||||||
| finally: | ||||||||||||||||||||||||||||||||||||
| if old is not None: | ||||||||||||||||||||||||||||||||||||
| os.environ["BUILD_DEFAULT_OP_SUBMODULE"] = old | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| self.assertEqual(plan["submodules"]["BUILD_DEFAULT_OP_SUBMODULE"], "ON") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(plan["submodules"]["BUILD_VLLM_SUBMODULE"], "ON") | ||||||||||||||||||||||||||||||||||||
| self.assertEqual(plan["submodules"]["BUILD_SGLANG_SUBMODULE"], "ON") | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| if __name__ == "__main__": | ||||||||||||||||||||||||||||||||||||
| unittest.main() | ||||||||||||||||||||||||||||||||||||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
在
CMakeLists.txt中,BUILD_VLLM_SUBMODULE和BUILD_SGLANG_SUBMODULE是两个非常关键的子模块构建选项(分别在第 135 行和第 136 行定义)。然而,它们在SUBMODULE_FLAGS列表中被遗漏了。建议将它们加入到
SUBMODULE_FLAGS中,以确保构建计划输出的完整性。