目录

.pte文件格式

ExecuTorch 程序文件被序列化为修改后的二进制 flatbuffer 附加了可选数据段的文件。.pte

             ┌───────────────────────────────────┐
             │Standard flatbuffer header         │
             ├───────────────────────────────────┤
Optional ──> │ExecuTorch extended header         │
             ├───────────────────────────────────┤
             │Flatbuffer-serialized program data │
             │                                   │
             │                                   │
          ┌─ ├───────────────────────────────────┤
          │  │Padding                            │
          │  ├───────────────────────────────────┤
          │  │Segment data                       │
          │  │                                   │
          │  │                                   │
          │  ├───────────────────────────────────┤
          │  │Padding                            │
Optional ─┤  ├───────────────────────────────────┤
          │  │Segment data                       │
          │  │                                   │
          │  │                                   │
          │  ├───────────────────────────────────┤
          │  │Padding                            │
          │  ├───────────────────────────────────┤
          │  │...                                │
          └─ └───────────────────────────────────┘

兼容性

请参阅 Runtime 兼容性策略 有关格式与 ExecuTorch 运行时。.pte

程序文件可以通过字节偏移量 4 处的魔术字符串来识别,从 其中 和 后跟两个 ASCII 十进制数字。ET

程序文件可能在字节偏移量 8 处具有可选的扩展标头,可识别 通过以 2 个 ASCII 十进制开头并后跟 2 个 ASCII 十进制的魔术字符串 数字。此标头包括 flatbuffer 编码的核心程序的大小 data 的 data 和可能跟随 Program data 的 Segments 的起始偏移量。 请注意,此标头是特定于 ExecuTorch 的,但即使存在,它也不会 扰乱大多数 flatbuffer-解析代码(除了很少使用的 ).ehGetBufferStartFromRootPointer()

所有数字都是 little-endian,与主机系统无关。

标题布局:

[0..3] uint32_t byte offset to the beginning of the flatbuffer root table.
[4..7] File magic bytes: "ET" followed by two ASCII decimal digits. The digits
       will change if the binary format of this file is changed in a
       non-backwards-compatible way.
Optional extended header:
|  [8..11] Extended header magic bytes: "eh" followed by two ASCII decimal
|          digits. The digits will change if the binary format of this header is
|          changed in a non-backwards-compatible way.
| [12..15] uint32_t size of this extended header in bytes, including the magic
|          header and this size field. Fields can be added to this header in
|          the future by increasing this size. This size does not include any
|          padding that may follow the header.
| [16..23] uint64_t size of the flatbuffer-encoded program data, starting from
|          byte offset zero above. I.e., it includes these headers.
| [24..31] uint64_t offset (from byte offset zero above) to the start of the
|          first segment, or zero if there are no segments.
|  [31..?] Any zero-padding necessary to preserve the alignment of the data
|          that follows.
End of optional extended header.

例:

        Offset to flatbuffer root (0x38)
        |            File magic ("ET??")
        |            |            Extended header magic ("eh??")
        |            |            |            Extended header size (0x18)
        vvvvvvvvvvv  vvvvvvvvvvv  vvvvvvvvvvv  vvvvvvvvvvv
0x0000  38 00 00 00  45 54 3F 3F  65 68 3F 3F  18 00 00 00
0x0010  F0 02 00 00  00 00 00 00  00 10 00 00  00 00 00 00
        ^^^^^^^^^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^^^^^^^^^^
        |                         Offset to segments (0x1000)
        Size of program flatbuffer data (0x2f0)

程序数据

请参阅 Program flatbuffer 架构。//executorch/schema/program.fbs

flatbuffer 编码的程序数据遵循 headers。通过嵌入大小 的 Extend Header,则客户端只能读取 Program 数据 无需读取区段数据。这很有用,因为程序数据通常 在模型的生命周期内保持不变,而大型 Segment 数据通常是 在模型初始化后可用。

细分数据

第一段从嵌入在扩展标头中的偏移量开始。 段通常与 4096 或匹配的 2 的其他幂对齐 目标系统的内存页面大小。如果需要,这使得它更易于使用。mmap()

程序数据中的数组包含 size/offset 有关(可选)后面的细分的信息。此数组中的偏移量为 相对于 Extended Headers 中的 Segment Offet。Program.segments

文档

访问 PyTorch 的全面开发人员文档

查看文档

教程

获取面向初学者和高级开发人员的深入教程

查看教程

资源

查找开发资源并解答您的问题

查看资源