-
Notifications
You must be signed in to change notification settings - Fork 77
Support: record torch backend autoload state #1977
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
Merged
ChaoZheng109
merged 1 commit into
hw-native-sys:main
from
Crane-Liu:codex/record-torch-backend-autoload-1950
Aug 27, 2026
Merged
Changes from all commits
Commits
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
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
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
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
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
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,69 @@ | ||
| # 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. | ||
| # ----------------------------------------------------------------------------------------------------------- | ||
| """Tests for torch backend autoload state in bind-phase reports.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
|
|
||
| from simpler_setup.tools import hbg_bind_phases | ||
|
|
||
|
|
||
| def _write_log(path, autoload_records: tuple[str, ...]) -> None: | ||
| lines = ["[stamp] command commit=abc"] | ||
| lines.extend(f"TIMING simpler: {record}" for record in autoload_records) | ||
| lines.extend( | ||
| [ | ||
| "bind phase=host_orch start_ns=1 dur_ns=1000000", | ||
| "bind phase=arena_h2d start_ns=2 dur_ns=1000000", | ||
| "bind phase=host_orch start_ns=3 dur_ns=500000", | ||
| "bind phase=arena_h2d start_ns=4 dur_ns=500000", | ||
| ] | ||
| ) | ||
| path.write_text("\n".join(lines) + "\n", encoding="utf-8") | ||
|
|
||
|
|
||
| def test_report_shows_each_torch_autoload_state(tmp_path, monkeypatch, capsys): | ||
| log = tmp_path / "run.log" | ||
| first = ( | ||
| 'torch_backend_autoload setting=invalid raw="a b\\"c" raw_truncated=false ' | ||
| "effective=disabled torch_imported=true torch_npu_loaded=false" | ||
| ) | ||
| second = ( | ||
| 'torch_backend_autoload setting=1 raw="1" raw_truncated=false ' | ||
| "effective=enabled torch_imported=true torch_npu_loaded=true" | ||
| ) | ||
| _write_log(log, (first, first, second)) | ||
| monkeypatch.setattr(sys, "argv", ["hbg_bind_phases", str(log), "--rounds", "2"]) | ||
|
|
||
| assert hbg_bind_phases.main() == 0 | ||
|
|
||
| output = capsys.readouterr().out | ||
| assert output.count(first) == 1 | ||
| assert output.count(second) == 1 | ||
|
|
||
|
|
||
| def test_report_warns_when_torch_autoload_state_is_missing(tmp_path, monkeypatch, capsys): | ||
| log = tmp_path / "run.log" | ||
| _write_log(log, ()) | ||
| monkeypatch.setattr(sys, "argv", ["hbg_bind_phases", str(log), "--rounds", "2"]) | ||
|
|
||
| assert hbg_bind_phases.main() == 0 | ||
|
|
||
| output = capsys.readouterr().out | ||
| assert "no `torch_backend_autoload` record" in output | ||
| assert "must be established before comparing" in output | ||
|
|
||
|
|
||
| def test_parser_accepts_record_without_raw_fields(tmp_path): | ||
| log = tmp_path / "run.log" | ||
| record = "torch_backend_autoload setting=0 effective=disabled torch_imported=true torch_npu_loaded=false" | ||
| _write_log(log, (record,)) | ||
|
|
||
| assert hbg_bind_phases.parse_torch_autoload(str(log)) == [record] |
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.
Uh oh!
There was an error while loading. Please reload this page.