def grouper(gen, batch_size=4):
    """Group together elements of an iterable without padding remainder."""
    while True:
        batch = []
        for i in range(batch_size):
            try:
                batch.append(next(gen))
            except StopIteration:
                if len(batch) > 0:
                    yield batch
                raise StopIteration
        yield batch
