8000 tensor_to_numpy symbol not exported in libtorch_python.so in pytorch 2.7 · Issue #154105 · pytorch/pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to 8000 content
tensor_to_numpy symbol not exported in libtorch_python.so in pytorch 2.7 #154105
Closed
@youkaichao

Description

@youkaichao

🐛 Describe the bug

Here is a simple file:

import torch
from torch.utils.cpp_extension import load_inline

cpp_source = """
#include <torch/extension.h>
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>

// NOTE: This is an internal utility.
namespace py = pybind11;

py::object tensor_to_numpy_func(torch::Tensor tensor) {
    // Use internal PyTorch utility
    return py::reinterpret_steal<py::object>(torch::utils::tensor_to_numpy(tensor));
}

"""

# Load the inline extension
tensor_utils = load_inline(
    name="tensor_to_numpy_internal",
    cpp_sources=cpp_source,
    functions=["tensor_to_numpy_func"],
    with_cuda=False,
    verbose=True,
    extra_cflags=["-O3"]
)

# Usage
if __name__ == "__main__":
    tensor = torch.tensor([[1.0, 2.0], [3.0, 4.0]], dtype=torch.float32)
    numpy_array = tensor_utils.tensor_to_numpy_func(tensor)
    
    print(numpy_array)
    print(type(numpy_array))

It works in pytorch 2.6 (cuda build, installed by pip install torch==2.6), but errors in pytorch 2.7 (cuda build, installed by pip install torch==2.7).

the error is:

ImportError: tensor_to_numpy_internal.so: undefined symbol: _ZN5torch5utils15tensor_to_numpyERKN2at6TensorEb

And then I inspected the so file:

$ nm -D libtorch_python.so | grep tensor_to_numpy 
# no output for pytorch 2.7

# has output for pytorch 2.6
0000000000dba6d0 T _ZN5torch5utils15tensor_to_numpyERKN2at6TensorEb

seems to be some build configuration bugs

Versions

linux x86 machine

cc @jbschlosser @mruberry @rgommers

Metadata

Metadata

Assignees

No one assigned

    Labels

    actionablemodule: cppRelated to C++ APImodule: numpyRelated to numpy support, and also numpy compatibility of our operatorstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0