SetInput error
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5k
- Forks
- 1.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 581
Description
🐛 Describe the bug
I am testing mobilenet_v3_small. My model generation code is below.
import torch
import torchvision
from torch.export import export
from executorch.exir import to_edge
import executorch.exir as exir
from torch.export import export, ExportedProgram
from torchvision.models import mobilenet_v3_small, MobileNet_V3_Small_Weights
from torch.utils.mobile_optimizer import optimize_for_mobile
m = mobilenet_v3_small(weights=MobileNet_V3_Small_Weights.IMAGENET1K_V1).eval()
m.eval()
example_args = (torch.randn(1, 3, 224, 224),)
aten_dialect: ExportedProgram = export(m, example_args)
edge_program: exir.EdgeProgramManager = exir.to_edge(aten_dialect)
executorch_program: exir.ExecutorchProgramManager = edge_program.to_executorch(
exir.ExecutorchBackendConfig(
passes=[], # User-defined passes
)
)
with open("mobilenet_v3_small.pte", "wb") as file:
file.write(executorch_program.buffer)
In my c++ code,
in the setup function, I use
executorch_model_ = std::make_unique(configs.model_path_.c_str(), Module::LoadMode::File);
In setInput function,:
for(int i=0;i<1;i++) {
auto input_tensor0 = executorch::extension::from_blob(input[i]->data, atenShape, data_type));
auto input_tensor = clone_tensor_ptr(input_tensor0);
std::cout<< "tensor data type0 " << static_cast(input_tensor->scalar_type()) << std::endl;
std::cout<< ensor data dim0 " << input_tensor->dim() << std::endl;
this->inputs_.emplace_back(input_tensor);
}
In execute function,
const auto result = executorch_model_->forward(this->inputs_);
I got the following error,
E 00:00:00.271241 executorch:tensor_impl.cpp:98] Attempted to resize a static tensor
E 00:00:00.271286 executorch:method.cpp:808] Error setting input 0: 0x10
F 00:00:00.271312 executorch:result.h:165] In function CheckOk(), assert failed: hasValue_
It looks like its trying to resize the input size of the forward method which TensorShapeDynamism::STATIC. Couldn't figure where it is configured as TensorShapeDynamism::STATIC.
Versions
I am using tag 0.4 on android NTK
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the tensor_impl.cpp:98 and method.cpp:808 errors, then inspect how the exported model's input shape and TensorShapeDynamism::STATIC setting interact with setInput. Compare the C++ atenShape and data type with the generated model input. Done means the model accepts input 0 without attempting to resize a static tensor and forward completes successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, cpp, python, pytorch
- Domain
- machine-learning, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100