Skip to content

Commit d68ea6b

Browse files
authored
update pnnx ci torch 2.8.0 (#6238)
1 parent c276398 commit d68ea6b

16 files changed

+66
-30
lines changed

.github/workflows/pnnx.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ permissions:
2121
contents: read
2222

2323
env:
24-
LIBTORCH_VERSION: 2.7.1
25-
TORCHVISION_VERSION: 0.22.1
24+
LIBTORCH_VERSION: 2.8.0
25+
TORCHVISION_VERSION: 0.23.0
2626
PROTOBUF_VERSION: 21.12
2727
ONNXRUNTIME_VERSION: 1.22.1
28-
CACHE_DATE: 20250723
28+
CACHE_DATE: 20250807
2929
SEGMENT_DOWNLOAD_TIMEOUT_MINS: 15
3030

3131
jobs:
@@ -129,7 +129,6 @@ jobs:
129129
pip3 install -r requirements.txt --break-system-packages
130130
patch -p1 -i $GITHUB_WORKSPACE/pnnx-patches/pytorch-v${{ env.LIBTORCH_VERSION }}-fix-mobile-build.patch
131131
patch -p1 -i $GITHUB_WORKSPACE/pnnx-patches/pytorch-v${{ env.LIBTORCH_VERSION }}-no-link-system-lib.patch
132-
patch -p1 -i $GITHUB_WORKSPACE/pnnx-patches/pytorch-v${{ env.LIBTORCH_VERSION }}-fix-pocketfft-build.patch
133132
mkdir -p build && cd build
134133
cmake -DCMAKE_INSTALL_PREFIX=$GITHUB_WORKSPACE/libtorch-${{ env.LIBTORCH_VERSION }}-install \
135134
-DCMAKE_BUILD_TYPE=MinSizeRel \
@@ -247,6 +246,7 @@ jobs:
247246
- { python: '3.12', numpy: '2.2.5', opencv: '4.10.*', torch: '2.5.0', torchvision: '0.20.0', torchaudio: '2.5.0+cpu' }
248247
- { python: '3.12', numpy: '2.2.5', opencv: '4.11.*', torch: '2.6.0', torchvision: '0.21.0', torchaudio: '2.6.0+cpu' }
249248
- { python: '3.12', numpy: '2.2.5', opencv: '4.11.*', torch: '2.7.0', torchvision: '0.22.0', torchaudio: '2.7.0+cpu' }
249+
- { python: '3.13', numpy: '2.2.5', opencv: '4.12.*', torch: '2.8.0', torchvision: '0.23.0', torchaudio: '2.8.0+cpu' }
250250

251251
name: test-${{ matrix.torch }}-py${{ matrix.python }}
252252

tools/pnnx/src/pass_level2/F_layer_norm.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,11 @@ pnnx.Output output 1 0 out
157157
return false;
158158

159159
// dim must be the last N dimensions
160-
std::vector<int> dim = captured_params.at("dim").ai;
160+
std::vector<int> dim;
161+
if (captured_params.at("dim").type == 2)
162+
dim.push_back(captured_params.at("dim").i);
163+
else // if (captured_params.at("dim").type == 5)
164+
dim = captured_params.at("dim").ai;
161165

162166
const int input_rank = (int)inputshape.size();
163167
const int dim_count = (int)dim.size();
@@ -183,7 +187,11 @@ pnnx.Output output 1 0 out
183187
void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const
184188
{
185189
const std::vector<int>& inputshape = op->inputs[0]->shape;
186-
const std::vector<int>& dim = captured_params.at("dim").ai;
190+
std::vector<int> dim;
191+
if (captured_params.at("dim").type == 2)
192+
dim.push_back(captured_params.at("dim").i);
193+
else // if (captured_params.at("dim").type == 5)
194+
dim = captured_params.at("dim").ai;
187195
const int input_rank = (int)inputshape.size();
188196
const int dim_count = (int)dim.size();
189197

@@ -240,7 +248,11 @@ pnnx.Output output 1 0 out
240248
return false;
241249

242250
// dim must be the last N dimensions
243-
std::vector<int> dim = captured_params.at("dim").ai;
251+
std::vector<int> dim;
252+
if (captured_params.at("dim").type == 2)
253+
dim.push_back(captured_params.at("dim").i);
254+
else // if (captured_params.at("dim").type == 5)
255+
dim = captured_params.at("dim").ai;
244256

245257
const int input_rank = (int)inputshape.size();
246258
const int dim_count = (int)dim.size();
@@ -278,7 +290,11 @@ pnnx.Output output 1 0 out
278290
void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const
279291
{
280292
const std::vector<int>& inputshape = op->inputs[0]->shape;
281-
const std::vector<int>& dim = captured_params.at("dim").ai;
293+
std::vector<int> dim;
294+
if (captured_params.at("dim").type == 2)
295+
dim.push_back(captured_params.at("dim").i);
296+
else // if (captured_params.at("dim").type == 5)
297+
dim = captured_params.at("dim").ai;
282298
const int input_rank = (int)inputshape.size();
283299
const int dim_count = (int)dim.size();
284300

tools/pnnx/src/pass_level2/torch_max.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@ pnnx.Output output 2 0 out indices
147147
if (captured_params.find("op_1.keepdims") == captured_params.end())
148148
return false;
149149

150-
if (captured_params.at("op_0.axes").type != 5 || captured_params.at("op_0.axes").ai.size() != 1)
150+
if (captured_params.at("op_0.axes").type != 2 && (captured_params.at("op_0.axes").type != 5 || captured_params.at("op_0.axes").ai.size() != 1))
151151
return false;
152152

153153
if (captured_params.at("op_1.axis").type != 2)
154154
return false;
155155

156-
if (captured_params.at("op_0.axes").ai[0] != captured_params.at("op_1.axis").i)
156+
if (captured_params.at("op_0.axes").type == 2 && captured_params.at("op_0.axes").i != captured_params.at("op_1.axis").i)
157+
return false;
158+
159+
if (captured_params.at("op_0.axes").type == 5 && captured_params.at("op_0.axes").ai[0] != captured_params.at("op_1.axis").i)
157160
return false;
158161

159162
if (captured_params.at("op_0.keepdims").i != captured_params.at("op_1.keepdims").i)
@@ -164,7 +167,10 @@ pnnx.Output output 2 0 out indices
164167

165168
void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const
166169
{
167-
op->params["dim"] = captured_params.at("op_0.axes").ai[0];
170+
if (captured_params.at("op_0.axes").type == 2)
171+
op->params["dim"] = captured_params.at("op_0.axes").i;
172+
else
173+
op->params["dim"] = captured_params.at("op_0.axes").ai[0];
168174
op->params["keepdim"] = captured_params.at("op_0.keepdims").i ? true : false;
169175
}
170176
};

tools/pnnx/src/pass_level2/torch_min.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,16 @@ pnnx.Output output 2 0 out indices
147147
if (captured_params.find("op_1.keepdims") == captured_params.end())
148148
return false;
149149

150-
if (captured_params.at("op_0.axes").type != 5 || captured_params.at("op_0.axes").ai.size() != 1)
150+
if (captured_params.at("op_0.axes").type != 2 && (captured_params.at("op_0.axes").type != 5 || captured_params.at("op_0.axes").ai.size() != 1))
151151
return false;
152152

153153
if (captured_params.at("op_1.axis").type != 2)
154154
return false;
155155

156-
if (captured_params.at("op_0.axes").ai[0] != captured_params.at("op_1.axis").i)
156+
if (captured_params.at("op_0.axes").type == 2 && captured_params.at("op_0.axes").i != captured_params.at("op_1.axis").i)
157+
return false;
158+
159+
if (captured_params.at("op_0.axes").type == 5 && captured_params.at("op_0.axes").ai[0] != captured_params.at("op_1.axis").i)
157160
return false;
158161

159162
if (captured_params.at("op_0.keepdims").i != captured_params.at("op_1.keepdims").i)
@@ -164,7 +167,10 @@ pnnx.Output output 2 0 out indices
164167

165168
void write(Operator* op, const std::map<std::string, Parameter>& captured_params) const
166169
{
167-
op->params["dim"] = captured_params.at("op_0.axes").ai[0];
170+
if (captured_params.at("op_0.axes").type == 2)
171+
op->params["dim"] = captured_params.at("op_0.axes").i;
172+
else
173+
op->params["dim"] = captured_params.at("op_0.axes").ai[0];
168174
op->params["keepdim"] = captured_params.at("op_0.keepdims").i ? true : false;
169175
}
170176
};

tools/pnnx/src/pass_level5/fuse_slice_to_tensor_split.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,17 @@ void fuse_slice_to_tensor_split(Graph& graph)
9898
full_dimsize_slice = true;
9999
break;
100100
}
101-
if (!op_in->shape.empty() && end2 == op_in->shape[dim])
101+
if (!op_in->shape.empty())
102102
{
103-
slice_n_ops.push_back(op2);
104-
full_dimsize_slice = true;
105-
break;
103+
if (dim < 0)
104+
dim += op_in->shape.size();
105+
106+
if (end2 == op_in->shape[dim])
107+
{
108+
slice_n_ops.push_back(op2);
109+
full_dimsize_slice = true;
110+
break;
111+
}
106112
}
107113

108114
tensor_split_indices.push_back(end2);

tools/pnnx/src/pass_onnx/fuse_constant_as_attribute.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ static constant_as_attribute caas[] = {
2828
{"If", 0, "cond"},
2929
{"Pad", 1, "pads"},
3030
{"Pad", 2, "value"},
31+
{"ReduceL1", 1, "axes"},
32+
{"ReduceL2", 1, "axes"},
3133
{"ReduceLogSumExp", 1, "axes"},
3234
{"ReduceMax", 1, "axes"},
3335
{"ReduceMean", 1, "axes"},

tools/pnnx/tests/onnx/test_F_relu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test():
5252
return True
5353

5454
# export dynamo onnx
55-
torch.onnx.dynamo_export(net, x, y, z, w).save("test_F_relu_dynamo.onnx")
55+
torch.onnx.export(net, (x, y, z, w), "test_F_relu_dynamo.onnx", dynamo=True, external_data=False)
5656

5757
# onnx to pnnx
5858
os.system("../../src/pnnx test_F_relu_dynamo.onnx inputshape=[16],[2,16],[3,12,16],[5,7,9,11]")

tools/pnnx/tests/onnx/test_convnext_tiny.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ def test():
3232
if not torch.allclose(a, b, 1e-4, 1e-4):
3333
return False
3434

35-
if version.parse(torch.__version__) < version.parse('2.8'):
35+
if version.parse(torch.__version__) < version.parse('2.9'):
3636
return True
3737

3838
# export dynamo onnx
39-
torch.onnx.dynamo_export(net, x).save("test_convnext_tiny_dynamo.onnx")
39+
torch.onnx.export(net, (x,), "test_convnext_tiny_dynamo.onnx", dynamo=True, external_data=False)
4040

4141
# onnx to pnnx
4242
os.system("../../src/pnnx test_convnext_tiny_dynamo.onnx inputshape=[1,3,224,224]")

tools/pnnx/tests/onnx/test_mobilenet_v2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test():
3232
return True
3333

3434
# export dynamo onnx
35-
torch.onnx.dynamo_export(net, x).save("test_mobilenet_v2_dynamo.onnx")
35+
torch.onnx.export(net, (x,), "test_mobilenet_v2_dynamo.onnx", dynamo=True, external_data=False)
3636

3737
# onnx to pnnx
3838
os.system("../../src/pnnx test_mobilenet_v2_dynamo.onnx inputshape=[1,3,224,224]")

tools/pnnx/tests/onnx/test_mobilenet_v3_small.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test():
3535
return True
3636

3737
# export dynamo onnx
38-
torch.onnx.dynamo_export(net, x).save("test_mobilenet_v3_small_dynamo.onnx")
38+
torch.onnx.export(net, (x,), "test_mobilenet_v3_small_dynamo.onnx", dynamo=True, external_data=False)
3939

4040
# onnx to pnnx
4141
os.system("../../src/pnnx test_mobilenet_v3_small_dynamo.onnx inputshape=[1,3,224,224]")

0 commit comments

Comments
 (0)