onnxslim 0.1.78__tar.gz → 0.1.80__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. {onnxslim-0.1.78/onnxslim.egg-info → onnxslim-0.1.80}/PKG-INFO +1 -1
  2. onnxslim-0.1.80/VERSION +1 -0
  3. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/ir/graph.py +117 -25
  4. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/symbolic_shape_infer.py +4 -2
  5. onnxslim-0.1.80/onnxslim/version.py +1 -0
  6. {onnxslim-0.1.78 → onnxslim-0.1.80/onnxslim.egg-info}/PKG-INFO +1 -1
  7. onnxslim-0.1.78/VERSION +0 -1
  8. onnxslim-0.1.78/onnxslim/version.py +0 -1
  9. {onnxslim-0.1.78 → onnxslim-0.1.80}/LICENSE +0 -0
  10. {onnxslim-0.1.78 → onnxslim-0.1.80}/MANIFEST.in +0 -0
  11. {onnxslim-0.1.78 → onnxslim-0.1.80}/README.md +0 -0
  12. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/__init__.py +0 -0
  13. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/__main__.py +0 -0
  14. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/argparser.py +0 -0
  15. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/cli/__init__.py +0 -0
  16. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/cli/_main.py +0 -0
  17. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/__init__.py +0 -0
  18. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/optimization/__init__.py +0 -0
  19. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/optimization/dead_node_elimination.py +0 -0
  20. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/optimization/subexpression_elimination.py +0 -0
  21. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/optimization/weight_tying.py +0 -0
  22. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/__init__.py +0 -0
  23. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/elimination/__init__.py +0 -0
  24. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/elimination/concat.py +0 -0
  25. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/elimination/reshape.py +0 -0
  26. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/elimination/reshape_as.py +0 -0
  27. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/elimination/slice.py +0 -0
  28. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/elimination/unsqueeze.py +0 -0
  29. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/__init__.py +0 -0
  30. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/concat_reshape.py +0 -0
  31. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/convadd.py +0 -0
  32. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/convbn.py +0 -0
  33. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/convmul.py +0 -0
  34. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/gelu.py +0 -0
  35. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/gemm.py +0 -0
  36. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/padconv.py +0 -0
  37. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/fusion/reduce.py +0 -0
  38. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/core/pattern/registry.py +0 -0
  39. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/misc/__init__.py +0 -0
  40. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/misc/tabulate.py +0 -0
  41. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/__init__.py +0 -0
  42. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/_sympy/__init__.py +0 -0
  43. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/_sympy/functions.py +0 -0
  44. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/_sympy/numbers.py +0 -0
  45. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/_sympy/printers.py +0 -0
  46. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/_sympy/solve.py +0 -0
  47. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/_sympy/symbol.py +0 -0
  48. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/__init__.py +0 -0
  49. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/exporters/__init__.py +0 -0
  50. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/exporters/base_exporter.py +0 -0
  51. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/exporters/onnx_exporter.py +0 -0
  52. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/graph_pattern/__init__.py +0 -0
  53. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/graph_pattern/graph_pattern.py +0 -0
  54. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/importers/__init__.py +0 -0
  55. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/importers/base_importer.py +0 -0
  56. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/importers/onnx_importer.py +0 -0
  57. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/ir/__init__.py +0 -0
  58. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/ir/function.py +0 -0
  59. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/ir/node.py +0 -0
  60. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/ir/tensor.py +0 -0
  61. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/logger/__init__.py +0 -0
  62. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/logger/logger.py +0 -0
  63. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/util/__init__.py +0 -0
  64. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/util/exception.py +0 -0
  65. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/third_party/onnx_graphsurgeon/util/misc.py +0 -0
  66. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim/utils.py +0 -0
  67. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim.egg-info/SOURCES.txt +0 -0
  68. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim.egg-info/dependency_links.txt +0 -0
  69. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim.egg-info/entry_points.txt +0 -0
  70. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim.egg-info/requires.txt +0 -0
  71. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim.egg-info/top_level.txt +0 -0
  72. {onnxslim-0.1.78 → onnxslim-0.1.80}/onnxslim.egg-info/zip-safe +0 -0
  73. {onnxslim-0.1.78 → onnxslim-0.1.80}/pyproject.toml +0 -0
  74. {onnxslim-0.1.78 → onnxslim-0.1.80}/setup.cfg +0 -0
  75. {onnxslim-0.1.78 → onnxslim-0.1.80}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onnxslim
3
- Version: 0.1.78
3
+ Version: 0.1.80
4
4
  Summary: OnnxSlim: A Toolkit to Help Optimize Onnx Model
5
5
  Home-page: https://github.com/inisis/OnnxSlim
6
6
  Author: inisis
@@ -0,0 +1 @@
1
+ 0.1.80
@@ -978,17 +978,46 @@ class Graph:
978
978
  return next(iter(tensor.values)) if tensor.shape else tensor.values
979
979
 
980
980
  def fold_shape(tensor):
981
- """Returns the input tensor shape if available, otherwise returns None."""
982
- inp = get_input(get_producer(tensor, "Shape"))
981
+ """Returns the input tensor shape if available, otherwise returns None.
982
+ Handles Shape node with optional 'start' and 'end' attributes (opset 15+).
983
+ """
984
+ shape_node = get_producer(tensor, "Shape")
985
+ inp = get_input(shape_node)
983
986
  if inp is None:
984
987
  return None
985
988
 
986
989
  if inp.shape is None or misc.is_dynamic_shape(inp.shape):
987
990
  return None
988
- return np.array(inp.shape, dtype=np.int64)
991
+
992
+ full_shape = inp.shape
993
+ num_dims = len(full_shape)
994
+
995
+ # Get start and end attributes (default: start=0, end=None means full shape)
996
+ start = shape_node.attrs.get("start", 0)
997
+ end = shape_node.attrs.get("end", None)
998
+
999
+ # Handle negative indices
1000
+ if start < 0:
1001
+ start = num_dims + start
1002
+ if end is None:
1003
+ end = num_dims
1004
+ elif end < 0:
1005
+ end = num_dims + end
1006
+
1007
+ # Clamp to valid range
1008
+ start = max(0, min(start, num_dims))
1009
+ end = max(0, min(end, num_dims))
1010
+
1011
+ if start > end:
1012
+ return None
1013
+
1014
+ target_shape = full_shape[start:end]
1015
+ return np.array(target_shape, dtype=np.int64)
989
1016
 
990
1017
  def fold_shape_gather(tensor):
991
- """Retrieves and returns the shape of the input tensor as a NumPy array, otherwise returns None."""
1018
+ """Retrieves and returns the shape of the input tensor as a NumPy array, otherwise returns None.
1019
+ Handles Shape node with optional 'start' and 'end' attributes (opset 15+).
1020
+ """
992
1021
  gather = get_producer(tensor, "Gather")
993
1022
  if gather is None:
994
1023
  return None
@@ -996,69 +1025,132 @@ class Graph:
996
1025
  data = gather.inputs[0]
997
1026
  indices_tensor = gather.inputs[1]
998
1027
 
999
- inp = get_input(get_producer(data, "Shape"))
1028
+ shape_node = get_producer(data, "Shape")
1029
+ inp = get_input(shape_node)
1000
1030
  if inp is None or inp.shape is None:
1001
1031
  return None
1002
1032
 
1003
1033
  if not isinstance(indices_tensor, Constant):
1004
1034
  return None
1005
1035
 
1036
+ # Get the shape slice from Shape node (considering start/end attributes)
1037
+ full_shape = inp.shape
1038
+ num_dims = len(full_shape)
1039
+
1040
+ start = shape_node.attrs.get("start", 0)
1041
+ end = shape_node.attrs.get("end", None)
1042
+
1043
+ if start < 0:
1044
+ start = num_dims + start
1045
+ if end is None:
1046
+ end = num_dims
1047
+ elif end < 0:
1048
+ end = num_dims + end
1049
+
1050
+ start = max(0, min(start, num_dims))
1051
+ end = max(0, min(end, num_dims))
1052
+
1053
+ if start > end:
1054
+ return None
1055
+
1056
+ shape_slice = full_shape[start:end]
1057
+
1006
1058
  indices = indices_tensor.values
1007
1059
  if not indices.shape: # Scalar-case
1008
- shape = inp.shape[int(indices)]
1060
+ idx = int(indices)
1061
+ # Handle negative indices relative to shape_slice
1062
+ if idx < 0:
1063
+ idx = len(shape_slice) + idx
1064
+ if idx < 0 or idx >= len(shape_slice):
1065
+ return None
1066
+ shape = shape_slice[idx]
1009
1067
  if misc.is_dynamic_dimension(shape):
1010
1068
  return None
1011
1069
  else:
1012
- shape = [inp.shape[index] for index in indices]
1070
+ shape = []
1071
+ for index in indices:
1072
+ idx = int(index)
1073
+ # Handle negative indices relative to shape_slice
1074
+ if idx < 0:
1075
+ idx = len(shape_slice) + idx
1076
+ if idx < 0 or idx >= len(shape_slice):
1077
+ return None
1078
+ shape.append(shape_slice[idx])
1013
1079
  if misc.is_dynamic_shape(shape):
1014
1080
  return None
1015
1081
 
1016
1082
  return np.array(shape, dtype=np.int64)
1017
1083
 
1018
1084
  def fold_shape_slice(tensor):
1019
- """Fold tensor shape slice information into a NumPy array of int64 type."""
1020
- slice = get_producer(tensor, "Slice")
1021
- if slice is None:
1085
+ """Fold tensor shape slice information into a NumPy array of int64 type.
1086
+ Handles Shape node with optional 'start' and 'end' attributes (opset 15+).
1087
+ """
1088
+ slice_node = get_producer(tensor, "Slice")
1089
+ if slice_node is None:
1022
1090
  return None
1023
1091
 
1024
- data = slice.inputs[0]
1092
+ data = slice_node.inputs[0]
1025
1093
 
1026
- if len(slice.inputs) >= 3:
1027
- starts, ends = slice.inputs[1:3]
1094
+ if len(slice_node.inputs) >= 3:
1095
+ starts, ends = slice_node.inputs[1:3]
1028
1096
  if any(not isinstance(t, Constant) for t in [starts, ends]):
1029
1097
  return None
1030
1098
  starts, ends = get_scalar_value(starts), get_scalar_value(ends)
1031
- elif "starts" in slice.attrs and "ends" in slice.attrs:
1032
- starts, ends = slice.attrs["starts"][0], slice.attrs["ends"][0]
1099
+ elif "starts" in slice_node.attrs and "ends" in slice_node.attrs:
1100
+ starts, ends = slice_node.attrs["starts"][0], slice_node.attrs["ends"][0]
1033
1101
  else:
1034
1102
  return None
1035
1103
 
1036
- inp = get_input(get_producer(data, "Shape"))
1104
+ shape_node = get_producer(data, "Shape")
1105
+ inp = get_input(shape_node)
1037
1106
  if inp is None or inp.shape is None:
1038
1107
  return None
1039
1108
 
1040
1109
  # For shape tensors, we can only slice on the 0th dimension.
1041
- if len(slice.inputs) > 3:
1042
- axes = slice.inputs[3]
1110
+ if len(slice_node.inputs) > 3:
1111
+ axes = slice_node.inputs[3]
1043
1112
  if not isinstance(axes, Constant):
1044
1113
  return None
1045
1114
 
1046
1115
  if get_scalar_value(axes) != 0:
1047
1116
  return None
1048
- elif "axes" in slice.attrs:
1049
- if slice.attrs["axes"][0] != 0:
1117
+ elif "axes" in slice_node.attrs:
1118
+ if slice_node.attrs["axes"][0] != 0:
1050
1119
  return None
1051
1120
 
1052
1121
  steps = 1
1053
- if len(slice.inputs) > 4:
1054
- steps = slice.inputs[4]
1122
+ if len(slice_node.inputs) > 4:
1123
+ steps = slice_node.inputs[4]
1055
1124
  if not isinstance(steps, Constant):
1056
1125
  return None
1057
1126
  steps = get_scalar_value(steps)
1058
- elif "steps" in slice.attrs:
1059
- steps = slice.attrs["steps"][0]
1127
+ elif "steps" in slice_node.attrs:
1128
+ steps = slice_node.attrs["steps"][0]
1129
+
1130
+ # Get the shape slice from Shape node (considering start/end attributes)
1131
+ full_shape = inp.shape
1132
+ num_dims = len(full_shape)
1133
+
1134
+ shape_start = shape_node.attrs.get("start", 0)
1135
+ shape_end = shape_node.attrs.get("end", None)
1136
+
1137
+ if shape_start < 0:
1138
+ shape_start = num_dims + shape_start
1139
+ if shape_end is None:
1140
+ shape_end = num_dims
1141
+ elif shape_end < 0:
1142
+ shape_end = num_dims + shape_end
1143
+
1144
+ shape_start = max(0, min(shape_start, num_dims))
1145
+ shape_end = max(0, min(shape_end, num_dims))
1146
+
1147
+ if shape_start > shape_end:
1148
+ return None
1149
+
1150
+ shape_slice = full_shape[shape_start:shape_end]
1060
1151
 
1061
- shape = inp.shape[starts:ends:steps]
1152
+ # Apply the Slice operation on the shape_slice
1153
+ shape = shape_slice[starts:ends:steps]
1062
1154
  if misc.is_dynamic_shape(shape):
1063
1155
  return None
1064
1156
 
@@ -1865,8 +1865,10 @@ class SymbolicShapeInference:
1865
1865
  else:
1866
1866
  scales = list(scales)
1867
1867
  new_sympy_shape = [
1868
- (round(d * (end - start) * scale))
1869
- for d, start, end, scale in zip(input_sympy_shape, roi_start, roi_end, scales)
1868
+ sympy.floor(d * (end - start) * scale + sympy.Rational(1, 2))
1869
+ for d, start, end, scale in zip(
1870
+ input_sympy_shape, roi_start, roi_end, scales
1871
+ )
1870
1872
  ]
1871
1873
  self._update_computed_dims(new_sympy_shape)
1872
1874
  else:
@@ -0,0 +1 @@
1
+ __version__ = "0.1.80"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: onnxslim
3
- Version: 0.1.78
3
+ Version: 0.1.80
4
4
  Summary: OnnxSlim: A Toolkit to Help Optimize Onnx Model
5
5
  Home-page: https://github.com/inisis/OnnxSlim
6
6
  Author: inisis
onnxslim-0.1.78/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.78
@@ -1 +0,0 @@
1
- __version__ = "0.1.78"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes