Repository navigation
Conversation
…razane#138) crps_cnormal, crps_clogistic and crps_ct computed lmass and umass with the active backend instead of the backend argument, so torch tensors that require grad (or live on a GPU) went through numpy. Convert the inputs with the requested backend and pass it to the CDFs, as crps.gtcnormal does. In crps_cnormal, set a tail mass to exactly 0 when its bound is infinite: jax's float32 erf stops short of +-1 at +-inf, which made gtcnormal return nan.
Owner
|
Thanks! #133 just landed and fixes the backend issue by construction, so this now conflicts. Could you rebase and keep only the jax ±inf mass guard plus a jax test (dropping the jax skip in |
Owner
|
@copilot resolve the merge conflicts in this pull request |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #138.
crps_cnormalcomputed its tail masses withstats._norm_cdf(...)without passingbackend, so they used the globally active backend (numpy by default) rather than the requested one. With torch tensors that require grad, this went through numpy and failed.crps_clogistic(_logis_cdf) andcrps_ct(_t_cdf) had the same pattern, so this fixes all three.Change: in each of the three wrappers, convert
location,scale,lower,upper(anddfforcrps_ct) with the requested backend'sasarray, and passbackend=backendto both CDF calls, ascrps.gtcnormalalready does.crps_cnormalalso sets a tail mass to exactly 0 when its bound is infinite. Once the masses really use jax, the float32erf(+-inf)returns about +-0.9999998, so the masses are not exactly 0, andgtcnormalreturnsnanbecause it only handles an infinite bound when the mass is exactly 0. The existingtest_crps_cnormal[jax]catches this.mainalready has the problem when jax is the active backend:sr.crps_cnormal(1.8, 0.4, 1.1)returnsnanthere.crps_clogisticdoes not need this, since its CDF gives exactly 0 and 1 at the infinite bounds.Tests
test_crps_censored_tail_masses_use_backend(torch only) callscrps_cnormalandcrps_clogisticwith the torch backend requested while numpy stays active, on a location tensor that requires grad, and checks that the gradient reaches it.Run locally on Windows, Python 3.12, from
uv.lock:_crps.py: 2 failed,RuntimeError: Can't call numpy() on Tensor that requires gradpytest tests/with this change, all backends: 606 passed, 37 skippedcrps_ctis not implemented for jax/torch (its existing test skips them), so its change is only exercised on numpy and numba. The device issue in #139 is separate and not touched here.This overlaps with the CRPS lines changed in #133. If that lands first, I am happy to rebase or close this.
Checklist
uv sync --all-extras --devthenuv run pytest tests/(exercises every installed backend: numpy, numba, jax, torch)bug; I cannot set labels from a fork)