| 410 | adapter: LoraLinearAdapter.Config = LoraLinearAdapter.default_config() |
| 411 | |
| 412 | def __init__(self, cfg: Config, *, parent: Module): |
| 413 | super().__init__(cfg, parent=parent) # Initiate the original linear layer. |
| 414 | cfg = self.config |
| 415 | self._add_child( |
| 416 | "layer", |
| 417 | cfg.layer.set( |
| 418 | input_dim=cfg.input_dim, |
| 419 | output_dim=cfg.output_dim, |
| 420 | ), |
| 421 | ) |
| 422 | self._add_child( |
| 423 | "adapter", |
| 424 | cfg.adapter.set( |
| 425 | input_dim=cfg.input_dim, |
| 426 | output_dim=cfg.output_dim, |
| 427 | ), |
| 428 | ) |
| 429 | |
| 430 | def forward(self, x: Tensor) -> Tensor: |
| 431 | return self.layer(x) + self.adapter(x) |