-
Notifications
You must be signed in to change notification settings - Fork 104
Add FAQ section to improve user guidance #608
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new FAQ section to the Turing.jl website and updates the navigation menu to include a link to it.
- Added a “FAQ” entry in the site navigation
- Created
faq/index.qmd
with a set of common Q&A on using Turing.jl
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
_quarto.yml | Inserted a navigation entry for the FAQ |
faq/index.qmd | Added FAQ page with detailed user guidance |
Comments suppressed due to low confidence (1)
_quarto.yml:27
- Indentation of the new navigation entry does not match the surrounding items and could break the YAML. Align the
- href: faq/
and itstext:
line with the other menu entries.
- href: faq/
Preview the changes: https://turinglang.org/docs/pr-previews/608 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice start, I think there are a few places where it's necessary to go into more detail, which I've commented on.
General comment for the entire PR: for the URLs, you can use the meta variables defined in _quarto.yml
, i.e. [text]({{< meta usage-automatic-differentiation >}})
to avoid hardcoding relative paths (useful if you want to move pages around, which has happened a couple of times).
You cannot directly condition on `x[2]` using `condition(model, @varname(x[2]) => 1.0)` because `x[2]` never appears on the LHS of a `~` statement. Only `x` as a whole appears there. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be good to have a bit more subtlety here, as there is a case where this isn't true: if you use x .~ dist
where dist
is a univariate distribution, then each element of x
is separately treated as being drawn from dist
. So, you can do
@model function f1()
x = Vector{Float64}(undef, 3)
x .~ Normal()
end
m1 = f1() | (@varname(x[1]) => 1.0)
sample(m1, NUTS(), 100) # OK
However, you can't condition on part of a distribution, so because MvNormal()
is a distribution that returns a vector, you can't condition on part of it. (Statistically, this would be like marginalising out some degrees of freedom, but we don't have the ability to do that now.)
@model function f2()
x = Vector{Float64}(undef, 3)
x ~ MvNormal(zeros(3), I)
end
m2 = f2() | (@varname(x[1]) => 1.0)
sample(m2, NUTS(), 100) # Not OK
And filldist
doesn't create a set of N iid distributions; it lumps them all into a single distribution, which is why you can't condition on x[1]
in the example. So it's not so much about conditioning on the LHS of a tilde, it's more about conditioning on entire distributions at once.
It's quite confusing, and hence why I think it's important to explain this carefully.
- [AbstractMCMC-Turing Interface](../developers/inference/abstractmcmc-turing/) - how to integrate your sampler with Turing | ||
- [AbstractMCMC Interface](../developers/inference/abstractmcmc-interface/) - the underlying interface documentation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [AbstractMCMC-Turing Interface](../developers/inference/abstractmcmc-turing/) - how to integrate your sampler with Turing | |
- [AbstractMCMC Interface](../developers/inference/abstractmcmc-interface/) - the underlying interface documentation |
These docs are severely outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely we keep it then when we update the docs we don't have to worry about linking? Also that seems like a separate issue, why do we have outdated docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely we keep it then when we update the docs we don't have to worry about linking
Those pages specifically aren't even in the sidebar (I removed them in #607) so for all intents and purposes don't exist.
why do we have outdated docs?
I mean, it's a research project, nobody has time to write docs, blah blah. These aren't the only outdated pages, and even the up-to-date pages probably have sections which are out of date.
Yes! Turing.jl supports both multithreaded and distributed sampling. See the [Core Functionality guide](../core-functionality/#sampling-multiple-chains) for detailed examples showing: | ||
- Multithreaded sampling using `MCMCThreads()` | ||
- Distributed sampling using `MCMCDistributed()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one also needs more nuance. Sampling one chain per thread is indeed done with MCMCThreads()
but (I think) the main intent behind this question is whether one can use threading within the model itself, e.g.,
@model function f(x)
Threads.@threads for i in eachindex(x)
x[i] ~ Normal()
end
end
That means that the execution of the model itself is inherently multithreaded (as opposed to sampling with MCMCThreads(), where each chain runs the model many times but only on one thread).
The TLDR of this in the model is that threaded observe statements are OK but threaded assume statements are not (they often crash in unpredictable ways, or sometimes they actually work if you're really lucky).
Another aspect maybe worth mentioning is that threads inside models don't work with many AD backends (see multithreaded
in https://turinglang.org/ADTests/ for an example)
|
||
Type stability is crucial for performance. Check out: | ||
- [Performance Tips](../usage/performance-tips/) - includes specific advice on type stability | ||
- [Automatic Differentiation](../usage/automatic-differentiation/) - contains benchmarking utilities using `DynamicPPL.TestUtils.AD` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [Automatic Differentiation](../usage/automatic-differentiation/) - contains benchmarking utilities using `DynamicPPL.TestUtils.AD` |
The AD page doesn't discuss type stability.
I think the best 'high-level' way to determine type stability is https://turinglang.org/DynamicPPL.jl/stable/api/#DynamicPPL.DebugUtils.model_warntype although I've not used it myself.
While there are many syntactic differences, key advantages of Turing include: | ||
- **Julia ecosystem**: Full access to Julia's profiling and debugging tools | ||
- **Parallel computing**: Much easier to use distributed and parallel computing inside models | ||
- **Flexibility**: Can use arbitrary Julia code within models | ||
- **Extensibility**: Easy to implement custom distributions and samplers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't answer the stated question?
If it's a question about syntax, I would personally think it's best to have Turing vs Stan in a single section, and Turing vs (other PPL) can be a different section. Apart from the parameter block, two of the common things that Stan models have that Turing doesn't are transformed data
and generated quantities
-- the gist in Turing is that any data transformations should be done before defining the model (so it's decoupled from the model) and generated quantities are covered in https://turinglang.org/docs/usage/tracking-extra-quantities/index.html.
- [Performance Tips](../usage/performance-tips/#choose-your-ad-backend) - quick guide on choosing backends | ||
- [AD Backend Benchmarks](https://turinglang.org/ADTests/) - performance comparisons across various models | ||
|
||
For more specific recommendations, check out the [DifferentiationInterface.jl tutorial](https://juliadiff.org/DifferentiationInterface.jl/DifferentiationInterfaceTest/stable/tutorial/). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think DITest is relevant yet --- to use the benchmarking functionality in there we would need to have a way of constructing DifferentiationInterfaceTest.Scenario
s from Turing models and although it's not very hard to write some code for that, it's probably too long to go into an FAQ page. Would be a good thing to add to the AD page, probably in a separate PR.
## I changed one line of my model and now it's so much slower; why? | ||
|
||
Small changes can have big performance impacts. Common culprits include: | ||
- Type instability introduced by the change | ||
- Switching from vectorized to scalar operations (or vice versa) | ||
- Inadvertently causing AD backend incompatibilities | ||
- Breaking assumptions that allowed compiler optimizations | ||
|
||
See our [Performance Tips](../usage/performance-tips/) and [Troubleshooting Guide](../usage/troubleshooting/) for debugging performance regressions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you took the list questions from somewhere else, but I don't really like this question. I don't get the intent behind it (what is the answer supposed to be?) and the result of this is, I think, reflected in the text, which is very vague and IMO not very helpful. If the answer is basically to read the performance section.
IME interactions with AD backend don't often lead to performance differences, usually it either runs fine or it crashes. If the AD is unusually slow it usually reflects slowness in the model itself.
You cannot directly condition on `x[2]` using `condition(model, @varname(x[2]) => 1.0)` because `x[2]` never appears on the LHS of a `~` statement. Only `x` as a whole appears there. | ||
|
||
To understand more about how Turing determines whether a variable is treated as random or observed, see: | ||
- [Compiler Design Overview](../developers/compiler/design-overview/) - explains the heuristics Turing uses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [Compiler Design Overview](../developers/compiler/design-overview/) - explains the heuristics Turing uses |
This one is also very outdated
Co-authored-by: Penelope Yong <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Penelope Yong <[email protected]>
This pull request adds a new FAQ section to the Turing.jl website and updates the navigation menu to include a link to the FAQ page. The FAQ section provides answers to common questions about using Turing.jl, covering topics such as random variables, implementing samplers, parallelism, debugging, syntax differences, automatic differentiation backends, and performance issues.
Website Navigation Update:
_quarto.yml
: Added a new link to the FAQ page in the website's navigation menu.FAQ Section Addition:
faq/index.qmd
: Created a new FAQ page with detailed answers to common questions about Turing.jl. Topics include variable treatment, sampler implementation, parallelism, type stability, debugging, syntax differences, automatic differentiation backends, and performance debugging.Relevant Issues: