Parse MLX FlatBuffer data into a dict using the generated FlatBuffer bindings.
(fb_data: bytes)
| 256 | |
| 257 | |
| 258 | def 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 | |
| 294 | def _parse_op_node(instr, op_name: str) -> Optional[Dict[str, Any]]: |
no test coverage detected