8000 Internal Assertion Failure in torch.tensor() in Restricted eval() Environment · Issue #155224 · pytorch/pytorch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Internal Assertion Failure in torch.tensor() in Restricted eval() Environment 8000  #155224
Closed
@LiSsHhUuAaIi

Description

@LiSsHhUuAaIi

🐛 Describe the bug

When using eval() with a restricted environment (builtins = None), only torch.tensor() creation fails with an internal assertion failure at DynamicTypes.cpp:71. Other tensor creation methods like torch.randn() and torch.randint() work correctly in the same environment.

import torch

env = {
    "torch": torch,
    "__builtins__": None  #Critical trigger
}

x = eval("torch.randn(5)", env) # Works
print("x:", x)
y = eval("torch.randint(0, 10, (5, )) ", env) # Works
print("y:", y)
z = eval("torch.tensor(3, dtype=torch.int64)", env) # Fails
print("z:", z)

Error Message

x: tensor([ 0.8359,  0.2416,  1.8487, -0.2097, -0.5932])
y: tensor([5, 1, 4, 5, 1])
Traceback (most recent call last):
  File "test.py", line 14, in <module>
    z = eval("torch.tensor(3, dtype=torch.int64)", env)
  File "<string>", line 1, in <module>
RuntimeError: storage_module && PyModule_Check(storage_module) INTERNAL ASSERT FAILED at "C:\\actions-runner\\_work\\pytorch\\pytorch\\pytorch\\torch\\csrc\\DynamicTypes.cpp":71, please report a bug to PyTorch.

Versions

Collecting environment information...
PyTorch version: 2.7.0+cpu
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Microsoft Windows 11
GCC version: Could not collect
Clang version: Could not collect
CMake version: version 4.0.2
Libc version: N/A

Python version: 3.10.10 (tags/v3.10.10:aad5f6a, Feb 7 2023, 17:20:36) [MSC v.1929 64 bit (AMD64)] (64-bit runtime)
Python platform: Windows-10-10.0.26100-SP0
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Name: AMD Ryzen 5 7500F 6-Core Processor
Manufacturer: AuthenticAMD
Family: 107
Architecture: 9
ProcessorType: 3
DeviceID: CPU0
CurrentClockSpeed: 3701
MaxClockSpeed: 3701
L2CacheSize: 6144
L2CacheSpeed: None
Revision: 24834

Versions of relevant libraries:
[pip3] mypy_extensions==1.1.0
[pip3] numpy==2.2.4
[pip3] nvidia-cuda-runtime-cu12==12.9.37
[pip3] > [pip3] onnx-coreml==1.3
[pip3] onnx-tf==1.10.0
[pip3] > [pip3] > [pip3] > [pip3] optree==0.15.0
[pip3] pytorch-lightning==2.5.1
[pip3] torch==2.7.0
[pip3] torch-directml==0.2.5.dev240914
[pip3] torch-geometric==2.6.1
[pip3] torch_scatter==2.1.2
[pip3] torch_tensorrt==2.7.0
[pip3] torchani==2.2.4
[pip3] torchao==0.11.0
[pip3] torchaudio==2.7.0
[pip3] torchdata==0.11.0
[pip3] torchfx==0.1.0
[pip3] torchmetrics==1.7.1
[pip3] torchrec==0.1.0
[pip3] torchsummary==1.5.1
[pip3] torchtext==0.18.0
[pip3] torchvision==0.19.1
[pip3] torchviz==0.0.3
[pip3] torchx-nightly==2025.5.28
[pip3] vector-quantize-pytorch==1.22.16
[conda] Could not collect

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0