onnx-graphsurgeon: fix cycle detection bug in toposort by xhdhr10000 · Pull Request #4087 · NVIDIA/TensorRT

import onnx
import onnx_graphsurgeon as gs

graph = gs.import_onnx(onnx.load('./toposort.onnx'))
graph.toposort()
""" Out:
Graph onnx_graphsurgeon_graph (Opset 11)
Local Functions: []
Inputs: [Variable (input): (shape=[], dtype=float32)]
Nodes: identity_0 (Identity)
        Inputs: [
                Variable (input): (shape=[], dtype=float32)
        ]
        Outputs: [
                Variable (identity_0_output): (shape=[], dtype=float32)
        ]
neg_1 (Neg)
        Inputs: [
                Variable (identity_0_output): (shape=[], dtype=float32)
        ]
        Outputs: [
                Variable (neg_1_output): (shape=[], dtype=float32)
        ]
mul_0 (Mul)
        Inputs: [
                Variable (identity_0_output): (shape=[], dtype=float32)
                Variable (neg_1_output): (shape=[], dtype=float32)
        ]
        Outputs: [
                Variable (mul_0_output): (shape=[], dtype=float32)
        ]
Outputs: [Variable (mul_0_output): (shape=[], dtype=float32)]
"""