pytorch / pytorch/executorch

Executorch does not seem to be able to accelerate Anomaly Transformer inference

Open
#8,631 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

module: llm module: user experience
Dominant language
Python
Stars
5k
Forks
1.2k
Avg merge
2d 10h
Merged PRs (30d)
581

Description

I want to use executorch to deploy the anomaly transformer model https://github.com/thuml/Anomaly-Transformer trained with pytorch to the Raspberry Pi 5. When converting the pth model to a pte model, the following warning appears:

/home/taylor/miniconda3/envs/executorch/lib/python3.10/site-packages/torch/export/_unlift.py:75: UserWarning: Attempted to insert a get_attr Node with no underlying reference in the owning GraphModule! Call GraphModule.add_submodule to add the necessary submodule, GraphModule.add_parameter to add the necessary Parameter, or nn.Module.register_buffer to add the necessary buffer
  getattr_node = gm.graph.get_attr(lifted_node)
/home/taylor/miniconda3/envs/executorch/lib/python3.10/site-packages/torch/fx/graph.py:1801: UserWarning: Node original_model_encoder_attn_layers_0_attention_inner_attention_distances target original_model.encoder.attn_layers.0.attention.inner_attention.distances distances of original_model.encoder.attn_layers.0.attention.inner_attention does not reference an nn.Module, nn.Parameter, or buffer, which is what 'get_attr' Nodes typically target
  warnings.warn(
/home/taylor/miniconda3/envs/executorch/lib/python3.10/site-packages/torch/fx/graph.py:1801: UserWarning: Node original_model_encoder_attn_layers_1_attention_inner_attention_distances target original_model.encoder.attn_layers.1.attention.inner_attention.distances distances of original_model.encoder.attn_layers.1.attention.inner_attention does not reference an nn.Module, nn.Parameter, or buffer, which is what 'get_attr' Nodes typically target
  warnings.warn(
/home/taylor/miniconda3/envs/executorch/lib/python3.10/site-packages/torch/fx/graph.py:1801: UserWarning: Node original_model_encoder_attn_layers_2_attention_inner_attention_distances target original_model.encoder.attn_layers.2.attention.inner_attention.distances distances of original_model.encoder.attn_layers.2.attention.inner_attention does not reference an nn.Module, nn.Parameter, or buffer, which is what 'get_attr' Nodes typically target
  warnings.warn(

Then I followed the steps of https://pytorch.org/executorch/stable/getting-started-setup.html to slightly modify the executor_runner.cpp code to record the time, and then run the pte model. The running time is as follows

I 00:00:01.327281 executorch:executor_runner.cpp:84] Model file SWaT.pte is loaded.
I 00:00:01.327354 executorch:executor_runner.cpp:93] Using method forward
I 00:00:01.327406 executorch:executor_runner.cpp:140] Setting up planned buffer 0, size 8239104.
I 00:00:01.346501 executorch:executor_runner.cpp:163] Method loaded.
method load time : 2.39548 ms
I 00:00:01.346714 executorch:executor_runner.cpp:178] Inputs prepared.
input prepared time : 0.102407 ms
I 00:00:14.292156 executorch:executor_runner.cpp:192] Model executed successfully.
model run time : 12945.4 ms
I 00:00:14.292199 executorch:executor_runner.cpp:199] 1 outputs: 
Output 0: tensor(sizes=[100], [
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 
  0., 0., 1.41644e-34, 2.33109e-21, 6.68264e-10, 0.0322331, 0.350365, 1.78738e-08, 4.11204e-23, 2.78298e-42, 
])

You can see that it takes about 13 seconds to infer once with the pte model, while it only takes 0.3 seconds to run the pth model with pytorch. I don't understand why this happens? Could this be the problem with this warning?

cc @mergennachin @cccclai @helunwencser @jackzhxng @byjlw

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the Anomaly Transformer pth-to-pte conversion using the linked ExecuTorch setup guide and record the reported warnings. Then inspect the modified executor_runner.cpp timing around method loading, input preparation, and execution on Raspberry Pi 5; done means identifying the cause of the 13-second inference time and whether the warnings or conversion affect the output.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch, raspberry-pi
Domain
embedded-iot, machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.