[BE] Remove outdated script to check namespace BC (#151453)

Now that we have bc_lint in CI, this script is no longer needed (nor has it ever been conclusive). I've already updated the Runbook to not need this script.

Suppressing bc_lint as this script is not shipped as a part of torch--it is not user facing! For context, this script is (rarely) used by the release notes manager to ensure BC across releases. It had been broken for at least since 2.6.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/151453
Approved by: https://github.com/albanD, https://github.com/jbschlosser
This commit is contained in:
Jane Xu
2025-04-16 07:58:42 -07:00
committed by PyTorch MergeBot
parent 90c5b86cd8
commit 4843ce7611

View File

@ -1,131 +0,0 @@
import argparse
import json
from os import path
import torch
# Import all utils so that getattr below can find them
all_submod_list = [
"",
"nn",
"nn.functional",
"nn.init",
"optim",
"autograd",
"cuda",
"sparse",
"distributions",
"fft",
"linalg",
"jit",
"distributed",
"futures",
"onnx",
"random",
"utils.bottleneck",
"utils.checkpoint",
"utils.data",
"utils.model_zoo",
]
def get_content(submod):
mod = torch
if submod:
submod = submod.split(".")
for name in submod:
mod = getattr(mod, name)
content = dir(mod)
return content
def namespace_filter(data):
out = {d for d in data if d[0] != "_"}
return out
def run(args, submod):
print(f"## Processing torch.{submod}")
prev_filename = f"prev_data_{submod}.json"
new_filename = f"new_data_{submod}.json"
if args.prev_version:
content = get_content(submod)
with open(prev_filename, "w") as f:
json.dump(content, f)
print("Data saved for previous version.")
elif args.new_version:
content = get_content(submod)
with open(new_filename, "w") as f:
json.dump(content, f)
print("Data saved for new version.")
else:
assert args.compare
if not path.exists(prev_filename):
raise RuntimeError("Previous version data not collected")
if not path.exists(new_filename):
raise RuntimeError("New version data not collected")
with open(prev_filename) as f:
prev_content = set(json.load(f))
with open(new_filename) as f:
new_content = set(json.load(f))
if not args.show_all:
prev_content = namespace_filter(prev_content)
new_content = namespace_filter(new_content)
if new_content == prev_content:
print("Nothing changed.")
print("")
else:
print("Things that were added:")
print(new_content - prev_content)
print("")
print("Things that were removed:")
print(prev_content - new_content)
print("")
def main():
parser = argparse.ArgumentParser(
description="Tool to check namespace content changes"
)
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("--prev-version", action="store_true")
group.add_argument("--new-version", action="store_true")
group.add_argument("--compare", action="store_true")
group = parser.add_mutually_exclusive_group()
group.add_argument("--submod", default="", help="part of the submodule to check")
group.add_argument(
"--all-submod",
action="store_true",
help="collects data for all main submodules",
)
parser.add_argument(
"--show-all",
action="store_true",
help="show all the diff, not just public APIs",
)
args = parser.parse_args()
if args.all_submod:
submods = all_submod_list
else:
submods = [args.submod]
for mod in submods:
run(args, mod)
if __name__ == "__main__":
main()