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

Class _ExtendedHeader

exir/_serialize/_program.py:150–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

148
149@dataclass
150class _ExtendedHeader:
151 # Class constants
152
153 # The magic bytes that should be at the beginning of the header.
154 EXPECTED_MAGIC: ClassVar[bytes] = b"eh00"
155 MINIMUM_LENGTH: ClassVar[int] = (
156 # Header magic
157 4
158 # Header length
159 + 4
160 # Flatbuffer data size
161 + 8
162 # Segment base offset
163 + 8
164 )
165 # The length of the header in bytes.
166 EXPECTED_LENGTH: ClassVar[int] = (
167 MINIMUM_LENGTH
168 # Segment data size
169 + 8
170 )
171
172 # To find the header, callers should provide at least this many bytes of
173 # the head of the serialized Program data. Keep this in sync with
174 # kNumHeadBytes in //executorch/schema/extended_header.cpp
175 NUM_HEAD_BYTES: ClassVar[int] = 64
176
177 # Instance attributes. @dataclass will turn these into ctor args.
178
179 # The size of the serialized program data in bytes.
180 program_size: int
181 # Offset to the start of the first segment, or zero if there
182 # are no segments.
183 segment_base_offset: int
184 # Size of the segment data, in bytes, or zero if there are no segments, or
185 # if the this field isn't populated in the PTE file.
186 segment_data_size: int
187
188 # The magic bytes read from or to be written to the binary header.
189 magic: bytes = EXPECTED_MAGIC
190 # The header length, in bytes, read from or to be written to the binary
191 # header.
192 length: int = EXPECTED_LENGTH
193
194 @staticmethod
195 def from_bytes(data: bytes) -> "_ExtendedHeader":
196 """Tries to read an extended header from the provided data.
197
198 Does not validate that the header is well-formed. Callers should
199 use is_valid().
200
201 Args:
202 data: The data to read from.
203 Returns:
204 The contents of the extended header.
205 Raises:
206 ValueError: If not enough data is provided.
207 """

Callers 4

test_to_bytesMethod · 0.90
from_bytesMethod · 0.85
serialize_pte_binaryFunction · 0.85

Calls

no outgoing calls

Tested by 2

test_to_bytesMethod · 0.72