def maybe_replace_symbols_with_source_tensor_shape_variables(
    shape: SYMBOLIC_SHAPE_TYPE, source_tensors: List[Var]
) -> VARIABLE_SHAPE_TYPE:
    """
    Given symbolic shape, replace symbols with source tensor shape variables

    Example:
        Given
            shape = [is0, is1]
            source_tensors = [x, y]
        where
            x.shape = [is0, 1]
            y.shape = [1, is1]
        we will return
            result_shape = [
                mb.slice_by_index(x=mb.shape(x=x), begin=[0], squeeze_mask=[True]),
                mb.slice_by_index(x=mb.shape(x=y), begin=[1], squeeze_mask=[True]),
            ]
    """
    result_shape = []
    for size in shape:
        if is_symbolic(size):
            found_symbol_source = False
            for tensor in source_tensors:
                for i in range(tensor.rank):
                    if str(size) == str(tensor.shape[i]):
                        result_shape.append(pymil_value_at(mb.shape(x=tensor), i))
                        found_symbol_source = True
                        break
                if found_symbol_source:
                    break
            if not found_symbol_source:
                raise ValueError(f"Symbol {str(size)} not found in source tensor shapes")
        else:
            result_shape.append(size)
    return result_shape

    Given symbolic shape, replace symbols with source tensor shape variables

    Example:
        Given
            shape = [is0, is1]
            source_tensors = [x, y]
        where
            x.shape = [is0, 1]
            y.shape = [1, is1]
        we will return
            result_shape = [
                mb.slice_by_index(x=mb.shape(x=x), begin=[0], squeeze_mask=[True]),
                mb.slice_by_index(x=mb.shape(x=y), begin=[1], squeeze_mask=[True]),
            ]
    
coremltools/converters/mil/frontend/_utils.py