This is an automated email from the git hooks/post-receive script. Git pushed a commit to branch release/9.0 in repository ffmpeg.
commit f2bb42fd69d48f583547389dbec5cdb6577e2d40 Author: Raja-89 <[email protected]> AuthorDate: Mon Jul 27 21:50:47 2026 +0530 Commit: Michael Niedermayer <[email protected]> CommitDate: Thu Nov 26 22:32:57 2026 +0100 avfilter/dnn: prevent crash on parameterless LibTorch models When loading a TorchScript model that does not contain any learnable parameters (e.g., a purely functional model), the Torch backend would crash during inference. This occurred because the code attempted to dereference the first iterator of the model's parameter list `parameters().begin()` to determine the device, which results in Undefined Behavior when the parameter list is empty. This commit fixes the issue by determining the inference device directly from the user-configured `ctx->device` string instead of probing the model parameters, allowing parameterless models to execute safely. Testing: 1. Generate a parameterless model: cat << 'EOF' > generate_model.py import torch class DummyModel(torch.nn.Module): def forward(self, x): return x scripted_model = torch.jit.script(DummyModel()) scripted_model.save("dummy_model.pt") EOF python3 generate_model.py 2. Run inference (previously crashed, now succeeds): ./ffmpeg -y -i input.mp4 -vf 'format=rgb24,dnn_processing=dnn_backend=torch:model=dummy_model.pt' -frames:v 5 -f null - Signed-off-by: Raja Rathour <[email protected]> (cherry picked from commit a234fc1130e6b17d550371dede849918202a303a) Signed-off-by: Michael Niedermayer <[email protected]> --- libavfilter/dnn/dnn_backend_torch.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavfilter/dnn/dnn_backend_torch.cpp b/libavfilter/dnn/dnn_backend_torch.cpp index 5f16234b8e..0cbfc1a2c3 100644 --- a/libavfilter/dnn/dnn_backend_torch.cpp +++ b/libavfilter/dnn/dnn_backend_torch.cpp @@ -248,7 +248,8 @@ static int th_start_inference(void *args) return DNN_GENERIC_ERROR; } // Transfer tensor to the same device as model - c10::Device device = (*th_model->jit_model->parameters().begin()).device(); + const char *device_name = ctx->device ? ctx->device : "cpu"; + c10::Device device(device_name); if (infer_request->input_tensor->device() != device) *infer_request->input_tensor = infer_request->input_tensor->to(device); inputs.push_back(*infer_request->input_tensor); -- To stop receiving notification emails like this one, please contact [email protected]. _______________________________________________ ffmpeg-cvslog mailing list -- [email protected] To unsubscribe send an email to [email protected]
