sgl-project--sglang
94057c3d3e
PR Test (NPU) / check-changes (push) Has been cancelled
PR Test (NPU) / pr-gate (push) Has been cancelled
PR Test (NPU) / set-image-config (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-1-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (0) (push) Has been cancelled
PR Test (NPU) / stage-b-test-2-npu-a2 (1) (push) Has been cancelled
PR Test (NPU) / stage-b-test-4-npu-a3 (push) Has been cancelled
PR Test (NPU) / stage-b-test-16-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-1-npu-a3 (push) Has been cancelled
PR Test (NPU) / multimodal-gen-test-2-npu-a3 (push) Has been cancelled
PR Test (Arm64) / pr-gate (push) Has been cancelled
PR Test (Arm64) / check-changes (push) Has been cancelled
PR Test (Arm64) / build-test (push) Has been cancelled
PR Test (sgl-router) / gate (push) Has been cancelled
PR Test (sgl-router) / tier-1 — lint (push) Has been cancelled
PR Test (sgl-router) / tier-2 — build + test (push) Has been cancelled
PR Test (sgl-router) / tier-3 — docker (placeholder) (push) Has been cancelled
PR Test (sgl-router) / tier-3 — k8s integration (push) Has been cancelled
PR Test (sgl-router) / tier-3 — e2e (push) Has been cancelled
PR Test (sgl-router) / finish (push) Has been cancelled
PR Test (NPU) / single-node-poc (map[name:qwen3_6_27b_w8a8_1p_in64k_out1k_50ms runner:linux-aarch64-a3-2 test_case:test/registered/ascend/performance/qwen3_6_27b/test_npu_qwen3_6_27b_w8a8_1p_in64k_out1k_50ms.py test_type:perf]) (push) Has been cancelled
PR Test (NPU) / pr-test-npu-finish (push) Has been cancelled
PR Test (Xeon) / pr-gate (push) Has been cancelled
PR Test (Xeon) / check-changes (push) Has been cancelled
PR Test (Xeon) / build-test (, xeon-gnr, base-b-test-cpu) (push) Has been cancelled
PR Test (XPU) / check-changes (push) Has been cancelled
PR Test (XPU) / pr-gate (push) Has been cancelled
PR Test (XPU) / stage-a-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / wait-for-stage-a (push) Has been cancelled
PR Test (XPU) / stage-b-test-1-gpu-xpu (push) Has been cancelled
PR Test (XPU) / finish (push) Has been cancelled
CI Model Inventory / build-inventory (push) Has been cancelled
Lint / lint (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Compilation Check (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Manual Policy (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark - Request Processing (push) Has been cancelled
PR Benchmark (SMG Components) / Benchmark Summary (push) Has been cancelled
PR Test (SMG) / build-wheel (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on windows (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (x86_64 - auto) (push) Has been cancelled
PR Test (SMG) / python-unit-tests (push) Has been cancelled
PR Test (SMG) / unit-tests (push) Has been cancelled
PR Test (SMG) / benchmarks (push) Has been cancelled
PR Test (SMG) / chat-completions (push) Has been cancelled
PR Test (SMG) / chat-completions-4gpu (push) Has been cancelled
PR Test (SMG) / e2e (push) Has been cancelled
PR Test (SMG) / docker-build-test (push) Has been cancelled
PR Test (SMG) / k8s-integration (push) Has been cancelled
PR Test (SMG) / finish (push) Has been cancelled
PR Test (SMG) / summarize-benchmarks (push) Has been cancelled
Release SGLang Model Gateway Docker Image / publish (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on macos (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - auto) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (aarch64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / build on linux (x86_64 - musllinux_1_1) (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Build SDist (push) Has been cancelled
Release SGLang Model Gateway to PyPI / Upload to PyPI (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (aarch64, 12.9, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu129-matrix (x86_64, 12.9, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu129 (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (aarch64, 13.0, 3.10, arm-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / build-cu130-matrix (x86_64, 13.0, 3.10, x64-kernel-build-node) (push) Has been cancelled
Release SGLang Kernels / release-cu130 (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 700) (push) Has been cancelled
Release SGLang Kernels / build-rocm-matrix (3.10, 720) (push) Has been cancelled
Release SGLang Kernels / release-rocm700 (push) Has been cancelled
Release SGLang Kernels / release-rocm720 (push) Has been cancelled
Release SGLang Kernels / build-musa43 (43, 3.10) (push) Has been cancelled
Release SGLang Kernels / release-musa43 (push) Has been cancelled
149 行
5.8 KiB
Python
149 行
5.8 KiB
Python
# Copyright 2023-2024 SGLang Team
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
# ==============================================================================
|
|
|
|
import contextlib
|
|
import multiprocessing as mp
|
|
import unittest
|
|
from typing import Dict, List, Tuple
|
|
|
|
import torch
|
|
|
|
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
|
|
from sglang.test.runners import SRTRunner
|
|
from sglang.test.test_utils import CustomTestCase
|
|
|
|
register_cuda_ci(est_time=263, stage="extra-a", runner_config="1-gpu-small")
|
|
register_amd_ci(est_time=224, suite="stage-b-test-1-gpu-small-amd")
|
|
|
|
PROMPTS = [
|
|
"AI is a field of computer science focused on",
|
|
"""
|
|
### Instruction:
|
|
Compose a SQL query that uses the following table: users, and returns the user_id and name of all users whose name that does not have a duplicate in the table.
|
|
### Response:
|
|
SELECT user_id, name FROM users WHERE name LIKE 'A%';
|
|
""",
|
|
]
|
|
|
|
ADAPTERS = [
|
|
"faridlazuarda/valadapt-llama-3.1-8B-it-chinese", # target_modules = q, v
|
|
"philschmid/code-llama-3-1-8b-text-to-sql-lora", # target_modules = q, k, v, o, gate, up, down
|
|
]
|
|
|
|
BASE_MODEL = "meta-llama/Meta-Llama-3.1-8B-Instruct"
|
|
|
|
|
|
@contextlib.contextmanager
|
|
def dynamically_loaded_adapter(runner, lora_path: str, lora_name: str):
|
|
"""A context manager to load and automatically unload a LoRA adapter."""
|
|
try:
|
|
runner.load_lora_adapter(lora_name=lora_name, lora_path=lora_path)
|
|
yield
|
|
finally:
|
|
runner.unload_lora_adapter(lora_name=lora_name)
|
|
|
|
|
|
class TestLoRAEviction(CustomTestCase):
|
|
def test_lora_eviction_with_different_target_modules(self):
|
|
"""
|
|
Test LoRA eviction with different target modules.
|
|
|
|
This test runs inference against two LoRA adapters in different orders to force eviction behavior, and ensures
|
|
that the outputs of the same (adapter, prompt) pair are consistent across runs.
|
|
"""
|
|
output_history = {}
|
|
self._run_test(ADAPTERS, output_history, reverse=False)
|
|
self._run_test(ADAPTERS, output_history, reverse=True)
|
|
|
|
def test_lora_eviction_with_reused_lora_name(self):
|
|
"""
|
|
Test LoRA eviction with reused LoRA names.
|
|
|
|
This test runs inference against two LoRA adapters with the same name to ensure that the eviction behavior
|
|
works correctly when reusing LoRA names.
|
|
"""
|
|
output_history = {}
|
|
self._run_test(ADAPTERS, output_history, reuse_lora_name=True, repeat=1)
|
|
self._run_test(ADAPTERS, output_history, reuse_lora_name=False, repeat=1)
|
|
|
|
def _run_test(
|
|
self,
|
|
lora_paths: List[str],
|
|
output_history: Dict[Tuple[str, str], str],
|
|
reverse: bool = False,
|
|
repeat: int = 2,
|
|
reuse_lora_name: bool = False,
|
|
):
|
|
REUSED_LORA_NAME = "lora"
|
|
max_new_tokens = 256
|
|
torch_dtype = torch.float16
|
|
base_path = BASE_MODEL
|
|
assert len(lora_paths) >= 2
|
|
|
|
initial_lora_paths = lora_paths if not reuse_lora_name else None
|
|
# Initialize runners
|
|
with SRTRunner(
|
|
base_path,
|
|
torch_dtype=torch_dtype,
|
|
model_type="generation",
|
|
lora_paths=initial_lora_paths,
|
|
max_loras_per_batch=1,
|
|
enable_lora=True,
|
|
max_lora_rank=256,
|
|
lora_target_modules=["all"],
|
|
) as srt_runner:
|
|
adapter_sequence = lora_paths if not reverse else lora_paths[::-1]
|
|
|
|
for i in range(repeat):
|
|
for j, lora_path in enumerate(adapter_sequence):
|
|
print(
|
|
f"\n========== Testing LoRA eviction with adapter '{lora_path}' (#{j + 1}/{len(adapter_sequence)}), reuse_lora_name: {reuse_lora_name}, reversed: {reverse}, repeat: {i + 1}/{repeat} ---"
|
|
)
|
|
|
|
lora_name = REUSED_LORA_NAME if reuse_lora_name else lora_path
|
|
context = (
|
|
dynamically_loaded_adapter(srt_runner, lora_path, lora_name)
|
|
if reuse_lora_name
|
|
else contextlib.nullcontext()
|
|
)
|
|
with context:
|
|
for prompt in PROMPTS:
|
|
print("\nprompt:\n", prompt)
|
|
srt_outputs = srt_runner.forward(
|
|
[prompt],
|
|
max_new_tokens=max_new_tokens,
|
|
lora_paths=[lora_name],
|
|
)
|
|
output = srt_outputs.output_strs[0].strip()
|
|
print("\noutput:\n", output)
|
|
|
|
prev_output = output_history.get((lora_path, prompt))
|
|
if prev_output is not None:
|
|
self.assertEqual(
|
|
prev_output,
|
|
output,
|
|
f"Output mismatch for adapter {lora_path} and prompt '{prompt}' on repeat {j + 1}, previous: '{prev_output}', current: '{output}'.",
|
|
)
|
|
else:
|
|
output_history[(lora_path, prompt)] = output
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
mp.set_start_method("spawn")
|
|
except RuntimeError:
|
|
pass
|
|
|
|
unittest.main(warnings="ignore")
|