# What is the intended use for \`Turing.returned(model)\`?

**URL:** <https://discourse.julialang.org/t/what-is-the-intended-use-for-turing-returned-model/130105>\
**Category:** Probabilistic Programming\
**Tags:** turing\
**Created:** [June 22, 2025, 12:01pm UTC](https://discourse.julialang.org/t/what-is-the-intended-use-for-turing-returned-model/130105 "2025-06-22T12:01:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lunafazio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lunafazio/32/217332_2.png) [@lunafazio](https://discourse.julialang.org/u/lunafazio)\
**Post date:** [June 22, 2025, 12:01pm UTC](https://discourse.julialang.org/t/what-is-the-intended-use-for-turing-returned-model/130105/1 "2025-06-22T12:01:00Z")

</div>

There are no examples in the documentation, but based on its description,

> Return a `model` wrapper indicating that it is a model over its return-values.

I assumed that this would allow me to do something like

```julia
chain = sample(returned(mymodel), ...)

```

or to use it as a submodel, but having it so that the parameters that are shown by Turing with `describe(chain)` would be the returned values (potentially given a nicer user-facing output for models where parameters of interest are transformations of what actually gets sampled).

I am familiar with the discussion on how the generality of `return` statements would make it so that this kind of operation cannot be expected to work in general, but this still leaves me wondering how to interpret the explanation given by the documentation and the intended use of such a function.

---

<div class="post-metadata">

**Author:** ![eteppo](https://avatars.discourse-cdn.com/v4/letter/e/90db22/32.png) [@eteppo](https://discourse.julialang.org/u/eteppo)\
**Post date:** [June 22, 2025, 5:07pm UTC](https://discourse.julialang.org/t/what-is-the-intended-use-for-turing-returned-model/130105/2 "2025-06-22T17:07:04Z")

</div>

Looks like for now [that method](https://turinglang.org/DynamicPPL.jl/stable/api/#DynamicPPL.returned-Tuple%7BModel%7D) is used by `to_submodel` which you use inside models to make submodels, marking their returned values sampleable with `~`. To put intermediates/transformations into the chain, [you can use](https://turinglang.org/docs/usage/tracking-extra-quantities/) walrus `:=` instead of assignment `=`.

---

<div class="post-metadata">

**Author:** ![lunafazio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lunafazio/32/217332_2.png) [@lunafazio](https://discourse.julialang.org/u/lunafazio)\
**Post date:** [June 22, 2025, 5:10pm UTC](https://discourse.julialang.org/t/what-is-the-intended-use-for-turing-returned-model/130105/3 "2025-06-22T17:10:44Z")

</div>

I see, thank you!

---

<div class="post-metadata">

**Author:** ![penelopeysm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/penelopeysm/32/213172_2.png) [@penelopeysm](https://discourse.julialang.org/u/penelopeysm)\
**Post date:** [June 29, 2025, 9:36pm UTC](https://discourse.julialang.org/t/what-is-the-intended-use-for-turing-returned-model/130105/4 "2025-06-29T21:36:08Z")

</div>

Just wanted to add, this method was only really for internal use but I [have a PR getting rid of it](https://github.com/TuringLang/DynamicPPL.jl/pull/960) (because, IMO, it didn’t accomplish much).

---

<div class="post-metadata">

**Author:** ![lunafazio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lunafazio/32/217332_2.png) [@lunafazio](https://discourse.julialang.org/u/lunafazio)\
**Post date:** [June 30, 2025, 7:16am UTC](https://discourse.julialang.org/t/what-is-the-intended-use-for-turing-returned-model/130105/5 "2025-06-30T07:16:24Z")

</div>

Thanks for the additional context! It did feel like it was just an internal thing when looking through the codebase but I guess the fact that it was documented threw me off a bit. 🙂
