def _fuse_cast_ops(self, cast_ops: List[Operation], reuse_input_var: bool = False):
        """
        Fuse the pattern of:
            input -> cast_1(dtype=dtype_1) -> cast_2(dtype=dtype_2) -> out

        If ``reuse_input_var = True``, the pattern is reduced to:
            input -> out

        otherwise, a new ``cast`` op with the same ``dtype`` as ``cast_2`` is created:
            input -> cast_3(dtype=dtype_2) -> out
        """
        if not isinstance(cast_ops[0], tuple):
            cast_ops = tuple((cast_ops,))

        ops_to_remove = []

        for cast_1, cast_2 in cast_ops:
            if reuse_input_var:
                new_output_var = self._dup_if_affect_io(cast_1.x, cast_2.outputs[0], cast_1)
            else:
                fused_output_var_name = cast_1.x.name + "_to_{}".format(cast_2.dtype.val)
                new_output_var = mb.cast(
                    x=cast_1.x,
                    dtype=cast_2.dtype,
                    name=fused_output_var_name,
                    before_op=cast_2,
                )
            # It's important to use `cast_2.enclosing_block` since `cast_2` might be present in a block nested under `cast_1.enclosing_block`
            cast_2.enclosing_block.replace_uses_of_var_after_op(
                anchor_op=cast_2,
                old_var=cast_2.outputs[0],
                new_var=new_output_var,
            )
            # Remove just the last cast op and let dce eliminate the rest of the ops if needed,
            # The reason is that first cast op could be feeding into other non-cast ops.
            ops_to_remove.append(cast_2)

        ops_to_remove[0].enclosing_block.remove_ops(ops_to_remove)

        Fuse the pattern of:
            input -> cast_1(dtype=dtype_1) -> cast_2(dtype=dtype_2) -> out

        If ``reuse_input_var = True``, the pattern is reduced to:
            input -> out

        otherwise, a new ``cast`` op with the same ``dtype`` as ``cast_2`` is created:
            input -> cast_3(dtype=dtype_2) -> out
        
coremltools/converters/mil/mil/passes/defs/optimize_repeat_ops.py