mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
This is one of a series of PRs to update us to PEP585 (changing Dict -> dict, List -> list, etc). Most of the PRs were completely automated with RUFF as follows: Since RUFF UP006 is considered an "unsafe" fix first we need to enable unsafe fixes: ``` --- a/tools/linter/adapters/ruff_linter.py +++ b/tools/linter/adapters/ruff_linter.py @@ -313,6 +313,7 @@ "ruff", "check", "--fix-only", + "--unsafe-fixes", "--exit-zero", *([f"--config={config}"] if config else []), "--stdin-filename", ``` Then we need to tell RUFF to allow UP006 (as a final PR once all of these have landed this will be made permanent): ``` --- a/pyproject.toml +++ b/pyproject.toml @@ -40,7 +40,7 @@ [tool.ruff] -target-version = "py38" +target-version = "py39" line-length = 88 src = ["caffe2", "torch", "torchgen", "functorch", "test"] @@ -87,7 +87,6 @@ "SIM116", # Disable Use a dictionary instead of consecutive `if` statements "SIM117", "SIM118", - "UP006", # keep-runtime-typing "UP007", # keep-runtime-typing ] select = [ ``` Finally running `lintrunner -a --take RUFF` will fix up the deprecated uses. Pull Request resolved: https://github.com/pytorch/pytorch/pull/145101 Approved by: https://github.com/bobrenjc93
64 lines
1.8 KiB
Python
64 lines
1.8 KiB
Python
import glob
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Any
|
|
|
|
|
|
REPO_ROOT = Path(__file__).resolve().parent.parent.parent
|
|
|
|
|
|
def flatten_data(d: dict[str, Any]) -> dict[str, Any]:
|
|
# Flatten the sccache stats data from a possibly nested dictionary to a flat
|
|
# dictionary. For example, the input:
|
|
# {
|
|
# "cache": {
|
|
# "hit": 1,
|
|
# "miss": 2,
|
|
# },
|
|
# }
|
|
# will be transformed to:
|
|
# {
|
|
# "cache_hit": 1,
|
|
# "cache_miss": 2,
|
|
# }
|
|
flat_data = {}
|
|
for key, value in d.items():
|
|
if isinstance(value, dict):
|
|
for k, v in flatten_data(value).items():
|
|
flat_data[f"{key}_{k}"] = v
|
|
else:
|
|
flat_data[key] = value
|
|
return flat_data
|
|
|
|
|
|
def main() -> None:
|
|
records = []
|
|
for file in glob.glob(str(REPO_ROOT / "sccache-stats-*.json")):
|
|
with open(file) as f:
|
|
data = json.load(f)
|
|
|
|
# I don't know what sccache info will be most useful yet, and the
|
|
# sccache json has a decent number of keys, so just flatten the data
|
|
# and store all of it
|
|
records.append(
|
|
{
|
|
"benchmark": {
|
|
"name": "sccache_stats",
|
|
},
|
|
"metric": {
|
|
"name": "sccache_stats",
|
|
"benchmark_values": [int(os.environ.get("BUILD_TIME") or 0)],
|
|
"extra_info": flatten_data(data),
|
|
},
|
|
}
|
|
)
|
|
output_file = REPO_ROOT / "test" / "test-reports" / "sccache-stats.json"
|
|
os.makedirs(output_file.parent, exist_ok=True)
|
|
with open(output_file, "w") as f:
|
|
json.dump(records, f)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|