-
Notifications
You must be signed in to change notification settings - Fork 28
Add: HF compare testing framework for Qwen3-14B model validation #184
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
wangqin1723-max
wants to merge
3
commits into
hw-native-sys:main
Choose a base branch
from
wangqin1723-max:feat/hf-compare-framework
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.
Open
Changes from all commits
Commits
Show all changes
3 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,9 @@ | ||
| # Copyright (c) PyPTO Contributors. | ||
| # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| # CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| # Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| # See LICENSE in the root of the software repository for the full text of the License. | ||
| # ----------------------------------------------------------------------------------------------------------- | ||
| """Testing utilities for pypto-lib (accuracy comparison, regression harnesses, ...).""" |
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,59 @@ | ||
| # Copyright (c) PyPTO Contributors. | ||
| # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| # CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| # Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| # See LICENSE in the root of the software repository for the full text of the License. | ||
| # ----------------------------------------------------------------------------------------------------------- | ||
| """Hugging Face comparison framework. | ||
|
|
||
| This package provides a pluggable harness for verifying that PyPTO kernels / | ||
| scopes / end-to-end models produce numerically equivalent outputs to a | ||
| reference implementation (typically a Hugging Face module on CPU). | ||
|
|
||
| Top-level entry points: | ||
|
|
||
| from llm.testing.hf_compare import ( | ||
| ComparisonCase, register_case, get_case, list_cases, | ||
| ) | ||
|
|
||
| Cases live under ``llm/testing/hf_compare/cases/`` and are registered with | ||
| ``@register_case("model.scope")``. The CLI in ``__main__.py`` discovers them | ||
| by name. | ||
| """ | ||
| from .base import ( | ||
| ChainStep, | ||
| ChainedComparisonCase, | ||
| CompareReport, | ||
| ComparisonCase, | ||
| InputSpec, | ||
| OutputSelector, | ||
| ReferenceModel, | ||
| SelectorResult, | ||
| TargetModel, | ||
| TensorSpec, | ||
| Tolerance, | ||
| WeightAdapter, | ||
| get_case, | ||
| list_cases, | ||
| register_case, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| "ChainStep", | ||
| "ChainedComparisonCase", | ||
| "CompareReport", | ||
| "ComparisonCase", | ||
| "InputSpec", | ||
| "OutputSelector", | ||
| "ReferenceModel", | ||
| "SelectorResult", | ||
| "TargetModel", | ||
| "TensorSpec", | ||
| "Tolerance", | ||
| "WeightAdapter", | ||
| "get_case", | ||
| "list_cases", | ||
| "register_case", | ||
| ] |
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,66 @@ | ||
| # Copyright (c) PyPTO Contributors. | ||
| # This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| # CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| # Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| # THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| # INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| # See LICENSE in the root of the software repository for the full text of the License. | ||
| # ----------------------------------------------------------------------------------------------------------- | ||
| """CLI for the HF comparison framework. | ||
|
|
||
| Usage: | ||
| python -m llm.testing.hf_compare list | ||
| python -m llm.testing.hf_compare run qwen3_14b.decode \\ | ||
| --hf-model-path /path/to/Qwen3-14B --platform a2a3 [--cpu-only] | ||
| """ | ||
| from __future__ import annotations | ||
|
|
||
| import argparse | ||
| import json | ||
| import sys | ||
|
|
||
| from .base import get_case, list_cases | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser(prog="hf_compare") | ||
| sub = parser.add_subparsers(dest="cmd", required=True) | ||
|
|
||
| sub.add_parser("list", help="List registered cases.") | ||
|
|
||
| run = sub.add_parser("run", help="Run one case.") | ||
| run.add_argument("case", help="Registered case name (see `list`).") | ||
| run.add_argument("--json", action="store_true", help="Print JSON report.") | ||
| run.add_argument( | ||
| "--kwarg", "-k", action="append", default=[], | ||
| help="Extra kwarg for the case factory, e.g. -k hf_model_path=/data/...", | ||
| ) | ||
|
|
||
| args = parser.parse_args(argv) | ||
| # Autodiscovery is lazy: list_cases() / get_case() trigger it internally. | ||
|
|
||
| if args.cmd == "list": | ||
| for name in list_cases(): | ||
| print(name) | ||
| return 0 | ||
|
|
||
| if args.cmd == "run": | ||
| kwargs: dict[str, str] = {} | ||
| for kv in args.kwarg: | ||
| if "=" not in kv: | ||
| parser.error(f"--kwarg must be key=value, got {kv!r}") | ||
| k, v = kv.split("=", 1) | ||
| kwargs[k] = v | ||
| case = get_case(args.case, **kwargs) | ||
| report = case.run() | ||
| if args.json: | ||
| print(json.dumps(report.to_json(), indent=2)) | ||
| else: | ||
| print(report.summary()) | ||
| return 0 if report.passed else 1 | ||
|
|
||
| return 2 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main()) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Module docstring advertises CLI flags that don't exist.
The example shows
--hf-model-path,--platform, and--cpu-only, but therunsubparser only registerscase,--json, and--kwarg/-k. Anyone copy-pasting this command will geterror: unrecognized arguments. The PR test plan correctly uses-k hf_model_path=... -k cpu_only=true, so update the docstring to match.📝 Suggested docstring fix
"""CLI for the HF comparison framework. Usage: python -m llm.testing.hf_compare list - python -m llm.testing.hf_compare run qwen3_14b.decode \\ - --hf-model-path /path/to/Qwen3-14B --platform a2a3 [--cpu-only] + python -m llm.testing.hf_compare run qwen3_14b.decode \\ + -k hf_model_path=/path/to/Qwen3-14B -k platform=a2a3 [-k cpu_only=true] """🤖 Prompt for AI Agents