Skip to content

Conversation

@Nishant-ZFYII
Copy link

Closes #29734

Details

  • Implemented PyTorch Frontend translator for torch_scatter::segment_mean_csr using a prefix-sum + gather boundaries approach (no unrolling over segments).

  • The segmentation axis is computed dynamically as axis = indptr.dim() - 1 (matches torch_scatter semantics).

  • Added handling for batch/broadcast-style indptr (when axis > 0) via bidirectional broadcast to [src_batch_dims..., indptr_last_dim].

  • Uses i64 indices for indptr/shape operations to avoid overflow and to match Gather-supported index types.

  • Handles the optional out argument via context.mutate_input(out_idx, result) (if provided).

  • Added a regression test for TorchScript that covers:

    • 2D indptr with shape (1, n) (segments along dim 1)
    • 1D indptr (segments along dim 0)

Limitations / Notes

  • Requires static ranks for src and indptr (validated).
  • Empty segments (indptr[i+1] == indptr[i]) are handled by clamping length to 1 to avoid division by zero (result becomes 0 for empty segments).
  • Test is TorchScript-only and is skipped for torch.export / torch.compile backends and when torch_scatter is not installed.

How to test

  • PyTorch layer test:

    • python -m pytest tests/layer_tests/pytorch_tests/test_segment_mean_csr.py -k segment_mean_csr -v

Tickets

@Nishant-ZFYII Nishant-ZFYII requested a review from a team as a code owner January 4, 2026 06:24
@github-actions github-actions bot added the category: PyTorch FE OpenVINO PyTorch Frontend label Jan 4, 2026
@sys-openvino-ci sys-openvino-ci added the ExternalPR External contributor label Jan 4, 2026
@Nishant-ZFYII
Copy link
Author

@mvafin Can you please review .

Thanks. !

@Nishant-ZFYII
Copy link
Author

Nishant-ZFYII commented Jan 5, 2026

@mlukasze @p-wysocki

Good Day,

Kindly requesting you to review the PR. Please let me know if further changes are required.

Thanks and Regards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: PyTorch FE OpenVINO PyTorch Frontend ExternalPR External contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Good First Issue]: Support torch_scatter::segment_mean_csr

2 participants