捷徑

.pte 檔案格式

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

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

相容性

請參閱執行時期相容性政策,以了解 .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 的綜合開發者文檔

查看文檔

教學

獲取適合初學者和高級開發者的深入教程

查看教程

資源

查找開發資源並獲取您問題的解答

查看資源