def _are_ops_identical(op1, op2):
        """
        Return True, if all inputs of op1 and op2 are identical.
        non-constant inputs must refer to the same object.

        For constant inputs, we only compare arrays with small size.
        Large size const ops are already deduplicated in the const_deduplication pass so we
        can compare the pointers.
        """

        def _are_values_identical(val1, val2):
            if not isinstance(val1, np.ndarray) or not isinstance(val2, np.ndarray):
                return np.array_equal(np.array(val1), np.array(val2))
            if val1.size != val2.size:
                return False
            if val1.size < 100:
                return np.array_equal(val1, val2)
            return False

        def _are_vars_identical(var1, var2):
            if var1 is var2:
                return True
            if var1.val is None and var2.val is None:
                if var1 != var2:
                    return False
            elif var1.val is not None and var2.val is not None:
                if var1.dtype != var2.dtype:
                    return False
                if not _are_values_identical(var1.val, var2.val):
                    return False
            else:
                return False
            return True

        if op1 == op2:
            return True
        if op1.op_type != op2.op_type:
            return False
        if len(op1.inputs) != len(op2.inputs):
            return False

        for key, value1 in op1.inputs.items():
            if key not in op2.inputs:
                return False
            value2 = op2.inputs[key]
            if isinstance(value1, Var) and isinstance(value2, Var):
                if not _are_vars_identical(value1, value2):
                    return False
            elif isinstance(value1, (list, tuple)) and isinstance(value2, (list, tuple)):
                if len(value1) != len(value2):
                    return False
                else:
                    for i, v in enumerate(value1):
                        if not _are_vars_identical(v, value2[i]):
                            return False
            else:
                return False

        assert len(op1.blocks) == 0, "this method does not handle ops that have blocks in it"
        assert len(op2.blocks) == 0, "this method does not handle ops that have blocks in it"
        return True

        Return True, if all inputs of op1 and op2 are identical.
        non-constant inputs must refer to the same object.

        For constant inputs, we only compare arrays with small size.
        Large size const ops are already deduplicated in the const_deduplication pass so we
        can compare the pointers.
        
coremltools/converters/mil/mil/passes/defs/cleanup/remove_redundant_ops.py