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

Code before:
        token_ids = torch.tensor(load_metadata.token_ids, dtype=torch.int64).cuda()
        slot_mapping = load_metadata.slot_mapping.cuda()
        offset = load_metadata.offset

        assert self.lmcache_engine is not None

        load_mask = torch.ones_like(token_ids, dtype=torch.bool)
        load_mask[:offset] = False

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

        retrieve_token_num = self.global_min_tokens(
            retrieve_token_num, self.tp_group, torch.device(f"cuda:{self.rank}")
        )

        # No new tokens to retrieve from LMCache
        if retrieve_token_num <= offset:
            self.lmcache_engine.lookup_unpin(lookup_id)
            logger.info(
                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}"
        )

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

Code after:
        token_ids = torch.tensor(load_metadata.token_ids, dtype=torch.int64).cuda()
        slot_mapping = load_metadata.slot_mapping.cuda()
        offset = load_metadata.offset

        assert self.lmcache_engine is not None

        load_mask = torch.ones_like(token_ids, dtype=torch.bool)
        load_mask[:offset] = False

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

        retrieve_token_num = self.global_min_tokens(
            retrieve_token_num, self.tp_group, torch.device(f"cuda:{self.rank}")
        )

        # No new tokens to retrieve from LMCache
        if retrieve_token_num <= offset:
            self.lmcache_engine.lookup_unpin(lookup_id)
            logger.info(
                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"
        )