This is an automated email from the git hooks/post-receive script.
Git pushed a commit to branch master
in repository ffmpeg.
The following commit(s) were added to refs/heads/master by this push:
new a234fc1130 avfilter/dnn: prevent crash on parameterless LibTorch models
a234fc1130 is described below
commit a234fc1130e6b17d550371dede849918202a303a
Author: Raja-89 <[email protected]>
AuthorDate: Mon Jul 27 21:50:47 2026 +0530
Commit: guoyejun <[email protected]>
CommitDate: Wed Jul 29 12:37:03 2026 +0000
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]>
---
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 b28d31cc5c..705327f4b1 100644
--- a/libavfilter/dnn/dnn_backend_torch.cpp
+++ b/libavfilter/dnn/dnn_backend_torch.cpp
@@ -272,7 +272,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);
_______________________________________________
ffmpeg-cvslog mailing list -- [email protected]
To unsubscribe send an email to [email protected]