def _transpose(v, name=None):
        """
        Transpose the last 2 dims.

        - ``v``: (Var, must be a tensor).
        - ``name``: Name for the ``transpose`` op if provided.
        """
        perm = list(range(v.rank))
        perm[-2], perm[-1] = perm[-1], perm[-2]

        if name is None:
            return mb.transpose(x=v, perm=perm)
        else:
            return mb.transpose(x=v, perm=perm, name=name)

        Transpose the last 2 dims.

        - ``v``: (Var, must be a tensor).
        - ``name``: Name for the ``transpose`` op if provided.
        
coremltools/converters/mil/mil/passes/defs/optimize_linear.py