-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Labels
Description
Bug Report
Is the issue related to model conversion?
Partially.
Describe the bug
See pytorch/pytorch#130374 for an example of mainstream code which generates non-C90 compatible identifiers. The problem is that onnx
does not verify that such identifiers are indeed illegal allowing them to pass. Example:
import torch
class Linear(torch.nn.Module):
def __init__(self, input_shape: int = 784):
super().__init__()
self.input_shape = input_shape
self.fc = torch.nn.Linear(input_shape, 10)
def forward(self, x):
x = x.view(
x.shape[0], self.input_shape
) # num samples is first dim. Then flatten the rest
x = self.fc(x)
return x
sample_input = {'x': torch.randn(10, 784, 1) }
input_names = ['x']
dynamic_axes = { 'x': [0] }
model = Linear()
torch.onnx.export(
model,
args=(sample_input,),
f="/tmp/traced.onnx",
training=torch.onnx.TrainingMode.TRAINING,
do_constant_folding=False,
input_names=input_names,
dynamic_axes=dynamic_axes
)
import onnx
onnx.checker.check_model(onnx.load("/tmp/traced.onnx"))
The checker will pass at the end of the script. I expect it to fail since the identifiers do not comply with the IR specification: https://github.com/onnx/onnx/blob/main/docs/IR.md#names-within-a-graph
System information
Collecting environment information...
PyTorch version: 2.3.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A
OS: macOS 14.5 (arm64)
GCC version: Could not collect
Clang version: 15.0.0 (clang-1500.3.9.4)
CMake version: version 3.29.3
Libc version: N/A
Python version: 3.11.8 (main, May 31 2024, 14:37:05) [Clang 15.0.0 (clang-1500.3.9.4)] (64-bit runtime)
Python platform: macOS-14.5-arm64-arm-64bit
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:
Apple M3 Max
Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] onnx==1.16.1
[pip3] onnxscript==0.1.0.dev20240605
[pip3] torch==2.3.1
[pip3] torchvision==0.18.1
[conda] Could not collect
Reproduction instructions
See above
Expected behavior
Checker should fail