-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor adapter composition implementation (#591)
Refactors the implementation of composition blocks in the model forward pass such that more of the logic is shared between all adapter methods. ### Changes - Move adapter methods into new `methods` folder - Introduce new `ComposableAdapterLayerBase` as subclass of `AdapterLayerbase` as shared base class of all adapter methods that support composition. - This class provides default implementations for a couple of composition blocks (currently `Stack`, `Parallel`, `BatchSplit`, `Average`) which can be used by all subclasses. - To enable these composition blocks for deriving methods, a couple of helper methods defined in `ComposableAdapterLayerBase` must be implemented. See https://github.com/calpt/adapter-transformers/blob/55fdc0cbe2f695914108a9c0e208127b13bc617e/src/adapters/methods/adapter_layer_base.py#L132-L222. - Different adapter methods require passing different inputs to each composition block. Thus, the input states are abstracted as a `NamedTuple` in the base class. Deriving classes should define concrete `NamedTuple`-derived state classes. E.g., see https://github.com/calpt/adapter-transformers/blob/55fdc0cbe2f695914108a9c0e208127b13bc617e/src/adapters/methods/bottleneck.py#L22 - Update `Split` composition block to support more than two child blocks. Splits are defined as a list of split indices, ie. `Split("a", "b", "c", splits=[64, 64, 64])`. **Breaking change** - Renamings: `AdapterLayer` -> `BottleneckLayer`; `PrefixTuningShim` -> `PrefixTuningLayer` --------- Co-authored-by: Leon Engländer <[email protected]>
- Loading branch information
1 parent
6da07d1
commit dfe17e9
Showing
42 changed files
with
1,150 additions
and
1,200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
AdapterLayer | ||
Adapter Implementation | ||
======================= | ||
|
||
.. autoclass:: adapters.AdapterLayer | ||
The following classes define the common interfaces for all adapter methods. | ||
They further hold logic shared by all adapter implementations. | ||
All newly added adapter methods should inherit from either one of these classes. | ||
|
||
.. autoclass:: adapters.AdapterLayerBase | ||
:members: | ||
|
||
.. autoclass:: adapters.ComposableAdapterLayerBase | ||
:members: |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.