[LoRA] Support modules_to_save for sequence classification (#53555)

Signed-off-by: linitra24 <Joy25810@foxmail.com>
Signed-off-by: linitra24 <renshuang.zhou@daocloud.io>
Co-authored-by: Jee Jee Li <pandaleefree@gmail.com>
This commit is contained in:
linitra24
2026-09-16 07:15:42 -07:00
committed by GitHub
co-authored by Jee Jee Li
parent ec4a3a5370
commit c81eb3e69c
20 changed files with 681 additions and 21 deletions
@@ -74,6 +74,20 @@ class DispatchPooler(Pooler):
def get_pooling_updates(self, task: PoolingTask) -> PoolingParamsUpdate:
return self.poolers_by_task[task].get_pooling_updates(task)
def replace_classifier(
self,
new_classifier: ClassifierFn,
) -> None:
"""Replaces the classifier to the LoRA-wrapped version."""
for task, pooler in self.poolers_by_task.items():
if task not in {"classify"}:
# Now LoRA only supports classification tasks,
# so we only replace the classifier for "classify" task.
continue
head = getattr(pooler, "head", None)
if head is not None and hasattr(head, "classifier"):
head.classifier = new_classifier
def forward(
self,
hidden_states: torch.Tensor,