@torch.no_grad()
def merge_compress_memory(self, mem: CompressedMemory, new_mem: List[torch.Tensor]) -> Tuple[(CompressedMemory, List[torch.Tensor])]:
    '\n        Concatenate new memories and compress the oldest memories.\n        '
    if ((self.mem_len == 0) and (self.c_mem_len == 0)):
        return (CompressedMemory([], []), [])
    if (mem is not None):
        (mem, c_mem) = (mem.mem, mem.c_mem)
    else:
        (mem, c_mem) = ([], [])
    if mem:
        mem = [torch.cat((m, x), dim=0) for (m, x) in zip(mem, new_mem)]
    else:
        mem = new_mem
    if (len(mem[0]) > self.mem_len):
        n_c_mem = ((((len(mem[0]) - self.mem_len) + self.compression_rate) - 1) // self.compression_rate)
        n_old = (n_c_mem * self.compression_rate)
        mem_to_compress = []
        uncompressed_mem = []
        for m in mem:
            (cm, m) = torch.split(m, [n_old, (len(m) - n_old)])
            mem_to_compress.append(cm)
            uncompressed_mem.append(m)
        mem = uncompressed_mem
        new_c_mem = []
        for (i, layer) in enumerate(self.model.transformer.layers):
            new_c_mem.append(layer.compress(mem_to_compress[i]))
        if c_mem:
            c_mem = [torch.cat((m, nm), dim=0) for (m, nm) in zip(c_mem, new_c_mem)]
        else:
            c_mem = new_c_mem
        if (len(c_mem[0]) > self.c_mem_len):
            c_mem = [m[(- self.c_mem_len):] for m in c_mem]
    else:
        mem_to_compress = []
    return (CompressedMemory(mem, c_mem), mem_to_compress)
Concatenate new memories and compress the oldest memories.
@torch.no_grad()
def merge_compress_memory(self, mem: CompressedMemory, new_mem: List[torch.Tensor]) -> Tuple[(CompressedMemory, List[torch.Tensor])]:
    '\n        \n        '
    if ((self.mem_len == 0) and (self.c_mem_len == 0)):
        return (CompressedMemory([], []), [])
    if (mem is not None):
        (mem, c_mem) = (mem.mem, mem.c_mem)
    else:
        (mem, c_mem) = ([], [])
    if mem:
        mem = [torch.cat((m, x), dim=0) for (m, x) in zip(mem, new_mem)]
    else:
        mem = new_mem
    if (len(mem[0]) > self.mem_len):
        n_c_mem = ((((len(mem[0]) - self.mem_len) + self.compression_rate) - 1) // self.compression_rate)
        n_old = (n_c_mem * self.compression_rate)
        mem_to_compress = []
        uncompressed_mem = []
        for m in mem:
            (cm, m) = torch.split(m, [n_old, (len(m) - n_old)])
            mem_to_compress.append(cm)
            uncompressed_mem.append(m)
        mem = uncompressed_mem
        new_c_mem = []
        for (i, layer) in enumerate(self.model.transformer.layers):
            new_c_mem.append(layer.compress(mem_to_compress[i]))
        if c_mem:
            c_mem = [torch.cat((m, nm), dim=0) for (m, nm) in zip(c_mem, new_c_mem)]
        else:
            c_mem = new_c_mem
        if (len(c_mem[0]) > self.c_mem_len):
            c_mem = [m[(- self.c_mem_len):] for m in c_mem]
    else:
        mem_to_compress = []
    return (CompressedMemory(mem, c_mem), mem_to_compress)