def download_pretrained_from_url(
        url: str,
        cache_dir: Union[str, None] = None,
        cache_file_name: Optional[str] = None,
) -> str:
    '''
    This function takes a clip model checkpoint url as input, downloads the model if it doesn't exist locally,
    and returns the local path of the downloaded file.

    Args:
        url: a valid string of the url address.
        cache_dir: the directory to store the file
        cache_file_name: name of the model file when it gets downloaded to the cache.
            If not provided, the basename of the URL is used.
    Returns:
        download_target: the local path of the downloaded file.
    '''
    buffer_size = 8192
    if not cache_dir:
        cache_dir = os.path.expanduser(ModelCache.clip_cache_path)
    os.makedirs(cache_dir, exist_ok=True)

    if cache_file_name is None:
        filename = os.path.basename(url)
    else:
        filename = cache_file_name

    download_target = os.path.join(cache_dir, filename)

    if os.path.isfile(download_target):
        return download_target

    with urllib.request.urlopen(url) as source, open(download_target, "wb") as output:
        with tqdm(total=int(source.headers.get("Content-Length")), ncols=80, unit='iB', unit_scale=True) as loop:
            while True:
                buffer = source.read(buffer_size)
                if not buffer:
                    break

                output.write(buffer)
                loop.update(len(buffer))

    return download_target

    This function takes a clip model checkpoint url as input, downloads the model if it doesn't exist locally,
    and returns the local path of the downloaded file.

    Args:
        url: a valid string of the url address.
        cache_dir: the directory to store the file
        cache_file_name: name of the model file when it gets downloaded to the cache.
            If not provided, the basename of the URL is used.
    Returns:
        download_target: the local path of the downloaded file.
    
src/marqo/inference/model_download/model_download.py