Skip to content

[dtensor][view_op] add as_strided op support to DTensor in FakeTensorMode #151495

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

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update on "[dtensor][view_op] add as_strided op support to DTensor in…
… FakeTensorMode"

Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at bottom):

*  #151497
*  #151507
* __->__ #151495

## Introduction
`flex_attention`'s FakeTensor propagation `flex_attention_fake_impl` [permutes](https://github.com/pytorch/pytorch/blob/fb6ac2f16132f7953711ce6924bc2ee4a033228c/torch/_higher_order_ops/flex_attention.py#L459) the stride of `out` (the attention score) based on `query`'s stride. To enable `flex_attention` call on DTensor, this requires us add `as_strided` support on DTensor in `FakeTensorMode`. 

## Limited Support
Due to the complexity of supporting actual `as_strided` on DTensor, I choose to only enable a limited subset:
1. `as_strided` only works correctly in `FakeTensorMode` i.e. shape and strided propagation.
2. `as_strided` is only allowed in case where `size == input.shape` because this PR specifically unblocks the use case of `flex_attention_fake_impl`. 
3. `as_strided` requires `storage_offset=None` because the other case is not defined in DTensor.

## Test
`pytest test/distributed/tensor/test_view_ops.py -s -k test_as_strided`

cc H-Huang awgu wanchaol fegin fduwjj wz337 wconstab d4l3k tianyu-l

[ghstack-poisoned]
  • Loading branch information
XilunWu committed Apr 18, 2025
commit dc6df792ca6f13b0658f264cd6120d6c79634bdf

This merge commit was added into this branch cleanly.

There are no new changes to show, but you can still view the diff.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy