`compile_and_save` needs twice the engine size on disk while it saves to ExecuTorch

オープン
#5,041 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
18/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python, pytorch
領域
data, devtools

調査の方向性

The save path is in compile_and_save in the Torch-TensorRT Python package, which writes each built engine to a temporary file before the ExecuTorch copy; the repro script in the issue measures peak disk use and is the check for done. The fix spans two projects: the ExecuTorch file-writing code that would need to punch holes in owned file-backed data after each chunk is copied, and the Torch-TensorRT hand-off of offloaded engine files. Start by reading how engine files are written and passed to ExecuTorch, then confirm the disk peak drops to about one copy.

索引モデルが issue の本文から書いたものです。

説明

What is wrong

compile_and_save writes each engine to a temporary file as soon as it is built. With output_format="executorch", the save then copies each file into the .pte (or .ptd). The temporary files are deleted only when the call returns. So at the end of the save, every engine is on disk twice.

For a large single-engine program this decides whether the export fits. #5026 lets the caller move the files to another disk, which helps, but the space is still needed.

What this blocks

No policy in pytorch/executorch#24353 is listed as failing because of this. It costs disk.
Any export with output_format="executorch" needs free space for twice its engines, so a large single-engine program needs twice its size free. That can decide whether it fits on a Jetson or a DGX Spark.
A fix lets an export fit when the free disk is only a little larger than the program.

Repro
import os, shutil, tempfile, threading, time
import torch, torch_tensorrt

work = tempfile.mkdtemp()
os.environ["TMPDIR"] = tempfile.tempdir = os.path.join(work, "tmp")
os.makedirs(tempfile.tempdir)
out = os.path.join(work, "model.pte")

def used(path):
    return sum(os.stat(os.path.join(r, f)).st_blocks * 512 for r, _, fs in os.walk(path) for f in fs)

peak, stop = [0], threading.Event()
def watch():
    while not stop.is_set():
        peak[0] = max(peak[0], used(work))
        time.sleep(0.2)

model = torch.nn.Sequential(*[torch.nn.Linear(8192, 8192, bias=False) for _ in range(32)]).cuda().bfloat16().eval()
x = torch.randn(4, 8192, device="cuda", dtype=torch.bfloat16)
ep = torch.export.export(model, (x,))
threading.Thread(target=watch, daemon=True).start()
torch_tensorrt.compile_and_save(ep, out, output_format="executorch", arg_inputs=[x], min_block_size=1)
stop.set()
print(f"program {os.path.getsize(out) / 2**30:.2f} GiB, disk peak {peak[0] / 2**30:.2f} GiB")
shutil.rmtree(work)
Actual
program 4.00 GiB, disk peak 8.00 GiB
Expected

The peak is about one copy. A proposal in 2 small parts:

  1. ExecuTorch: file-backed data that the caller marks as owned is consumed by the write. After each chunk is copied, that range of the source is released (fallocate with FALLOC_FL_PUNCH_HOLE, supported on ext4, XFS and btrfs), and the file is removed at the end. Elsewhere it copies as today.
  2. Torch-TensorRT: hand each offloaded engine file to ExecuTorch as owned data, since nothing reads it after the save.
Versions

torch 2.15.0 (CUDA 13.2), torch_tensorrt 2.15.0, executorch 1.6.0, TensorRT 11.4.0.106. Script run on H100, driver 580.126.09 (btrfs).

Related: #4863 (keeping built engines on disk until the save, which is where the temporary files come from), #5026.

主要言語
Python
スター
3k
フォーク
421
平均マージ
4日 7時間
マージ済み PR(30日)
62

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pytorch/TensorRT のほかの issue

pytorch/TensorRT の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。