-
Notifications
You must be signed in to change notification settings - Fork 713
Closed
Labels
bugUnexpected behaviour that should be corrected (type)Unexpected behaviour that should be corrected (type)triagedReviewed and examined, release as been assigned if applicable (status)Reviewed and examined, release as been assigned if applicable (status)
Description
🐞Describing the bug
When using torch.nn.functional.pad(x, (1, x.size(-1)))
with dynamic pad size, coremltools throws an error at line
if pad.val is not None: |
Stack Trace

To Reproduce
import torch
import numpy as np
import coremltools as ct
class SimpleModel(torch.nn.Module):
def __init__(self):
super().__init__()
def forward(self, x: torch.Tensor) -> torch.Tensor:
return torch.nn.functional.pad(x, (1, x.size(-1)))
example_input = torch.rand(3)
traced_model = torch.jit.trace(SimpleModel(), example_input)
for i in range(2, 10):
x = torch.rand(i)
output = traced_model(x)
print(f"{x.shape}: {output.shape}")
input_shape = ct.EnumeratedShapes(shapes=[[1], [2], [3]], default=[2])
model = ct.convert(
traced_model,
convert_to="mlprogram",
inputs=[ct.TensorType(shape=input_shape, name="input", dtype=np.float32)],
outputs=[ct.TensorType(name="output", dtype=np.float32)],
)
System environment (please complete the following information):
- coremltools version: 8.3.0
- OS (e.g. MacOS version or Linux type): macOS 15.6
- Any other relevant version information (e.g. PyTorch or TensorFlow version): PyTorch 2.6.0
Metadata
Metadata
Assignees
Labels
bugUnexpected behaviour that should be corrected (type)Unexpected behaviour that should be corrected (type)triagedReviewed and examined, release as been assigned if applicable (status)Reviewed and examined, release as been assigned if applicable (status)