Skip to content

Conversation

larryliu0820
Copy link
Contributor

@larryliu0820 larryliu0820 commented Oct 6, 2025

This pull request enhances the executor_runner example by adding support for loading and using .ptd (portable tensor data) files. This enables the runner to ingest pre-serialized tensor data, improving flexibility for model input handling. The changes include updates to both build configuration and the main runner logic.

Support for .ptd file loading and usage:

  • Added a new command-line flag data_path to specify the path to a .ptd data file in executor_runner.cpp and integrated logic to load this file and parse its contents using FlatTensorDataMap. [1] [2]
  • Updated the runner to pass the loaded tensor data map to the model method loader, allowing methods to access pre-loaded input data.

Build and dependency updates:

  • Included flat_tensor_data_map as a dependency in both the Bazel build targets and CMake build configuration to ensure the new functionality is available during compilation. [1] [2] [3]
  • Added the necessary header include for flat_tensor_data_map in executor_runner.cpp and updated the relevant namespace usage. [1] [2]

Test Plan:

Tested with .pte and .ptd for CUDA backend:

python -m executorch.examples.cuda.scripts.export --model_name linear --output_dir ./

Make sure we have linear.pte and aoti_cuda_blob.ptd.

Build executor runner with the following options:

cmake -DCMAKE_BUILD_TYPE=Debug -DEXECUTORCH_BUILD_CUDA=ON -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON -DEXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR=ON -DEXECUTORCH_BUILD_EXTENSION_TENSOR=ON -S. -Bcmake-out

Then do:

cmake --build cmake-out -j8

Then we can run:

cmake-out/executor_runner --model_path linear.pte --ptd_path aoti_cuda_blob.ptd
I 00:00:00.000594 executorch:executor_runner.cpp:189] PTD file aoti_cuda_blob.ptd is loaded.
I 00:00:00.000671 executorch:executor_runner.cpp:199] PTD data map created with 1 keys.
I 00:00:00.000749 executorch:executor_runner.cpp:249] Model file linear.pte is loaded.
I 00:00:00.000758 executorch:executor_runner.cpp:258] Using method forward
I 00:00:00.000770 executorch:executor_runner.cpp:309] Setting up planned buffer 0, size 96.
I 00:00:00.002908 executorch:cuda_backend.cpp:140] Writing 394624 bytes to /tmp/linear_so_blob844427.so
I 00:00:00.324783 executorch:cuda_backend.cpp:174] container_handle = 0x26a71b0
I 00:00:00.324867 executorch:executor_runner.cpp:337] Method loaded.
I 00:00:00.325796 executorch:cuda_backend.cpp:249] Inputs copied to GPU
I 00:00:00.325829 executorch:cuda_backend.cpp:278] Outputs created on GPU
E 00:00:00.326623 executorch:memory.cpp:286] Cannot delete null tensor
I 00:00:00.326678 executorch:executor_runner.cpp:374] Model executed successfully 1 time(s) in 1.777041 ms.
I 00:00:00.326691 executorch:executor_runner.cpp:383] 1 outputs: 
OutputX 0: tensor(sizes=[3, 3], [-0.199237, 0.550725, 0.0830356, -0.199237, 0.550725, 0.0830356, -0.199237, 0.550725, 0.0830356])
E 00:00:00.328474 executorch:memory.cpp:299] Didn't find tensor 0x699a3d0

Copy link

pytorch-bot bot commented Oct 6, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/14833

Note: Links to docs will display an error until the docs builds have been completed.

❌ 5 New Failures

As of commit d017656 with merge base 0b748bf (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 6, 2025
@larryliu0820 larryliu0820 added the release notes: none Do not include this in the release notes label Oct 6, 2025
@larryliu0820 larryliu0820 marked this pull request as ready for review October 6, 2025 23:38
Copy link
Contributor

@lucylq lucylq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

Copy link

meta-codesync bot commented Oct 6, 2025

@larryliu0820 has imported this pull request. If you are a Meta employee, you can view this in D84020938.

@larryliu0820 larryliu0820 force-pushed the add_data_support branch 3 times, most recently from 117d265 to 38e07b6 Compare October 7, 2025 08:46
@larryliu0820 larryliu0820 merged commit d8e07bd into main Oct 7, 2025
289 of 294 checks passed
@larryliu0820 larryliu0820 deleted the add_data_support branch October 7, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants