[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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user