Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does current implementation of Fusion support Stack Composition? #574

Closed
SpaceHunterInf opened this issue Aug 11, 2023 · 2 comments
Closed
Labels
question Further information is requested

Comments

@SpaceHunterInf
Copy link

SpaceHunterInf commented Aug 11, 2023

Environment info

I believe I am using version 3.2.1. However, I am not sure how to check the version that I installed. Would you please also tell me how to check this? I can only check the verision of "transformers" which is "'4.24.0".

Details

Traceback (most recent call last): File "T5_adapter.py", line 279, in <module> train(args) File "T5_adapter.py", line 121, in train model.add_adapter_fusion(ac.Fuse(ac.Stack('base','a'),ac.Stack('base','b'),ac.Stack('base','c'))) File "/home/xz479/rds/hpc-work/miniconda3/envs/adapter/lib/python3.8/site-packages/transformers/adapters/model_mixin.py", line 509, in add_adapter_fusion self.config.adapters.add_fusion(adapter_names, config=config) File "/home/xz479/rds/hpc-work/miniconda3/envs/adapter/lib/python3.8/site-packages/transformers/adapters/configuration.py", line 758, in add_fusion fusion_name = ",".join(fusion_name) TypeError: sequence item 0: expected str instance, Stack found

What I intended to do is to pass the data through a "base" adapter, then the output is fed to 3 adapters "a,b,c" identically.
So I did this model.add_adapter_fusion(ac.Fuse(ac.Stack('base','a'),ac.Stack('base','b'),ac.Stack('base','c'))).
In the documentation, it says Fuse can support Stack without further composition. However it gives me this error. Would you please verify if I am using the composition correctly?

Thank you very much.

@SpaceHunterInf SpaceHunterInf added the question Further information is requested label Aug 11, 2023
@adapter-hub-bert
Copy link
Member

This issue has been automatically marked as stale because it has been without activity for 90 days. This issue will be closed in 14 days unless you comment or remove the stale label.

@calpt
Copy link
Member

calpt commented Nov 19, 2023

Fuse and Stack can indeed be nested as described. For the setup described (first passing though "base" adapter and afterwards fusing adapters "a", "b" and "c", the code would look as follows:

model.add_adapter("base")
model.add_adapter("a")
model.add_adapter("b")
model.add_adapter("c")

model.add_adapter_fusion(["a", "b", "c"])

model.active_adapters = ac.Stack("base", ac.Fuse("a", "b", "c"))

Note that for adding the fusion layer (add_adapter_fusion()), only the to be fused adapters should be specified. The full composition setup is then given when activating adapters via active_adapters.

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants