Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement indexing operations in PyTorch #910

Merged
merged 1 commit into from
Sep 1, 2024

Conversation

HarshvirSandhu
Copy link
Contributor

@HarshvirSandhu HarshvirSandhu commented Jul 9, 2024

Implement indexing ops in pytorch

  • Subtensor
  • IncSubtensor
  • AdvancedSubtensor[1]
  • AdvancedIncSubtensor[1]

Description

Related Issue

Checklist

Type of change

  • New feature / enhancement

@ricardoV94 ricardoV94 changed the title Implement indexing Ops Implement indexing operations in PyTorch Jul 9, 2024
@ricardoV94 ricardoV94 added torch PyTorch backend enhancement New feature or request labels Jul 9, 2024
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 85.41667% with 14 lines in your changes missing coverage. Please review.

Project coverage is 81.74%. Comparing base (1a1c62b) to head (b38a01c).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pytensor/link/pytorch/dispatch/subtensor.py 84.61% 9 Missing and 3 partials ⚠️
pytensor/link/pytorch/dispatch/basic.py 87.50% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #910   +/-   ##
=======================================
  Coverage   81.73%   81.74%           
=======================================
  Files         182      183    +1     
  Lines       47633    47724   +91     
  Branches    11604    11616   +12     
=======================================
+ Hits        38934    39011   +77     
- Misses       6509     6520   +11     
- Partials     2190     2193    +3     
Files with missing lines Coverage Δ
pytensor/compile/mode.py 84.54% <ø> (ø)
pytensor/link/pytorch/dispatch/__init__.py 100.00% <100.00%> (ø)
pytensor/link/pytorch/dispatch/basic.py 93.33% <87.50%> (-1.54%) ⬇️
pytensor/link/pytorch/dispatch/subtensor.py 84.61% <84.61%> (ø)

pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/basic.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
tests/link/pytorch/test_subtensor.py Outdated Show resolved Hide resolved
tests/link/pytorch/test_subtensor.py Outdated Show resolved Hide resolved
tests/link/pytorch/test_subtensor.py Show resolved Hide resolved
Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking pretty good! Some change requests and suggestions to make the tests more robust.

pytensor/link/pytorch/dispatch/basic.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/basic.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
tests/link/pytorch/test_subtensor.py Show resolved Hide resolved
tests/link/pytorch/test_subtensor.py Outdated Show resolved Hide resolved
Copy link
Member

@ricardoV94 ricardoV94 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting there, some smaller feedback this time

pytensor/link/pytorch/dispatch/subtensor.py Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
tests/link/pytorch/test_subtensor.py Outdated Show resolved Hide resolved
tests/link/pytorch/test_subtensor.py Outdated Show resolved Hide resolved
pytensor/link/pytorch/dispatch/subtensor.py Outdated Show resolved Hide resolved
@ricardoV94
Copy link
Member

@HarshvirSandhu I pushed some simplification and also needed special logic for repeated indices in IncSubtensor. Feel free to review and see if you spot any issues. Note that I squashed the commits and force-pushed, so you'll have to retrieve the remote branch before you can do any changes

Co-authored-by: Ricardo Vieira <28983449+ricardov94@users.noreply.github.com>
Comment on lines +62 to +65
if not inplace:
x = x.clone()
x[indices] = y
return x
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works for me locally, are you sure it wasn't working on your end?

@ricardoV94 ricardoV94 merged commit 4134881 into pymc-devs:main Sep 1, 2024
59 of 60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request torch PyTorch backend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants