|
9 | 9 |
|
10 | 10 | import copy |
11 | 11 | import json |
12 | | -import logging |
13 | 12 | import math |
14 | 13 | import re |
15 | 14 |
|
|
21 | 20 | from executorch.exir._serialize._flatbuffer import ( |
22 | 21 | _FlatbufferResult, |
23 | 22 | _program_flatbuffer_to_json, |
24 | | - _program_json_to_flatbuffer, |
25 | 23 | ) |
26 | 24 | from executorch.exir._serialize._flatbuffer_program import _program_to_flatbuffer |
27 | 25 | from executorch.exir._serialize._named_data_store import ( |
|
51 | 49 | # endian. |
52 | 50 | _HEADER_BYTEORDER: Literal["little"] = "little" |
53 | 51 |
|
54 | | -logger = logging.getLogger(__name__) |
55 | | - |
56 | 52 |
|
57 | 53 | @dataclass |
58 | 54 | class PTEFile: |
@@ -423,35 +419,6 @@ def _extract_named_data( |
423 | 419 | program.named_data = named_data |
424 | 420 |
|
425 | 421 |
|
426 | | -def _program_to_flatbuffer_with_fallback( |
427 | | - program: Program, |
428 | | - *, |
429 | | - constant_tensor_alignment: int, |
430 | | - delegate_alignment: Optional[int], |
431 | | -) -> _FlatbufferResult: |
432 | | - """ |
433 | | - Serializes the Program into a FlatBuffer, with a JSON fallback for robustness. |
434 | | -
|
435 | | - The FlatBuffer serialization path is the preferred fast path, offering |
436 | | - significantly better runtime performance and lower memory usage in benchmarks. |
437 | | - The JSON path is retained solely as a fallback to ensure robustness in cases |
438 | | - where FlatBuffer serialization fails. |
439 | | - """ |
440 | | - try: |
441 | | - return _program_to_flatbuffer( |
442 | | - program, |
443 | | - constant_tensor_alignment=constant_tensor_alignment, |
444 | | - delegate_alignment=delegate_alignment, |
445 | | - ) |
446 | | - except Exception: |
447 | | - logger.exception("FlatBuffer serialization failed. Falling back to JSON path.") |
448 | | - return _program_json_to_flatbuffer( |
449 | | - _program_to_json(program), |
450 | | - constant_tensor_alignment=constant_tensor_alignment, |
451 | | - delegate_alignment=delegate_alignment, |
452 | | - ) |
453 | | - |
454 | | - |
455 | 422 | def serialize_pte_binary( |
456 | 423 | pte_file: PTEFile, |
457 | 424 | *, |
@@ -557,7 +524,9 @@ def serialize_pte_binary( |
557 | 524 | segments_data.append(segment.data) |
558 | 525 |
|
559 | 526 | # Convert to a standard flatbuffer binary. |
560 | | - result: _FlatbufferResult = _program_to_flatbuffer_with_fallback( |
| 527 | + # Prefer the direct flatbuffer path to avoid JSON+flatc roundtrip, |
| 528 | + # which reduces CPU/memory and avoids temp file I/O. |
| 529 | + result: _FlatbufferResult = _program_to_flatbuffer( |
561 | 530 | program, |
562 | 531 | constant_tensor_alignment=constant_tensor_alignment, |
563 | 532 | delegate_alignment=delegate_alignment, |
|
0 commit comments