Skip to content
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

Support potential type argument in rand for eltype of Sampleable #2306

Closed
bgctw opened this issue Aug 16, 2024 · 1 comment
Closed

Support potential type argument in rand for eltype of Sampleable #2306

bgctw opened this issue Aug 16, 2024 · 1 comment

Comments

@bgctw
Copy link

bgctw commented Aug 16, 2024

In Distributions there is a long-standing discussion about how to specify the type of samples from a Distribution. This is important for code involving GPU computations that often needs Float32 rather than Float64.

Currently, this eltype of the sample is somehow mingled with the type of the parameters in Distributions.jl.
One suggestion is, to specify the eltype with a new variant of the rand function: rand(::Type{T}, ::Sampleable, ...)

In the linked issue, I argued for an alternative solution where this type can be specified with the Distribution, because the rand approach is not straightforward to extend to Turing. In Turing, the user, i.e. the author of the model, does not call the rand function directly, but relies on specifying the distribution, that a prior is sampled from.

However, it is believed that Turing should adapt.
Indeed, it seems that it can already be specified with the default type parameter in the Turing.@model macro, like
Turing.@model function tmodel_cross(obs_target, ::Type{T} = Float32) where {T}
Contrary, if it would be hard for Turing to adapt its syntax to specify the eltype of the Sampleable, this would be good time to contribute the discussion at the linked Distribution.jl issue.

@mhauru
Copy link
Member

mhauru commented Aug 19, 2024

Thanks for the pointer! Seems @devmotion attended to this and the linked PR is now closed, so I'll close this one too.

@mhauru mhauru closed this as completed Aug 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants