TuringLang / TuringLang/SSMProblems.jl

GeneralisedFilters: Stratified resampler is exported but has no CPU method

Open
#187 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Julia
Stars
11
Forks
7
PR merge metrics
No merged PRs in 30d

Description

Stratified is exported from GeneralisedFilters, but sample_ancestors has no method for a plain Vector, so any CPU use of it fails with a MethodError.

Reproducer
using Random, GeneralisedFilters
using GeneralisedFilters: Stratified, Systematic, Multinomial, Metropolis, Rejection,
    sample_ancestors

w = [0.25, 0.25, 0.25, 0.25]
sample_ancestors(Random.default_rng(), Stratified(), w)
ERROR: MethodError: no method matching sample_ancestors(::TaskLocalRNG, ::Stratified, ::Vector{Float64})

The other four exported resamplers all work on the same input:

Resampler sample_ancestors(rng, r, w)
Systematic() [1, 2, 3, 4]
Stratified() MethodError
Multinomial() [4, 2, 3, 4]
Metropolis() [2, 1, 3, 3]
Rejection() [1, 2, 3, 4]

It surfaces the same way through a filter, so BF(64; resampler = Stratified()) fails while the other four return a log-likelihood.

Cause

Stratified is defined as a bare struct, and its only sample_ancestors and sample_offspring methods are typed on CuVector. On 0.4.2 those sit at src/resamplers.jl:281-292; on 0.5.0 the struct is at src/resamplers.jl:240 and the CuVector methods have moved to ext/CUDAExt.jl:61-69. Either way there is no CPU implementation, so the exported name only works on GPU arrays.

Version

GeneralisedFilters 0.4.2, Julia 1.12, macOS. Read from the source, 0.5.0 looks the same in this respect, though I have not run it.

This was opened by a bot. Please ping @seabbs for any questions.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the direct sample_ancestors reproducer and inspect the Stratified definitions in src/resamplers.jl and ext/CUDAExt.jl. Compare its CPU behavior with the other resamplers and verify the fix through BF(64; resampler = Stratified()) as well as the direct Vector call. Done means both return successfully on CPU while existing CuVector behavior remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.