{"id":24604,"library":"sne4onnx","title":"sne4onnx","description":"A lightweight tool for extracting subgraphs (model slicing) from ONNX models. Useful when onnx-simplifier exceeds the 2GB Protocol Buffers file size limit, or to split models into arbitrary sizes. Current version 2.0.1, released June 2024. Development is active.","status":"active","version":"2.0.1","language":"python","source_language":"en","source_url":"https://github.com/PINTO0309/sne4onnx","tags":["onnx","model extraction","subgraph","slicing","neural network"],"install":[{"cmd":"pip install sne4onnx","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Core dependency for loading, manipulating, and saving ONNX models","package":"onnx","optional":false}],"imports":[{"note":"The main module exposes both CLI and Python API; no submodule import needed.","wrong":"","symbol":"sne4onnx","correct":"import sne4onnx"}],"quickstart":{"code":"import onnx\nfrom sne4onnx import extraction\n\n# Load an ONNX model\nmodel = onnx.load('model.onnx')\n\n# Define input and output operation names for the subgraph\ninput_names = ['input']  # name of the input tensor or node\noutput_names = ['output']  # name of the output tensor or node\n\n# Extract the subgraph\nnew_model = extraction(model, input_names, output_names)\n\n# Save the extracted model\nonnx.save(new_model, 'extracted.onnx')","lang":"python","description":"Extract a subgraph from an ONNX model by specifying input and output operation names."},"warnings":[{"fix":"Update to v2.0.0+ and ensure no usage of `onnx_graphsurgeon` inside sne4onnx (it is no longer a dependency).","message":"In version 2.0.0, dependency on `onnx_graphsurgeon` was removed. Code that relied on internals of `onnx_graphsurgeon` or used sne4onnx together with it may break.","severity":"breaking","affected_versions":"<2.0.0"},{"fix":"Use node names (e.g., from model.graph.node[i].name) as input/output_op_names. Inspect the model's graph nodes to find correct names.","message":"The extraction function expects operation (node) names, not tensor names. Providing tensor names may silently fail or produce unexpected subgraphs.","severity":"gotcha","affected_versions":"all"},{"fix":"Avoid calling `onnx.shape_inference.infer_shapes()` on models with external data before extraction. Let sne4onnx handle it.","message":"When using external data (large models with external data files), the library may corrupt the model if shape inference is run. Version 1.0.15 fixed this, but if you manually call `onnx.shape_inference.infer_shapes()` before extraction, you may encounter issues.","severity":"gotcha","affected_versions":">=1.0.15"},{"fix":"Use `sne4onnx -h` to see current CLI arguments. Prefer long-form options for scripts to avoid ambiguity.","message":"The CLI `sne4onnx` arguments changed between versions. Short form parameters were added in v1.0.10 but long form (`--input_onnx_file_path`) may still be used. In v2.0.0, the CLI remains similar but ensure you use the correct syntax.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use `from sne4onnx import extraction` or `from sne4onnx.extraction import extraction`. The correct import is: from sne4onnx import extraction","cause":"Incorrect import path; attempting to call extraction as a top-level attribute.","error":"AttributeError: module 'sne4onnx' has no attribute 'extraction'"},{"fix":"Use node names (e.g., from model.graph.node[i].name). Convert tensor names to node names if necessary.","cause":"Providing tensor names instead of node (operation) names.","error":"KeyError: 'input_tensor_name'"},{"fix":"Ensure input_op_names and output_op_names refer to nodes that form a valid subgraph. Use onnx.checker.check_model on the extracted model to debug.","cause":"Extracted subgraph may have dangling inputs or outputs that are not connected properly.","error":"onnx.onnx_cpp2py_export.checker.ValidationError: Model validation failed."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}