快捷方式

.pte 檔案格式

ExecuTorch .pte 程式檔案被序列化為修改過的二進位制 flatbuffer 檔案,並可選擇附加資料段。

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

相容性

請參閱 Runtime Compatibility Policy,瞭解有關 .pte 格式與 ExecuTorch 執行時之間相容性保證的詳細資訊。

頭部

程式檔案可以透過位元組偏移量 4 處的魔術字串識別,該字串以 ET 開頭,後跟兩個 ASCII 十進位制數字。

程式檔案可以在位元組偏移量 8 處有一個可選的擴充套件頭部,該頭部由以 eh 開頭並後跟兩個 ASCII 十進位制數字的魔術字串識別。此頭部包含 flatbuffer 編碼的核心程式資料的大小,以及可能緊隨程式資料之後的段的起始偏移量。請注意,此頭部是 ExecuTorch 特有的,但即使存在,它也不會擾亂大多數 flatbuffer 解析程式碼(除了極少使用的 GetBufferStartFromRootPointer())。

所有數字均為小端序,無論主機系統如何。

頭部佈局

[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)

程式資料

請參閱 //executorch/schema/program.fbs 瞭解 Program flatbuffer 模式。

flatbuffer 編碼的程式資料緊隨頭部。透過將此區域的大小嵌入擴充套件頭部,客戶端可以只讀取程式資料而無需讀取段資料。這很有用,因為程式資料通常會在模型的生命週期內保留,而較大的段資料通常在模型初始化後即可釋放。

段資料

第一個段從擴充套件頭部中嵌入的偏移量處開始。段通常對齊到 4096 或其他與目標系統記憶體頁面大小匹配的 2 的冪次方。如果需要,這使得使用 mmap() 更加容易。

程式資料中的 Program.segments 陣列包含可選的後續段的大小/偏移資訊。此陣列中的偏移量是相對於擴充套件頭部中的段偏移量而言的。

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深入教程

檢視教程

資源

查詢開發資源並獲取問題解答

檢視資源