pytorch - ✅(Solved) Fix Offsets validation raises unclear errors and inconsistent messages [1 pull requests, 1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#177228Fetched 2026-04-08 00:21:46
View on GitHub
Comments
1
Participants
1
Timeline
27
Reactions
0
Author
Participants
Timeline (top)
mentioned ×10subscribed ×10labeled ×4cross-referenced ×2

Error Message

  • If offsets is None, the error message could be more informative.
  • Update grammar and wording of error messages to match the rest of the codebase.

Fix Action

Fixed

PR fix notes

PR #177241: Fix offsets validation and improve error message consistency

Description (problem / solution / changelog)

Fixes #177228.

This PR updates torch/nn/functional.py to properly validate the offsets tensor when input is 1D:

  • Ensures offsets is properly checked when None
  • Raises clear and consistent ValueErrors for incorrectly shaped offsets tensors
  • Updates error message grammar, capitalization, and wording for readability and consistency across the codebase

This ensures tensor shape errors are easier to debug and error messages are clear and consistent.

Changed files

  • torch/nn/functional.py (modified, +6961/-6913)
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Problem

When input is 1D in torch/nn/functional.py, the offsets tensor validation is unclear.
Specifically:

  • If offsets is None, the error message could be more informative.
  • If offsets has the wrong dimensions, the message is inconsistent with the rest of the codebase.

These inconsistencies make it harder for users to debug tensor shape issues.

Proposed improvement

  • Ensure offsets is properly checked when input is 1D.
  • Raise clear and consistent ValueErrors for None or incorrectly shaped tensors.
  • Update grammar and wording of error messages to match the rest of the codebase.

Location: torch/nn/functional.py, offsets validation section when input.dim() == 1.

This would improve both correctness and readability.

Versions

Collecting environment information... PyTorch version: N/A Is debug build: N/A CUDA used to build PyTorch: N/A ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11 Home (10.0.26200 64-bit) GCC version: Could not collect Clang version: Could not collect CMake version: Could not collect Libc version: N/A

Python version: 3.13.1 (tags/v3.13.1:0671451, Dec 3 2024, 19:06:28) [MSC v.1942 64 bit (AMD64)] (64-bit runtime) Python platform: Windows-11-10.0.26200-SP0 Is CUDA available: N/A CUDA runtime version: Could not collect CUDA_MODULE_LOADING set to: N/A GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4060 Laptop GPU Nvidia driver version: 577.02 cuDNN version: Could not collect Is XPU available: N/A HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: N/A Caching allocator config: N/A

CPU: Name: AMD Ryzen 7 8845HS w/ Radeon 780M Graphics Manufacturer: AuthenticAMD Family: 107 Architecture: 9 ProcessorType: 3 DeviceID: CPU0 CurrentClockSpeed: 3488 MaxClockSpeed: 3801 L2CacheSize: 8192 L2CacheSpeed: None Revision: 29954

Versions of relevant libraries: [pip3] numpy==2.4.2 [pip3] torch==2.12.0.dev20260225+cpu [pip3] torchaudio==2.11.0.dev20260224+cpu [pip3] torchvision==0.26.0.dev20260224+cpu [conda] Could not collect

cc @albanD @mruberry @jbschlosser @walterddr @mikaylagawarecki

extent analysis

Fix Plan

Ensure Proper offsets Validation

To fix the issue, we need to update the offsets validation in torch/nn/functional.py when input is 1D. Here's a step-by-step plan:

  1. Check for None offsets:

if input.dim() == 1 and offsets is None: raise ValueError("offsets cannot be None when input is 1D")


2. **Validate `offsets` shape**:
   ```python
if input.dim() == 1 and offsets is not None:
    if offsets.dim() != 1:
        raise ValueError("offsets must be 1D when input is 1D")
  1. Update error messages: Update the error messages to match the rest of the codebase. For example:

raise ValueError(f"Invalid offsets shape. Expected 1D tensor, but got {offsets.shape}")


4. **Apply changes**:
   Apply these changes to the `offsets` validation section in `torch/nn/functional.py` when `input.dim() == 1`.

### Verification

To verify that the fix worked:

1. **Test with `None` `offsets`**:
   Test that a `ValueError` is raised when `offsets` is `None` and `input` is 1D.

2. **Test with incorrectly shaped `offsets`**:
   Test that a `ValueError` is raised when `offsets` has the wrong shape and `input` is 1D.

3. **Test with correct `offsets`**:
   Test that no error is raised when `offsets` has the correct shape and `input` is 1D.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING