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

Function parse_mlx_flatbuffer

backends/mlx/pte_inspector.py:258–291  ·  view source on GitHub ↗

Parse MLX FlatBuffer data into a dict using the generated FlatBuffer bindings.

(fb_data: bytes)

Source from the content-addressed store, hash-verified

256
257
258def parse_mlx_flatbuffer(fb_data: bytes) -> Dict[str, Any]:
259 """Parse MLX FlatBuffer data into a dict using the generated FlatBuffer bindings."""
260 result: Dict[str, Any] = {}
261 try:
262 graph = _get_fb_graph(fb_data)
263
264 result = _parse_graph_info(graph)
265 result["instruction_chains"] = _parse_instructions(graph)
266 result["named_slots"] = _parse_named_slots(graph)
267 result["tensor_meta"] = _parse_tensor_meta(graph)
268
269 input_map, output_map, mutable_buffer_map = _parse_io_maps(graph)
270 result["input_map"] = input_map
271 result["output_map"] = output_map
272 result["mutable_buffer_map"] = mutable_buffer_map
273
274 try:
275 cs = graph.ConstantSegment()
276 if cs:
277 result["constant_segment"] = {
278 "offset": cs.Offset(),
279 "size": cs.Size(),
280 }
281 except Exception as e:
282 result["constant_segment_error"] = f"parse_failed: {e}"
283
284 except ImportError as e:
285 result["error"] = f"FlatBuffer bindings not available: {e}"
286 result["_fallback"] = "Using basic header parsing only"
287 except Exception as e:
288 result["error"] = f"FlatBuffer parse error: {e}"
289 result["traceback"] = traceback.format_exc()
290
291 return result
292
293
294def _parse_op_node(instr, op_name: str) -> Optional[Dict[str, Any]]:

Callers 3

parse_mlx_payloadFunction · 0.85
show_mlx_summaryFunction · 0.85
show_mlx_instructionsFunction · 0.85

Calls 9

_get_fb_graphFunction · 0.85
_parse_graph_infoFunction · 0.85
_parse_instructionsFunction · 0.85
_parse_named_slotsFunction · 0.85
_parse_tensor_metaFunction · 0.85
_parse_io_mapsFunction · 0.85
ConstantSegmentMethod · 0.80
OffsetMethod · 0.45
SizeMethod · 0.45

Tested by

no test coverage detected