Skip to content

Test upsample testsuite against multiple eltypes#716

Open
CarloLucibello wants to merge 1 commit into
masterfrom
cl/upsample-eltypes
Open

Test upsample testsuite against multiple eltypes#716
CarloLucibello wants to merge 1 commit into
masterfrom
cl/upsample-eltypes

Conversation

@CarloLucibello

Copy link
Copy Markdown
Member

Addresses the T = Float32 # TODO test against all supported eltypes for each backend item catalogued in #702.

The forward/gradient testsets in test/testsuite/upsample.jl (upsample_nearest, linear/bilinear/trilinear) are now run in a loop over the float eltypes each backend supports:

float_types = Symbol(Backend) == :MetalBackend ? [Float16, Float32] : [Float16, Float32, Float64]
@testset "eltype = $T" for T in float_types

This mirrors the per-backend eltype pattern already used in test/testsuite/scatter.jl. Metal drops Float64 since it has none natively.

Details

  • Float16/Float64 forward + eltype-preservation are now covered (previously only Float32). isapprox automatically relaxes rtol to the less-precise operand, so the existing ground-truth comparisons pass for Float16 unchanged.
  • Gradients are checked only at Float32/Float64. Finite-difference gradient checking is unreliable at half precision (observed 3–17% error), so for Float16 only the forward pass runs — via gradtest's skip=true (CPU) / gputest's checkgrad=false (GPU).
  • GPU safety: the explicit ∇upsample_bilinear/∇upsample_trilinear correctness checks invoke the gradient kernels, which use @atomic adds (half-precision atomics aren't universally available on GPU), so they're gated behind the same condition. Float16 stays forward-only — no atomics — on every backend.
  • The Rational/UInt8 forward tests moved out of the per-eltype loop into their own testset so they run once instead of once per float eltype. pixel_shuffle and the complex-valued tests are unchanged.

Testing

CPU testsuite is green: 129 pass, 5 intentional Float16 gradient skips, 0 failures. GPU backends were not run locally.

🤖 Generated with Claude Code

Address the `T = Float32 # TODO test against all supported eltypes`
item from #702. The forward/gradient testsets are now run in a loop
over `[Float16, Float32, Float64]` (Metal drops `Float64`), mirroring
the per-backend eltype pattern in `scatter.jl`.

- Float16/Float64 forward + eltype-preservation are now covered
  (previously only Float32). `isapprox` relaxes `rtol` to the
  less-precise operand, so the ground-truth comparisons pass for
  Float16 unchanged.
- Gradients are only checked at Float32/Float64: finite differences
  are unreliable at half precision, and the gradient kernels rely on
  atomics not universally available for Float16 on GPU. For Float16
  the gradient comparison is skipped (`gradtest` skip / `gputest`
  checkgrad=false) and the explicit ∇ kernel checks are gated off.
- The Rational/UInt8 forward tests move into their own testset so they
  run once rather than once per float eltype.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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

Successfully merging this pull request may close these issues.

1 participant