Repository: LMCache/LMCache
File: lmcache/integration/sglang/sglang_adapter.py (Python)

Code before:
                f"LMCache retrieve skipped: lookup={retrieve_token_num}, "
                f"offset={offset}, no new tokens to load"
            )
            return 0

        layerwise_retriever = self.lmcache_engine.retrieve_layer(
            token_ids[:retrieve_token_num],
            mask=load_mask[:retrieve_token_num],
            kvcaches=self.kvcaches,
            slot_mapping=slot_mapping[:retrieve_token_num],
            sync=False,
        )

        next(layerwise_retriever)
        # Load First Layer
        next(layerwise_retriever)

        self.layerwise_retrievers.append(layerwise_retriever)
        self.layer_load_layer.append(1)

        self.lookup_id_list.append(lookup_id)

        num_new_tokens = retrieve_token_num - offset
        logger.info(
            f"LMCache retrieve started: lookup={retrieve_token_num}, "
            f"offset={offset}, new_tokens={num_new_tokens}"
        )

        return num_new_tokens

    def store_kv(self, store_metadata: StoreMetadata) -> None:
        slot_mapping = store_metadata.kv_indices.to(torch.int64).cuda()
        token_ids = torch.tensor(store_metadata.token_ids, dtype=torch.int64).cuda()
        store_mask = torch.ones_like(token_ids, dtype=torch.bool)

        lookup_id = str(uuid.uuid4())
        self.lmcache_engine.lookup(token_ids, lookup_id=lookup_id, pin=True)

        layerwise_storer = self.lmcache_engine.store_layer(
            token_ids,
            mask=store_mask,
            kvcaches=self.kvcaches,
            slot_mapping=slot_mapping,
            offset=store_metadata.offset,
            sync=False,
        )
        next(layerwise_storer)
        for _ in range(self.sgl_config.num_hidden_layers):
            next(layerwise_storer)

        self.lmcache_engine.lookup_unpin(lookup_id)

Review comment (suggestion):
```suggestion
            f"offset={offset}, retrieve {num_new_tokens} new tokens"
```

Code after:
                f"LMCache retrieve skipped: lookup={retrieve_token_num}, "
                f"offset={offset}, no new tokens to retrieve"
            )
            return 0

        layerwise_retriever = self.lmcache_engine.retrieve_layer(
            token_ids[:retrieve_token_num],
            mask=load_mask[:retrieve_token_num],
            kvcaches=self.kvcaches,
            slot_mapping=slot_mapping[:retrieve_token_num],
            sync=False,
        )

        next(layerwise_retriever)
        # Load First Layer
        next(layerwise_retriever)

        self.layerwise_retrievers.append(layerwise_retriever)
        self.layer_load_layer.append(1)

        self.lookup_id_list.append(lookup_id)

        num_new_tokens = retrieve_token_num - offset
        logger.info(
            f"LMCache retrieve started: lookup={retrieve_token_num}, "
            f"offset={offset}, retrieve {num_new_tokens} new tokens"
        )

        return num_new_tokens

    def store_kv(self, store_metadata: StoreMetadata) -> None:
        slot_mapping = store_metadata.kv_indices.to(torch.int64).cuda()
        token_ids = torch.tensor(store_metadata.token_ids, dtype=torch.int64).cuda()
        store_mask = torch.ones_like(token_ids, dtype=torch.bool)

        lookup_id = str(uuid.uuid4())
        self.lmcache_engine.lookup(token_ids, lookup_id=lookup_id, pin=True)

        layerwise_storer = self.lmcache_engine.store_layer(
            token_ids,
            mask=store_mask,
            kvcaches=self.kvcaches,
            slot_mapping=slot_mapping,
            offset=store_metadata.offset,
            sync=False,
        )
        next(layerwise_storer)
        for _ in range(self.sgl_config.num_hidden_layers):
            next(layerwise_storer)

        self.lmcache_engine.lookup_unpin(lookup_id)