Skip to content

_unsafe_view returns copy if self has conjugate bit set #60478

Closed

Description

@soulitzer

Since _unsafe_view's schema has no alias info, ConjugateFallback considers it an out-of-place operation, so the conjugate is always materialized, producing a copy.

auto a = torch::tensor(1., at::TensorOptions().dtype(at::ScalarType::ComplexDouble)).conj();
auto b = at::_unsafe_view(a, {1});
b += 1;
std::cout << "a: " << a << "b: " << b << std::endl;

Output:

a: 
[W Copy.cpp:240] Warning: Casting complex values to real discards the imaginary part (function operator())
1
[ CPUComplexDoubleType{} ]
b: 
 2
[ CPUComplexDoubleType{1} ]

cc @ezyang @gchanan @zou3519 @bdhirsh @jbschlosser @anjali411 @dylanbespalko @mruberry @lezcano @nikitaved

Activity

  1. added
    module: complex
    on Jun 22, 2021
  2. soulitzer commented on Jun 22, 2021

    @soulitzer
    ContributorAuthor
  3. albanD commented on Jun 22, 2021

    @albanD
    Collaborator

    Adding high priority because _unsafe_view is used quite a bit to implement other ops, so that might break important ops.

  4. anjali411 commented on Jun 24, 2021

    @anjali411
    Contributor

    There's an easy fix for this one! we can add _unsafe_view to the fallthrough list here:

    TORCH_LIBRARY_IMPL(aten, Conjugate, m) {

    are there other ops similar to _unsafe_view that are views but their schema has no alias infos?

  5. albanD commented on Jun 24, 2021

    @albanD
    Collaborator

    Not that I'm aware of no.

  6. added
    triaged
    and removed on Jun 28, 2021
  7. 3 remaining items

  8. added a commit that references this issue on May 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    high prioritymodule: complextriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions