From 1240ac13b84a58b9d90009c1937d1a552148fbe0 Mon Sep 17 00:00:00 2001 From: Yuhao Yang <47235274+yhyang201@users.noreply.github.com> Date: Mon, 10 Nov 2025 21:30:19 +0800 Subject: [PATCH] vlm: fix tiny multimodal cache bug (#12984) --- python/sglang/srt/managers/mm_utils.py | 2 +- test/srt/models/test_vlm_models.py | 59 -------------------------- 2 files changed, 1 insertion(+), 60 deletions(-) diff --git a/python/sglang/srt/managers/mm_utils.py b/python/sglang/srt/managers/mm_utils.py index e1060e5dd..914c96cda 100644 --- a/python/sglang/srt/managers/mm_utils.py +++ b/python/sglang/srt/managers/mm_utils.py @@ -380,7 +380,7 @@ def _get_chunked_prefill_embedding( # if all items has been prefixed, we do not need to calculate embedding if all([offset_end < prefix_length[i] for _, offset_end in items_offset]): continue - item_hashes = [item.hash for item in embedding_items] + item_hashes = [item.hash for item in embedding_items_per_req] embedding_items_hash = MultiModalStaticCache.combine_hashes(item_hashes) embedding_per_req = embedding_cache.get(item_hashes) if embedding_per_req is None: diff --git a/test/srt/models/test_vlm_models.py b/test/srt/models/test_vlm_models.py index 45fbef1b9..42f1bd1b6 100644 --- a/test/srt/models/test_vlm_models.py +++ b/test/srt/models/test_vlm_models.py @@ -51,21 +51,6 @@ class TestVLMModels(CustomTestCase): os.environ["OPENAI_API_KEY"] = cls.api_key os.environ["OPENAI_API_BASE"] = f"{cls.base_url}/v1" - def _detect_eviction_in_logs(self, log_output): - """Detect if eviction events occurred in the log output.""" - eviction_keywords = ["Cache eviction: evicted"] - - eviction_detected = False - eviction_count = 0 - - for line in log_output.split("\n"): - if any(keyword in line for keyword in eviction_keywords): - eviction_detected = True - eviction_count += 1 - print(f"Eviction detected: {line.strip()}") - - return eviction_detected, eviction_count - def run_mmmu_eval( self, model_version: str, @@ -269,50 +254,6 @@ class TestVLMModels(CustomTestCase): for model in models_to_test: self._run_vlm_mmmu_test(model, "./logs") - def test_vlm_mmmu_benchmark_with_small_cache(self): - """Test VLM models against MMMU benchmark with a small embedding cache to force eviction.""" - models_to_test = MODELS - - if is_in_ci(): - models_to_test = [random.choice(MODELS)] - - for model in models_to_test: - custom_env = {"SGLANG_VLM_CACHE_SIZE_MB": "5"} - - # Run the test with output capture - server_output = self._run_vlm_mmmu_test( - model, - "./logs_small_cache", - test_name=" with small embedding cache (evict test)", - custom_env=custom_env, - log_level="debug", # Enable debug logging for eviction detection - capture_output=True, # Capture server output - ) - - # Print server output for debugging - print("Server output:\n", server_output) - - # Analyze server output for eviction events - eviction_detected, eviction_count = self._detect_eviction_in_logs( - server_output - ) - - # Assert that eviction was detected (since we're using small cache) - self.assertTrue( - eviction_detected, - f"Expected eviction events to be detected with small cache (5MB), but none found. " - f"Cache size may be too large for the workload or eviction logic may not be working. " - f"Total log content length: {len(server_output)} characters", - ) - - print( - f"Eviction detection summary: {eviction_count} eviction events detected" - ) - - # Additional assertion: if eviction was detected, the test passed - if eviction_detected: - print("✅ Eviction logic successfully triggered and detected!") - if __name__ == "__main__": # Define and parse arguments here, before unittest.main