def join(*parts, **kwargs):
    """
    This functions tries to solve some issues when joining multiple absolute
    paths on both *nix and windows platforms.

    See tests/unit/utils/path_join_test.py for some examples on what's being
    talked about here.

    The "use_posixpath" kwarg can be be used to force joining using poxixpath,
    which is useful for Salt fileserver paths on Windows masters.
    """
    parts = [salt.utils.stringutils.to_str(part) for part in parts]

    kwargs = salt.utils.args.clean_kwargs(**kwargs)
    use_posixpath = kwargs.pop("use_posixpath", False)
    if kwargs:
        salt.utils.args.invalid_kwargs(kwargs)

    pathlib = posixpath if use_posixpath else os.path

    # Normalize path converting any os.sep as needed
    parts = [pathlib.normpath(p) for p in parts]

    try:
        root = parts.pop(0)
    except IndexError:
        # No args passed to func
        return ""

    root = salt.utils.stringutils.to_unicode(root)
    if not parts:
        ret = root
    else:
        stripped = [p.lstrip(os.sep) for p in parts]
        ret = pathlib.join(root, *salt.utils.data.decode(stripped))
    return pathlib.normpath(ret)

join(parts=('/home/XXX/.gdrive-downloader', 'true'), kwargs={})

<module 'posixpath' from '/local/rcs/XXX/miniforge3/envs/saltstack+salt/lib/python3.9/posixpath.py'>


idx_pad0_fill = _get_idx(ndim, dim, slice(None, pw[0], None))


def do_replace(fname, content, before_text, after_text, fence=None):
    before_text = strip_quoted_wrapping(before_text, fname, fence)
    after_text = strip_quoted_wrapping(after_text, fname, fence)
    fname = Path(fname)

    # does it want to make a new file?
    if not fname.exists() and not before_text.strip():
        fname.touch()
        content = ""

    if content is None:
        return

    if not before_text.strip():
        # append to existing file, or start a new file
        new_content = content + after_text
    else:
        new_content = replace_most_similar_chunk(content, before_text, after_text)

    return new_content

do_replace(fname='/tmp/tmp7g7a2csg/file.txt', content='two\n', before_text='two\n', after_text='three\n', fence=('```', '```'))

'two\n'

'two\n'

'two\n'


def bounded_product(sequence, n=None, seed=None):
    """
    Returns a shuffled, bounded cartesian product of the input sequence.
    Designed to cover as wide a range of permutations as possible with a limited number of iterations.
    Will manifest the whole list in memory, so not suitable for super large sequences.

    :param sequence: iterable
    :param n: length of returned list
    :param seed: random seed for reproducibility
    :return: list
    """
    p = list(itertools.product(*sequence))
    if seed is not None:
        random.seed(seed)
    random.shuffle(p)
    return p if n is None else p[:n]

bounded_product(sequence=([[0, 1, 1], [1, 2, 2], [0, 2, 2]], [True, False], [[[['global'], 'all']], [[['local'], 'all']], [[['sparse_variable'], 'all']], [[['sparse_fixed'], 'all']]], [[True, False], [False, True]], [[{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]]), n=50, seed=None)

[([0, 1, 1], True, [[['global'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['global'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['global'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['global'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['local'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['local'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['local'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['local'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], False, [[['global'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], False, [[['global'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], False, [[['global'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], False, [[['global'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], False, [[['local'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], False, [[['local'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], False, [[['local'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis... True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], True, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], True, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], True, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], True, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], True, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], True, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['global'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['global'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['global'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['global'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['local'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['local'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['local'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['local'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False])]

[([0, 1, 1], False, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], False, [[['local'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([1, 2, 2], True, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([1, 2, 2], True, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([1, 2, 2], True, [[['local'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], True, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], True, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], True, [[['local'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([1, 2, 2], True, [[['global'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([1, 2, 2], False, [[['global'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['global'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], True, [[['global'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['global'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], False, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], False, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([1, 2, 2], False, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([1, 2, 2], True, [[['local'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['local'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([1, 2, 2], False, [[['local'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, '...abled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([1, 2, 2], False, [[['local'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['local'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([1, 2, 2], True, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([1, 2, 2], True, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['local'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([1, 2, 2], False, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([1, 2, 2], True, [[['local'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([1, 2, 2], True, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['global'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], True, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], True, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['global'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], False, [[['global'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([1, 2, 2], False, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['sparse_variable'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['sparse_fixed'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 2, 2], False, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True]), ([0, 1, 1], True, [[['sparse_variable'], 'all']], [True, False], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 1, 1], True, [[['sparse_fixed'], 'all']], [False, True], [{'enabled': True, 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, False]), ([0, 2, 2], False, [[['local'], 'all']], [True, False], [{'enabled': True, 'type': 'bfloat16', 'loss_scale': 0, 'loss_scale_window': 1000, 'hysteresis': 2, 'min_loss_scale': 1}, True])]


def _get_definition_names(parso_cache_node, used_names, name_key):
    if parso_cache_node is None:
        names = used_names.get(name_key, ())
        return tuple(name for name in names if name.is_definition(include_setitem=True))

    try:
        for_module = _definition_name_cache[parso_cache_node]
    except KeyError:
        for_module = _definition_name_cache[parso_cache_node] = {}

    try:
        return for_module[name_key]
    except KeyError:
        names = used_names.get(name_key, ())
        result = for_module[name_key] = tuple(
            name for name in names if name.is_definition(include_setitem=True)
        )
        return result

_get_definition_names(parso_cache_node={node=<Module: @1-3>, lines=['def f(a, b=1):\n', '    "Document for function f."\n', ''], change_time=1712197932.5185623, last_used=1712197932.5185623}, used_names={_dict={'f': [<Name: f@1,4>], 'a': [<Name: a@1,6>], 'b': [<Name: b@1,9>]}}, name_key='f')


def quat_from_axis_angle(axis, angle):
        axis_ = np.array(axis, dtype=np.float64)
        half_angle = angle * 0.5
        ret = np.empty(4)
        ret[0] = math.cos(half_angle)
        ret[1:4] = math.sin(half_angle) * axis_
        return ret

quat_from_axis_angle(axis=[1.0, 0.0, 0.0], angle=6.1086523819801535)


def transform(self, name: str) -> str:
        """
        Transform ``name`` with the configured auto-dashes behavior.

        If the collection's ``auto_dash_names`` attribute is ``True``
        (default), all non leading/trailing underscores are turned into dashes.
        (Leading/trailing underscores tend to get stripped elsewhere in the
        stack.)

        If it is ``False``, the inverse is applied - all dashes are turned into
        underscores.

        .. versionadded:: 1.0
        """
        # Short-circuit on anything non-applicable, e.g. empty strings, bools,
        # None, etc.
        if not name:
            return name
        from_, to = "_", "-"
        if not self.auto_dash_names:
            from_, to = "-", "_"
        replaced = []
        end = len(name) - 1
        for i, char in enumerate(name):
            # Don't replace leading or trailing underscores (+ taking dotted
            # names into account)
            # TODO: not 100% convinced of this / it may be exposing a
            # discrepancy between this level & higher levels which tend to
            # strip out leading/trailing underscores entirely.
            if (
                i not in (0, end)
                and char == from_
                and name[i - 1] != "."
                and name[i + 1] != "."
            ):
                char = to
            replaced.append(char)
        return "".join(replaced)

transform(self=<Collection None: >, name='make_sudouser', self._configuration={}, self.auto_dash_names=True, self.collections={}, self.default=None, self.loaded_from=None, self.name=None, self.tasks={})


def secrets_dir(env=os.getenv('D2_ENVIRONMENT', None),
                basedir=os.getenv('D2_SECRETS_BASEDIR', None)):
    if env is not None:
        env_str = str(env)
    else:
        cwd = os.getcwd()
        default_file = os.path.join(cwd, '.python_secrets_environment')
        if os.path.exists(default_file):
            with open(default_file, 'r') as f:
                env_str = f.read().strip()
        else:
            env_str = os.path.basename(cwd)
    if basedir is None:
        basedir = os.path.join(
                HOME,
                'secrets' if sys.platform.startswith('win') else '.secrets')
    return os.path.join(basedir, env_str)

secrets_dir(env=None, basedir=None)


def _make_rect_tag(column, length, height, cell_width, cell_height, background_color):
    attributes = {
        'x': str(column * cell_width),
        'y': str(height),
        'width': str(length * cell_width),
        'height': str(cell_height)
    }

    if background_color.startswith('#'):
        attributes['fill'] = background_color
    else:
        attributes['class'] = background_color
    rect_tag = etree.Element('rect', attributes)
    return rect_tag

_make_rect_tag(column=0, length=2, height=0, cell_width=8, cell_height=1, background_color='red')


def _readREFullObj(fp, array, dtype):

        nbyte = HarFileIO._getEntrySize(fp)
        dataForm = '=4sii'

        V = HarFileIO._unpack_data(fp, dataForm)

        if fb(V[0]) != '    ':
            raise Exception("Encountered characters at read7D[1]")

        nrec = V[1]
        NDim = V[2]
        dataForm = "=" + ('i' * NDim)

        V = HarFileIO._unpack_data(fp, dataForm)

        if nbyte != HarFileIO._getEntrySize(fp):
            raise RuntimeError("Header corrupted read7D[0] @ %d" % fp.tell())

        oldshape = array.shape
        array = array.flatten('F')
        idata = 0
        while nrec > 1:
            nbyte = HarFileIO._getEntrySize(fp)
            dataForm = '4s15i'
            V = HarFileIO._unpack_data(fp, dataForm)

            if fb(V[0]) != '    ':
                raise RuntimeError("Encountered characters at first four positions at)SetEl")

            if nbyte != HarFileIO._getEntrySize(fp):
                raise RuntimeError('read7D data[2] corrupted')

            nbyte = HarFileIO._getEntrySize(fp)
            ndata = (nbyte - 8) // struct.calcsize(dtype)
            dataForm = '4si' + str(ndata) + dtype
            V = HarFileIO._unpack_data(fp, dataForm)

            if nbyte != HarFileIO._getEntrySize(fp):
                raise RuntimeError('read7D data[2])corrupted')

            if fb(V[0]) != '    ':
                raise RuntimeError("Encountered characters at read7D[2]")

            nrec = V[1]
            array[idata:idata + ndata] = V[2:]
            idata += ndata
        array = array.reshape(oldshape, order='F')
        return array

_readREFullObj(fp=<_io.BufferedReader name='/local/rcs/XXX/code/pytrace-collector/logs/pypibugs/tried/GEMPACKsoftware+HARPY/GEMPACKsoftware+HARPY/test_remove_header_array.har'>, array=array([[0., 0.],       [0., 0.]], dtype=float32), dtype='f')


def generate_samples_loguniform(low, high, step, base, size=1):
    """Generate sample for (discrete)uniform density."""

    samples = base ** (random.uniform(low=logb(low, base), high=logb(high, base), size=size))
    if step:
        samples = step * np.floor(samples / step)
    return samples

generate_samples_loguniform(low=5.8884365535558836e-08, high=2.6977394324449206e-07, step=None, base=10, size=100000)


def format_uptime(uptime_in_seconds):
    """Format number of seconds into human-readable string.

    :param uptime_in_seconds: The server uptime in seconds.
    :returns: A human-readable string representing the uptime.

    >>> uptime = format_uptime('56892')
    >>> print(uptime)
    15 hours 48 min 12 sec
    """

    m, s = divmod(int(uptime_in_seconds), 60)
    h, m = divmod(m, 60)
    d, h = divmod(h, 24)

    uptime_values = []

    for value, unit in ((d, 'days'), (h, 'hours'), (m, 'min'), (s, 'sec')):
        if value == 0 and not uptime_values:
            # Don't include a value/unit if the unit isn't applicable to
            # the uptime. E.g. don't do 0 days 0 hours 1 min 30 sec.
            continue
        elif value == 1 and unit.endswith('s'):
            # Remove the "s" if the unit is singular.
            unit = unit[:-1]
        uptime_values.append('{0} {1}'.format(value, unit))

    uptime = ' '.join(uptime_values)
    return uptime

format_uptime(uptime_in_seconds=59)


def is_eq(value, rep=None):
    if rep is None:
        rep = repr(value)

    def is_valid(data, explain=False):
        if not explain:
            return data == value
        return (
            True, 'data is equal to {}'.format(rep)
        ) if data == value else (
            False, 'data is not equal to {}'.format(rep)
        )
    return is_valid

is_eq(value=0, rep=None)

<function is_eq.<locals>.is_valid at 0x7fde77983310>


def _create_key_val_str(input_dict: Union[Mapping[Any, Any], Any]) -> str:
    """
    Returns string of format {'key': val, 'key2': val2}
    Function is called recursively for nested dictionaries

    :param input_dict: dictionary to transform
    :return: (str) reformatted string
    """

    def list_to_str(input_list: List[str]) -> str:
        """
        Convert all list items to string.
        Function is called recursively for nested lists
        """
        converted_list = []
        for item in sorted(input_list, key=lambda x: str(x)):
            if isinstance(item, dict):
                item = _create_key_val_str(item)
            elif isinstance(item, list):
                item = list_to_str(item)

            converted_list.append(str(item))
        list_str = ", ".join(converted_list)
        return "[" + list_str + "]"

    items_list = []
    for key in sorted(input_dict.keys(), key=lambda x: str(x)):
        val = input_dict[key]
        if isinstance(val, dict):
            val = _create_key_val_str(val)
        elif isinstance(val, list):
            val = list_to_str(input_list=val)

        items_list.append(f"{key}: {val}")

    key_val_str = "{{{}}}".format(", ".join(items_list))
    return key_val_str

_create_key_val_str(input_dict={})

<function _create_key_val_str.<locals>.list_to_str at 0x7f684994adc0>


def base64url_decode(input: Union[bytes, str]) -> bytes:
    input_bytes = force_bytes(input)

    rem = len(input_bytes) % 4

    if rem > 0:
        input_bytes += b"=" * (4 - rem)

    return base64.urlsafe_b64decode(input_bytes)

base64url_decode(input='hJtXIZ2uSN5kbQfbtTNWbpdmhkV8FJG-Onbc6mxCcYg')


def _find_and_replace_patterns(content, patterns_and_insertions):
  r"""content: str

  patterns_and_insertions: List[Dict]

  Example for patterns_and_insertions:

      [
          {
              "pattern" :
              r"(?:\\figcompfigures{\s*)(?P<first>.*?)\s*}\s*{\s*(?P<second>.*?)\s*}\s*{\s*(?P<third>.*?)\s*}",
              "insertion" :
              r"\parbox[c]{{{second}\linewidth}}{{\includegraphics[width={third}\linewidth]{{figures/{first}}}}}}",
              "description": "Replace figcompfigures"
          },
      ]
  """
  for pattern_and_insertion in patterns_and_insertions:
    pattern = pattern_and_insertion['pattern']
    insertion = pattern_and_insertion['insertion']
    description = pattern_and_insertion['description']
    logging.info('Processing pattern: %s.', description)
    p = regex.compile(pattern)
    m = p.search(content)
    while m is not None:
      local_insertion = insertion.format(**m.groupdict())
      if pattern_and_insertion.get('strip_whitespace', True):
        local_insertion = strip_whitespace(local_insertion)
      logging.info(f'Found {content[m.start():m.end()]:<70}')
      logging.info(f'Replacing with {local_insertion:<30}')
      content = content[: m.start()] + local_insertion + content[m.end() :]
      m = p.search(content)
    logging.info('Finished pattern: %s.', description)
  return content

_find_and_replace_patterns(content='& \\figcompfigures{\n\timage1.jpg\n}{\n\t\\ww\n}{\n\t1.0\n\t}\n& \\figcompfigures{image2.jpg}{\\ww}{1.0}', patterns_and_insertions=[{'pattern': '(?:\\\\figcompfigures{\\s*)(?P<first>.*?)\\s*}\\s*{\\s*(?P<second>.*?)\\s*}\\s*{\\s*(?P<third>.*?)\\s*}', 'insertion': '\\parbox[c]{{\n            {second}\\linewidth\n        }}{{\n            \\includegraphics[\n                width={third}\\linewidth\n            ]{{\n                figures/{first}\n            }}\n        }} ', 'description': 'Replace figcompfigures'}])

'& \\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image1.jpg}}\n& \\figcompfigures{image2.jpg}{\\ww}{1.0}'

'& \\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image1.jpg}}\n& \\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image2.jpg}}'

'Replace figcompfigures'

<regex.Match object; span=(2, 49), match='\\figcompfigures{\n\timage1.jpg\n}{\n\t\\ww\n}{\n\t1.0\n\t}'>

<regex.Match object; span=(89, 126), match='\\figcompfigures{image2.jpg}{\\ww}{1.0}'>

'\\parbox[c]{\n            \\ww\\linewidth\n        }{\n            \\includegraphics[\n                width=1.0\\linewidth\n            ]{\n                figures/image1.jpg\n            }\n        } '

'\\parbox[c]{\n            \\ww\\linewidth\n        }{\n            \\includegraphics[\n                width=1.0\\linewidth\n            ]{\n                figures/image2.jpg\n            }\n        } '


def get_google_drive_folder_location():
    """
    Try to locate the Google Drive folder.

    Returns:
        (str) Full path to the current Google Drive folder
    """
    gdrive_db_path = "Library/Application Support/Google/Drive/sync_config.db"
    yosemite_gdrive_db_path = (
        "Library/Application Support/Google/Drive/" "user_default/sync_config.db"
    )
    yosemite_gdrive_db = os.path.join(os.environ["HOME"], yosemite_gdrive_db_path)
    if os.path.isfile(yosemite_gdrive_db):
        gdrive_db_path = yosemite_gdrive_db

    googledrive_home = None

    gdrive_db = os.path.join(os.environ["HOME"], gdrive_db_path)
    if os.path.isfile(gdrive_db):
        con = sqlite3.connect(gdrive_db)
        if con:
            cur = con.cursor()
            query = (
                "SELECT data_value "
                "FROM data "
                "WHERE entry_key = 'local_sync_root_path';"
            )
            cur.execute(query)
            data = cur.fetchone()
            googledrive_home = str(data[0])
            con.close()

    if not googledrive_home:
        error(
            constants.ERROR_UNABLE_TO_FIND_STORAGE.format(
                provider="Google Drive install"
            )
        )

    return googledrive_home

get_google_drive_folder_location()

Question: "SELECT data_value FROM data WHERE entry_key = 'local_sync_root_path';"


def find_csv_columns(csv, column_separator):
    lines = csv.strip().split('\n')
    numeric_lines = [line for line in lines if column_separator in line and numeric_start.search(line)]
    n_columns = list(set([len(line.split(column_separator)) for line in numeric_lines]))
    if len(n_columns) != 1:
        raise CsvParseError('Numeric lines have different number of columns')
    n_columns = n_columns[0]
    for line in lines:
        if not numeric_start.search(line) and len(line.split(column_separator)) == n_columns:
            return [cell.strip() for cell in line.split(column_separator)]

find_csv_columns(csv='20.000\t68.334\t0\n20.250\t68.335\t0\n19998.498\t27.402\t0', column_separator='\t')


def det_hess(u):
    """
    Get the determinant of the Hessian matrix of `u`.

    Parameters
    ----------
    * `u` : numpy.ndarray
        The ndarray input with shape (n0+2, n1+2, ..., nd1+2).

    Returns
    -------
    * numpy.ndarray
        The ndarray of the second grad of `u` with shape (n0, n1, ..., nd1).
    """
    ndim = np.ndim(u)
    inshape = np.asarray(u.shape)
    outshape = list(inshape - 2)

    # obtain the second gradient per each pairs of axes
    hess_unarranged = np.zeros([ndim, ndim] + outshape)
    for i in range(ndim):
        for j in range(i,ndim):
            grad2_val = grad2(u, (i,j))
            hess_unarranged[i,j] = grad2_val
            hess_unarranged[j,i] = grad2_val

    # rearrange hessian to have shape: outshape + [ndim, ndim]
    perm_idx = list(range(2,ndim+2)) + list(range(2))
    hess = np.transpose(hess_unarranged, perm_idx)

    # calculate and return the determinant
    return np.linalg.det(hess)

det_hess(u=array([  0.,   1.,   4.,   9.,  16.,  25.,  36.,  49.,  64.,  81., 100.,       121., 144., 169., 196., 225., 256., 289., 324., 361., 400., 441.,       484., 529., 576., 625., 676., 729., 784., 841., 900., 961.]))


def _readSetElementInfoRecord(fp):

        SetNames = []
        ElementList = []
        SetStatus = []

        nbyte = HarFileIO._getEntrySize(fp)

        # read the data, has to be in chunks as it is dependent on interanl size specifications
        dataForm = '=' + '4siii12si'

        V = HarFileIO._unpack_data(fp, dataForm)

        if fb(V[0]) != '    ':
            raise RuntimeError("Encountered characters at first four positions at SetEl")

        NSets = V[3]
        Coefficient = fb(V[4])
        setKnown=V[5]!=0
        if not setKnown:
            dataForm = '=i'
        else:
            dataForm = "=" + str(NSets * 12) + 's' + str(NSets) + 's' + str(NSets) + 'i' + 'i'

        V = HarFileIO._unpack_data(fp, dataForm)
        if setKnown:
            SetNames = [fb(V[0][i:i + 12]) for i in range(0, NSets * 12, 12)]
            SetStatus = [fb(V[1][i:i + 1]) for i in range(0, NSets)]

        Nexplicit = V[-1]
        dataForm = '=' + str(Nexplicit * 12) + 's'
        V = HarFileIO._unpack_data(fp, dataForm)

        if Nexplicit > 0:
            dataForm = '=' + str(Nexplicit * 12) + 's'
            V = HarFileIO._unpack_data(fp, dataForm)

            ElementList = [fb(V[-1][i:i + 12]) for i in range(0, NSets * 12, 12)]

        HarFileIO._checkRead(fp, nbyte)

        return Coefficient, SetNames, SetStatus, ElementList

_readSetElementInfoRecord(fp=<_io.BufferedReader name='/local/rcs/XXX/code/pytrace-collector/logs/pypibugs/tried/GEMPACKsoftware+HARPY/GEMPACKsoftware+HARPY/test_remove_header_array.har'>)

(b'SimpleSet   SimpleSet2  ', b'kk', 0, 0, 0)


def show_ios_class_methods(args: list) -> None:
    """
        Displays the methods available in a class.

        :param args:
        :return:
    """

    if len(clean_argument_flags(args)) <= 0:
        click.secho('Usage: ios hooking list class_methods <class name> (--include-parents)', bold=True)
        return

    classname = args[0]

    api = state_connection.get_api()
    methods = api.ios_hooking_get_class_methods(classname, _should_include_parent_methods(args))

    if len(methods) > 0:

        # dump the methods to screen
        for method in methods:
            click.secho(method)

        click.secho('\nFound {0} methods'.format(len(methods)), bold=True)

    else:
        click.secho('No class / methods found')

show_ios_class_methods(args=['TEKeychainManager'])


def strip_whitespace(text):
  """Strips all whitespace characters.

  https://stackoverflow.com/questions/8270092/remove-all-whitespace-in-a-string
  """
  pattern = regex.compile(r'\s+')
  text = regex.sub(pattern, '', text)
  return text

strip_whitespace(text='\\parbox[c]{\n            \\ww\\linewidth\n        }{\n            \\includegraphics[\n                width=1.0\\linewidth\n            ]{\n                figures/image1.jpg\n            }\n        } ')

'\\parbox[c]{\\ww\\linewidth}{\\includegraphics[width=1.0\\linewidth]{figures/image1.jpg}}'


def convert_lit_checkpoint(checkpoint_path: Path, output_path: Path, config_path: Path) -> None:
    config = Config.from_json(config_path)

    if "falcon" in config.name:
        copy_fn = partial(copy_weights_falcon, config.name)
    elif config._mlp_class in ("LLaMAMLP", "LLaMAMoE"):
        copy_fn = partial(copy_weights_llama, config)
    elif "phi" in config.name:
        copy_fn = partial(copy_weights_phi, config)
    else:
        copy_fn = copy_weights_gpt_neox

    # initialize a new empty state dict to hold our new weights
    sd = {}
    with incremental_save(output_path) as saver:
        lit_weights = lazy_load(checkpoint_path)
        lit_weights = lit_weights.get("model", lit_weights)
        check_conversion_supported(lit_weights)
        copy_fn(sd, lit_weights, saver=saver)
        gc.collect()
        saver.save(sd)

convert_lit_checkpoint(checkpoint_path=PosixPath('/tmp/pytest-of-XXX/pytest-193/test_convert_lit_checkpoint0/foo.ckpt'), output_path=PosixPath('/tmp/pytest-of-XXX/pytest-193/test_convert_lit_checkpoint0/generated.bin'), config_path=PosixPath('/tmp/pytest-of-XXX/pytest-193/test_convert_lit_checkpoint0/foo.json'))

OrderedDict([('lm_head.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32000, 32)))), ('transformer.wte.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32000, 32)))), ('transformer.h.0.norm_1.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32,)))), ('transformer.h.0.attn.attn.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(96, 32)))), ('transformer.h.0.attn.proj.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32, 32)))), ('transformer.h.0.norm_2.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32,)))), ('transformer.h.0.mlp.fc_1.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(11008, 32)))), ('transformer.h.0.mlp.fc_2.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(11008, 32)))), ('transformer.h.0.mlp.proj.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32, 11008)))), ('transformer.h.1.norm_1.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32,)))), ('transformer.h.1.attn.attn.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(96, 32)))), ('transformer.h.1.attn.proj.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32, 32)))), ('transformer.h.1.norm_2.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32,)))), ('transformer.h.1.mlp.fc_1.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(11008, 32)))), ('transformer.h.1.mlp.fc_2.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(11008, 32)))), ('transformer.h.1.mlp.proj.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32, 11008)))), ('transformer.ln_f.weight', _NotYetLoadedTensor(tensor(..., device='meta', size=(32,))))])

functools.partial(<function copy_weights_llama at 0x7f7fca5d34c0>, Config(name='Llama-2-7b-hf', hf_config={'org': 'meta-llama', 'name': 'Llama-2-7b-hf'}, block_size=8, vocab_size=32000, padding_multiple=128, padded_vocab_size=32000, n_layer=2, n_head=2, n_embd=32, rotary_percentage=1.0, parallel_residual=False, bias=False, lm_head_bias=False, n_query_groups=2, shared_attention_norm=False, _norm_class='RMSNorm', norm_eps=1e-05, _mlp_class='LLaMAMLP', gelu_approximate='none', intermediate_size=11008, rope_condense_ratio=1, rope_base=10000, n_expert=0, n_expert_per_token=0))

{'lm_head.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f806c094b80>, 'model.embed_tokens.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca4b0f70>, 'model.layers.0.input_layernorm.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca4b0130>, 'model.layers.0.self_attn.q_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca4b0a30>, 'model.layers.0.self_attn.k_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca4b07f0>, 'model.layers.0.self_attn.v_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca401550>, 'model.layers.0.self_attn.o_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca401160>, 'model.layers.0.post_attention_layernorm.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca26a460>, 'model.layers.0.mlp.gate_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca502e80>, 'model.layers.0.mlp.up_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca502ee0>, 'model.layers.0.mlp.down_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca502760>, 'model.layers.1.input_layernorm.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca4dc460>, 'model.layers.1.self_attn.q_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca57ff10>, 'model.layers.1.self_attn.k_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca57f340>, 'model.layers.1.self_attn.v_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f801db95b80>, 'model.layers.1.self_attn.o_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f801db95fa0>, 'model.layers.1.post_attention_layernorm.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca26a9a0>, 'model.layers.1.mlp.gate_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f8024328460>, 'model.layers.1.mlp.up_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f80243287c0>, 'model.layers.1.mlp.down_proj.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f7fca459e50>, 'model.norm.weight': <lit_gpt.utils.SavingProxyForTensor object at 0x7f8024180bb0>}

{name=PosixPath('/tmp/pytest-of-XXX/pytest-193/test_convert_lit_checkpoint0/generated.bin'), zipfile=<torch.PyTorchFileWriter object at 0x7f8109872270>, has_saved=False, next_key=0}

{name=PosixPath('/tmp/pytest-of-XXX/pytest-193/test_convert_lit_checkpoint0/generated.bin'), zipfile=<torch.PyTorchFileWriter object at 0x7f8109872270>, has_saved=False, next_key=21}

{name=PosixPath('/tmp/pytest-of-XXX/pytest-193/test_convert_lit_checkpoint0/generated.bin'), zipfile=<torch.PyTorchFileWriter object at 0x7f8109872270>, has_saved=True, next_key=21}


<regex.Match object; span=(2, 49), match='\\figcompfigures{\n\timage1.jpg\n}{\n\t\\ww\n}{\n\t1.0\n\t}'>

'Replace figcompfigures'


def _insert(self, key, value):
        flat_key = self._serialize_key(key)
        i = self._index.get(flat_key, -1)
        if i >= 0:
            self._items[i] = (key, value)
        else:
            self._items.append((key, value))
            self._index[flat_key] = len(self._items) - 1

_insert(self=OrderedMapSerializedKey([]), key='みbob', value=199)


def encode_request(*args):
    """Pack a series of arguments into a RESP array of bulk strings."""
    result = ["*" + str(len(args)) + CRLF]

    for arg in args:
        if arg is None:
            result.append('$-1' + CRLF)
        else:
            s = str(arg)
            result.append('$' + str(len(s)) + CRLF + s + CRLF)

    return "".join(result)

encode_request(args=('ping',))