[feat] Enhance lora_update_weight_from_tensor for RL training (#19314)
This commit is contained in:
@@ -329,6 +329,38 @@ class TestLoRALoadFromTensor(CustomTestCase):
|
||||
|
||||
print("\n[Test]LoRA logprob comparison test passed!")
|
||||
|
||||
def test_lora_e2e_load_from_flattened_bucket(self):
|
||||
"""Test loading LoRA via FlattenedTensorBucket format (RL weight sync path)."""
|
||||
from sglang.srt.utils import MultiprocessingSerializer
|
||||
from sglang.srt.weight_sync.tensor_bucket import FlattenedTensorBucket
|
||||
|
||||
named_tensors = list(self.lora_tensors.items())
|
||||
bucket = FlattenedTensorBucket(named_tensors=[(n, t) for n, t in named_tensors])
|
||||
bucket_dict = {
|
||||
"flattened_tensor": bucket.get_flattened_tensor(),
|
||||
"metadata": bucket.get_metadata(),
|
||||
}
|
||||
serialized = MultiprocessingSerializer.serialize(bucket_dict, output_str=True)
|
||||
|
||||
result = self.engine.load_lora_adapter_from_tensors(
|
||||
lora_name="self_cognition_Alice_flattened",
|
||||
tensors=serialized,
|
||||
config_dict=self.lora_config_dict,
|
||||
load_format="flattened_bucket",
|
||||
)
|
||||
self.assertTrue(result.success, f"Failed: {result.error_message}")
|
||||
|
||||
output = self.engine.generate(
|
||||
prompt=[TEST_PROMPT],
|
||||
sampling_params={"max_new_tokens": MAX_NEW_TOKENS, "temperature": 0.0},
|
||||
lora_path=["self_cognition_Alice_flattened"],
|
||||
)
|
||||
self.assertEqual(
|
||||
output[0]["text"][: len(EXPECTED_OUTPUT)],
|
||||
EXPECTED_OUTPUT,
|
||||
"Output after applying LoRA via flattened bucket does not match expected",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.engine.shutdown()
|
||||
|
||||
Reference in New Issue
Block a user