Skip to content

Import pt2 - #1693

Open
syamajala wants to merge 2 commits into
flexflow:masterfrom
syamajala:import-pt2
Open

syamajala wants to merge 2 commits into
flexflow:masterfrom
syamajala:import-pt2

Conversation

@syamajala

@syamajala syamajala commented Nov 18, 2026 •

Copy link
Copy Markdown

Import pytorch pt2 files into flexflow. Walks the model.json and calls ComputationGraphBuilder. Verified with yolov10. Dumped flexflow's yolov10 to json and compared with the pytorch implementation. Import yolov10 pt2 file, dumped to json compared with pt2 and flexflow's yolov10 json. All match.


This change is Reviewable

syamajala and others added 2 commits November 18, 2026 04:35
New bin/import-pt2 tool that reads a .pt2 archive written by
torch.export.save() and rebuilds its graph with ComputationGraphBuilder,
then outputs V1 JSON (default) or DOT (--dot).

- pt2_archive: minimal zip reader (zip64 aware) for the stored,
  uncompressed entries PyTorch writes; finds models/model.json under any
  top-level directory. No libtorch dependency.
- pt2_to_computation_graph: translates ATen nodes to builder calls.
  Parameters and buffers are implied by their owning op (conv2d weight ->
  out_channels/kernel, bias -> use_bias, etc.); weight values are not
  imported. After every op, FlexFlow's inferred shape is checked against
  the shape recorded in the .pt2.
- Supported ops: conv2d, batch_norm, linear, silu/relu/gelu/sigmoid/tanh/
  exp/rsqrt, add/sub/mul/div (tensor and scalar), cat, chunk/split,
  view/reshape/flatten/(un)squeeze, transpose/permute, max_pool2d,
  adaptive_avg_pool2d, upsample_nearest2d, matmul/bmm, softmax, plus
  pass-through of detach/clone/dropout(eval)/no-op casts. Unsupported ops,
  dynamic shapes and unsupported arguments fail with an error naming the
  node.

Tested on ultralytics YOLOv10x (batch 8, end2end=false): the imported
graph is structurally identical to export-model-arch yolov10x (576
non-weight layers, 513 weights, same attrs, shapes, wiring and outputs).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant