fix: support tensor bounds and prevent in-place mask mutation in IntervalGuidance (#2241) #2242
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.43 · 383 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.356
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #2242"
general
weight: 0.35
patelshivani2283-lab
What does this PR do?
Fixes two issues in
IntervalGuidanceConfigandIntervalGuidanceinsbi/inference/potentials/vector_field_adaptor.py:1. Tensor bounds & scalar precision support:
IntervalGuidanceConfigtypeslower_boundandupper_boundasOptional[Union[float, Tensor]]. However,self.lower_bound >= self.upper_boundraisedRuntimeError: Boolean value of Tensor with more than one value is ambiguouswhen multidimensional tensors were passed.__post_init__now compares Python scalars directly (preserving precision for tight intervals such as1.0and1.0 + 1e-8) and converts non-scalars to tensors on matching devices using(lb >= ub).any(), correctly supporting floats, 0-d tensors, mixed-device tensors, and multidimensional tensors.2. Prevent in-place mask mutation:
interval_fnpreviously assignedconfig.mask = config.mask.unsqueeze(0).expand_as(out)in-place on the dataclass instance, corruptingconfig.maskfrom(D,)to(N1, D). Any subsequent evaluation with a different batch size $N_2$ (e.g. during ODE integration or multi-batch evaluation) crashed withRuntimeError: expand(...): the number of sizes provided (2) must be greater or equal to the number of dimensions in the tensor (3). It now uses a localmasktensor and broadcasts withmask.expand_as(out)without mutatingconfig.mask.3. Device & dtype preservation: Ensures tensor bounds and mask are moved to
device=input.deviceanddtype=input.dtypeto avoid device/dtype mismatch crashes when evaluating on GPU or with non-default dtypes.Does this close any issues?
Fixes #2241
Anything else we should know?
test_interval_guidance_config_tensor_bounds: validates valid/invalid tensor and scalar bounds (including tight intervals like1.0and1.0 + 1e-8) and bounds requirement.test_interval_guidance_with_mask_multiple_batch_sizes: verifies evaluations across different batch sizes (10, 5, 1) without mask mutation or runtime errors.test_interval_guidance_mask_semantics: verifies penalties are applied only to masked dimensions.pytest tests/score_samplers_test.py -k "test_interval_guidance").tests/linearGaussian_vector_field_test.pypass.ruff checkandruff format --checkpass on changed files.Checklist
uv run pytest -n auto -m "not slow and not gpu"passes.uv run pre-commit run --all-filespasses (ruff and formatting).uv run pyright sbipasses (verified on CI Linting workflow).pytest.mark.slow.An AI coding assistant was used to assist in identifying edge cases and writing tests. All changes and math were reviewed and verified locally.