From dd74a312b21404843b52791a33e0f9e345eb9b7f Mon Sep 17 00:00:00 2001 From: Lucy Qiu Date: Thu, 29 Aug 2024 17:05:20 -0700 Subject: [PATCH] Update default segment alignment to 128 (#4994) Summary: Pull Request resolved: https://github.com/pytorch/executorch/pull/4994 Previous segment alignment=4096. This means models with small constant data will have .pte files filled mostly with padding. Update segment alignment=128 to ensure small models retain small binary size. Reviewed By: dbort Differential Revision: D61104820 --- exir/_serialize/_program.py | 2 +- exir/_serialize/test/test_program.py | 4 +++- exir/capture/_config.py | 2 +- exir/lowered_backend_module.py | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/exir/_serialize/_program.py b/exir/_serialize/_program.py index a82b947cec3..d22de71d1c2 100644 --- a/exir/_serialize/_program.py +++ b/exir/_serialize/_program.py @@ -348,7 +348,7 @@ def serialize_pte_binary( mutable_data: Optional[List[Buffer]] = None, extract_delegate_segments: bool = False, extract_constant_segment: bool = False, - segment_alignment: int = 4096, + segment_alignment: int = 128, constant_tensor_alignment: Optional[int] = None, delegate_alignment: Optional[int] = None, ) -> Cord: diff --git a/exir/_serialize/test/test_program.py b/exir/_serialize/test/test_program.py index 54f8c7b6225..09927ad9648 100644 --- a/exir/_serialize/test/test_program.py +++ b/exir/_serialize/test/test_program.py @@ -5,6 +5,8 @@ # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. +# pyre-unsafe + import copy import difflib import json @@ -36,7 +38,7 @@ ) from executorch.exir.tests.common import get_test_program -SEGMENT_ALIGNMENT: int = 4096 +SEGMENT_ALIGNMENT: int = 128 CONSTANT_TENSOR_ALIGNMENT: int = 16 diff --git a/exir/capture/_config.py b/exir/capture/_config.py index 42dc170c19d..c0f7b71baf9 100644 --- a/exir/capture/_config.py +++ b/exir/capture/_config.py @@ -73,7 +73,7 @@ class ExecutorchBackendConfig: # When extracting segments, the starting offset of each segment will be # aligned to this value (in bytes). Must be a power of two. - segment_alignment: int = 4096 + segment_alignment: int = 128 # If provided, the minimum alignment of tensor buffers in the program. Must # be a power of 2. If not provided, uses the value in the schema file. diff --git a/exir/lowered_backend_module.py b/exir/lowered_backend_module.py index d93905a2bd0..6ba3b6bcb05 100644 --- a/exir/lowered_backend_module.py +++ b/exir/lowered_backend_module.py @@ -137,7 +137,7 @@ def original_module(self) -> ExportedProgram: def buffer( self, extract_delegate_segments: bool = False, - segment_alignment: int = 4096, + segment_alignment: int = 128, constant_tensor_alignment: Optional[int] = None, delegate_alignment: Optional[int] = None, memory_planning: MemoryPlanningPass = None, # pyre-fixme[9]