-
Notifications
You must be signed in to change notification settings - Fork 29.4k
Granite speech - minor fixes to support training with the HF trainer #38833
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
base: main
Are you sure you want to change the base?
Conversation
avoid unused parameters that DDP does not like
trainers often pass this argument automatically
this ensures save_pretrained will not crash when saving the processor during training https://github.com/huggingface/transformers/blob/d5d007a1a0f0c11a726a54c8f00bd71825f84d02/src/transformers/feature_extraction_utils.py#L595
@@ -50,15 +50,16 @@ def __init__( | |||
**kwargs, | |||
): | |||
super().__init__(**kwargs) | |||
self.sampling_rate = sampling_rate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this isn't used currently
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it's not used. I added it to stay consistent with other audio feature extractors that have this property.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some comments on each change, giving relevant context
@@ -88,7 +88,9 @@ def __call__( | |||
else: | |||
audio_inputs = {} | |||
|
|||
text_inputs = self.tokenizer(prompt_strings, padding=True, **kwargs) | |||
if "padding" not in kwargs: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
avoids a crash when trainers pass padding=True
to the processor
@@ -92,7 +92,7 @@ def forward(self, hidden_states: torch.Tensor) -> torch.Tensor: | |||
hidden_states = hidden_states.view(batch_size * nblocks, self.window_size, dim) | |||
|
|||
query_output = self.qformer( | |||
query_embeds=self.query.data, | |||
query_embeds=self.query, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bugfix. When using .data
this trainable parameter did not receive gradients.
# Currently lazily initialized | ||
self.melspec = None | ||
requires_backends(self, ["torchaudio"]) | ||
self.mel_filters = torchaudio.transforms.MelSpectrogram(**self.melspec_kwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the lazy init, and renamed it to mel_filters
. This specific name avoids a crash when serializing the processor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this PR do?
Minor updates to
granite_speech
to enable finetuning it with HF trainers.padding=True
to the processor.data
from a forward callmelspec
tomel_filters
to leverage this, which avoids a crash onsave_pretrained
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
CC: @ArthurZucker @eustlb @alex-jw-brooks @avishaiElmakies @gsaon