Coder Social home page Coder Social logo

Comments (2)

jerrychenhf avatar jerrychenhf commented on June 26, 2024

This problem is related a few changes.

#104689 has a fix in 2.1.0 for "Inplace tensor update on transpose" problem for HPU or other devices that doens't have support on non contiguous output.But this PR cause some issues in part of the code calling wrap_output_with_input_device_.

#119868 reverted part of the code of #104689 to fix the new issues in 2.3.0. So the original issue in #103650 reopens in 2.3.0

from pytorch.

jerrychenhf avatar jerrychenhf commented on June 26, 2024

There are cases that a FakeTensor is not reserve its fakeness when calling into convert_element_type.
For example, the following code run on CPU, the input FakeTensor is not preserved in output of type conversion in _to_copy decomposition for some calls.

import torch

def fn(a):
 b = a.t()
 b.mul_(1.0)
 return b

x = torch.arange(6).reshape([2, 3]).to('cpu')

print("x ", x.cpu())

compiled_fn = torch.compile(fn)
y = compiled_fn(x)

print("y ", y.cpu())

_to_copy start: FakeTensor(..., device='meta', size=(3, 2), dtype=torch.int64)
after type converted: tensor(..., device='meta', size=(3, 2))
_to_copy start: FakeTensor(..., size=(3, 2))
after type converted: FakeTensor(..., size=(3, 2), dtype=torch.int64)
_to_copy start: FakeTensor(..., size=(3, 2))
after type converted: FakeTensor(..., size=(3, 2), dtype=torch.int64)

I found usually the convert_element_type_meta is called under the fake mode if necessary and torch.empty_strided in the TensorMeta function will return FakeTensor in such case. But I am not sure why the first call in the above case doesn't preserve the Fakeness (Is this itself a bug?)

I read through the discussions in #119868. There were a few proposals.

Is there any problem of the initial proposal of "checking the input and current type as the fakeness and call wrap_output_with_input_device only necessary"?
I think convert_element_type_meta is much more impactful if we want to give convert_element_type_meta the semantics of preserving fakeness. Please suggest.

@ezyang @laithsakka

from pytorch.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.