MCPcopy Create free account
hub / github.com/pytorch/executorch / convert_to_flatbuffer

Function convert_to_flatbuffer

devtools/bundled_program/serialize/__init__.py:50–63  ·  view source on GitHub ↗
(program_json: str)

Source from the content-addressed store, hash-verified

48
49
50def convert_to_flatbuffer(program_json: str) -> bytes:
51 with tempfile.TemporaryDirectory() as d:
52 # load given and common schema
53 write_schema(d, BUNDLED_PROGRAM_SCHEMA_NAME)
54 write_schema(d, SCALAR_TYPE_SCHEMA_NAME)
55
56 schema_path = os.path.join(d, "{}.fbs".format(BUNDLED_PROGRAM_SCHEMA_NAME))
57 json_path = os.path.join(d, "{}.json".format(BUNDLED_PROGRAM_SCHEMA_NAME))
58 with open(json_path, "wb") as json_file:
59 json_file.write(program_json.encode("ascii"))
60 _flatc_compile(d, schema_path, json_path)
61 output_path = os.path.join(d, "{}.bpte".format(BUNDLED_PROGRAM_SCHEMA_NAME))
62 with open(output_path, "rb") as output_file:
63 return output_file.read()
64
65
66def convert_from_flatbuffer(program_flatbuffer: bytes) -> bytes:

Calls 4

_flatc_compileFunction · 0.90
write_schemaFunction · 0.85
writeMethod · 0.80
encodeMethod · 0.45

Tested by

no test coverage detected