Skip to content

Improve error message for initialization failures with troubleshootin… #2637

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mcmc/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ function find_initial_params(

# if we failed to find valid initial parameters, error
return error(
"failed to find valid initial parameters in $(max_attempts) tries. This may indicate an error with the model or AD backend; please open an issue at https://github.com/TuringLang/Turing.jl/issues",
"failed to find valid initial parameters in $(max_attempts) tries. See https://turinglang.org/docs/uri/initial-parameters for common causes and solutions. If the issue persists, please open an issue at https://github.com/TuringLang/Turing.jl/issues",
)
end

Expand Down
14 changes: 14 additions & 0 deletions test/mcmc/hmc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,20 @@ using Turing
@test Turing.Inference.getstepsize(spl, hmc_state) isa Float64
end
end

@testset "improved error message for initialization failures" begin
# Model that always fails to initialize
@model function failing_model()
x ~ Normal()
@addlogprob! -Inf
end

# Test that error message includes troubleshooting link
@test_throws ErrorException sample(failing_model(), NUTS(), 10; progress=false)
@test_throws "https://turinglang.org/docs/uri/initial-parameters" sample(
failing_model(), NUTS(), 10; progress=false
)
end
end

end
Loading