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

HierarchicalModel can't be instantiated easily with AutoModel.from_pretrained #122

Open
angus-lherrou opened this issue Feb 16, 2023 · 2 comments
Assignees
Milestone

Comments

@angus-lherrou
Copy link
Collaborator

Since HierarchicalModel uses a separate config class for its encoder heads, it does not play nice with AutoModel.from_pretrained.

>>> model = AutoModel.from_pretrained(<path/to/pretrained/model>, config=<CnlpConfig>)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../site-packages/transformers/models/auto/auto_factory.py", line 463, in from_pretrained
    return model_class.from_pretrained(
  File ".../site-packages/transformers/modeling_utils.py", line 2156, in from_pretrained
    model = cls(config, *model_args, **model_kwargs)
TypeError: HierarchicalModel.__init__() missing 1 required positional argument: 'transformer_head_config'

This config needs to be the same as it is in training, so it needs to be part of what gets exported when saving the model. The most straightforward approach would be to incorporate it into CnlpConfig as an optional dict attribute.

@angus-lherrou angus-lherrou self-assigned this Feb 16, 2023
@angus-lherrou angus-lherrou added this to the v0.5.0 milestone Feb 16, 2023
@angus-lherrou
Copy link
Collaborator Author

The ideal invocation is as above; as a workaround with the current implementation, we can manually construct and pass in a HierarchicalTransformerConfig object with the same parameters as the model (which we will just have to know):

>>> transformer_head_config = HierarchicalTransformerConfig(n_layers=2, d_model=256 ,d_inner=2048, n_head=8, d_k=8, d_v=96)
>>> model = AutoModel.from_pretrained(encoder_name, config=config, transformer_head_config=transformer_head_config)

@tmills
Copy link
Contributor

tmills commented May 19, 2023

is this done?

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

No branches or pull requests

2 participants