Skip to content

Commit 051c927

Browse files
authored
Minor update to make rank optional in peft class (#846)
Make rank flexible and add some other checks for, eg, lora and fact-based peft methods
1 parent e417023 commit 051c927

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

micro_sam/models/peft_sam.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,17 @@ class PEFT_Sam(nn.Module):
307307
def __init__(
308308
self,
309309
model: Sam,
310-
rank: int,
310+
rank: Optional[int] = None,
311311
peft_module: nn.Module = LoRASurgery,
312312
attention_layers_to_update: Union[List[int]] = None,
313313
quantize: bool = False,
314314
**module_kwargs
315315
):
316316
super().__init__()
317317

318-
assert rank > 0
318+
if issubclass(peft_module, Union[LoRASurgery, FacTSurgery]) and (not rank or rank <= 0):
319+
raise RuntimeError("The chosen PEFT method cannot run without a valid rank choice.")
320+
319321
assert issubclass(peft_module, Union[LoRASurgery, FacTSurgery, SelectiveSurgery, SSFSurgery, AdaptFormer]), (
320322
"Invalid PEFT module"
321323
)

0 commit comments

Comments
 (0)