keras/src/tree/dmtree_impl.py/sequence_fn
def lists_to_tuples(structure):
    def sequence_fn(instance, args):
        if isinstance(instance, list):
            return tuple(args)
        return dmtree._sequence_like(instance, args)

    return pack_sequence_as(
        structure,
        dmtree.flatten(structure),
        sequence_fn=sequence_fn,
    )