[export] Generate compatible thrift schema out of schema.py (#141611)

Summary: To make sure schema.py and schema.thrift are kept in sync, we use the int keys from thrift and use Python Annotated type to associate fields between thrift and schema.py. Later we will use this association to build a single source of truth between the schemas.

Test Plan: CI

Differential Revision: D66253157

Pull Request resolved: https://github.com/pytorch/pytorch/pull/141611
Approved by: https://github.com/yiming0416
This commit is contained in:
Zhengxu Chen
2024-11-29 20:09:49 +00:00
committed by PyTorch MergeBot
parent 7dd9b5fc43
commit a8a570512b
6 changed files with 575 additions and 163 deletions

View File

@ -72,6 +72,10 @@ if __name__ == "__main__":
yaml_content = yaml_header + "\n" + yaml_payload
thrift_schema = "// " + first_line
thrift_schema += "\n// " + checksum
thrift_schema += "\n" + commit.thrift_schema
if args.dry_run:
print(yaml_content)
print("\nWill write the above schema to" + args.prefix + commit.yaml_path)
@ -80,3 +84,5 @@ if __name__ == "__main__":
f.write(yaml_content)
with open(args.prefix + commit.cpp_header_path, "w") as f:
f.write(cpp_header)
with open(args.prefix + commit.thrift_schema_path, "w") as f:
f.write(thrift_schema)