pytorch / executorch

On-device AI across mobile, embedded and edge for PyTorch
https://pytorch.org/executorch/
Other
2.22k stars 371 forks source link

ImportError: cannot import name '_transform' from 'executorch.exir.program._program' #2204

Open adonnini opened 9 months ago

adonnini commented 9 months ago

I tried to produce a model to run for inference from my Android application using the executorch runtime enviroment. Execution failed producing the traceback log reported below.

Here is the code I used to produce the lowered model:

        m = TransEncoder(config, config.total_loc_num).to(device)
        m.eval()
        pre_autograd_aten_dialect = capture_pre_autograd_graph(m, (config, config.total_loc_num, device))
        aten_dialect: ExportedProgram = export(pre_autograd_aten_dialect, (config, config.total_loc_num, device))
        edge_program: EdgeProgramManager = to_edge(aten_dialect)
        lowered_module = edge_program.to_backend(XnnpackPartitioner())
        save_path = save_path = "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/LocationPrediction/loweredModels/tpt_delegate.pte"
        with open(save_path, "wb") as f:
            f.write(lowered_module.to_executorch().buffer)

Please let me know if you need additional information, and what I should do next.

Thanks

TRACEBACK LOG

Traceback (most recent call last):
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/LocationPrediction/main.py", line 68, in <module>
    res_single = single_run(train_loader, val_loader, test_loader, config, device, log_dir)
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/LocationPrediction/main.py", line 23, in single_run
    model, perf = get_trainedNets(config, model, train_loader, val_loader, device, log_dir)
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/LocationPrediction/utils/utils.py", line 47, in get_trainedNets
    best_model, performance = trainNet(config, model, train_loader, val_loader, device, log_dir=log_dir)
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/LocationPrediction/utils/train.py", line 211, in trainNet
    from executorch.backends.xnnpack.partition.xnnpack_partitioner import XnnpackPartitioner
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/trajectory-prediction-transformers-master/executorch/backends/xnnpack/__init__.py", line 8, in <module>
    from .partition.xnnpack_partitioner import (
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/trajectory-prediction-transformers-master/executorch/backends/xnnpack/partition/xnnpack_partitioner.py", line 25, in <module>
    from executorch.backends.xnnpack.passes.fuse_batch_norm_with_conv import (
  File "/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/trajectory-prediction-transformers-master/executorch/backends/xnnpack/passes/__init__.py", line 31, in <module>
    from executorch.exir.program._program import _transform
ImportError: cannot import name '_transform' from 'executorch.exir.program._program' (/home/adonnini1/Development/ContextQSourceCode/NeuralNetworks/LocationPrediction/executorch/exir/program/_program.py)
kimishpatel commented 8 months ago

@JacobSzwejbka @iseeyuan ?

larryliu0820 commented 8 months ago

It seems you need to update your ExecuTorch install in python environment. Pull the latest, do a

pip install .

and see if that fixes your issue

adonnini commented 8 months ago

@larryliu0820 Thanks! production of the lowered model was successful. Btw, I simply cloned the main branch and then followed the instructions in https://pytorch.org/executorch/stable/getting-started-setup.html Then I ran my training module including the executorch code

Another point to note. I repeated the above also for another model I use. The error did not occur which is good news. However execution failed with the error reported in https://github.com/pytorch/pytorch/issues/120219