Support Audio Flamingo Next checkpoints#44830
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
ebezzam
left a comment
There was a problem hiding this comment.
Some fixes are also needed for the config!
| if isinstance(self.audio_config, dict): | ||
| self.audio_config["model_type"] = self.audio_config.get("model_type", "audioflamingo3_encoder") | ||
| elif self.audio_config is None: | ||
| self.audio_config = {"model_type": "audioflamingo3_encoder"} | ||
| if self.rope_parameters is None: | ||
| self.rope_parameters = { | ||
| "rope_type": "default", | ||
| "rope_theta": kwargs.get("rope_theta", 1200), | ||
| "partial_rotary_factor": kwargs.get("partial_rotary_factor", 0.2), | ||
| } | ||
| if isinstance(self.audio_config, dict): | ||
| self.audio_config["model_type"] = self.audio_config.get("model_type", "audioflamingonext_encoder") | ||
| self.audio_config = CONFIG_MAPPING[self.audio_config["model_type"]](**self.audio_config) | ||
| elif self.audio_config is None: | ||
| self.audio_config = CONFIG_MAPPING["audioflamingonext_encoder"]() |
There was a problem hiding this comment.
two code blocks for self.audio_config are getting genetated
| if isinstance(self.audio_config, dict): | ||
| self.audio_config["model_type"] = self.audio_config.get("model_type", "audioflamingo3_encoder") | ||
| elif self.audio_config is None: | ||
| self.audio_config = {"model_type": "audioflamingo3_encoder"} |
There was a problem hiding this comment.
modular doesn't let you override the other self.audio_config unfortunately. But what stops from using MusicFlamingoConfig as is?
|
@ebezzam thanks for the reviews!
|
eustlb
left a comment
There was a problem hiding this comment.
Thanks a lot for the great work, @lashahub. Since this model is actually MusicFlamingo, there is no strong reason to merge it as a separate model. I understand that the main issue is the naming, and now that we have clarified the situation, it might have been better to merge this architecture from the start under the AudioFlamingoNext naming, with the MusicFlamingo Hub repo simply being a specific checkpoint of the AudioFlamingoNext model.
Note that adding a new model based on an already merged architecture is not a problem. For example, look at the granite-speech releases: since they are just new checkpoints for the granite_speech model type, they simply use AutoModelForSpeechSeq2Seq.
Here, I see two possible paths forward:
-
The simplest option: just use
AutoModelForSpeechSeq2Seqwithmodel_type: musicflamingoin the config. -
If the
MusicFlamingocheckpoints on the Hub actually correspond to theAudioFlamingoNextarchitecture, then we could replace the currentmusicflamingoarchitecture withAudioFlamingoNextand addMusicFlamingoclasses for backward compatibility.
Personally, I would much rather go with option 1.
# Conflicts: # src/transformers/models/musicflamingo/configuration_musicflamingo.py # src/transformers/models/musicflamingo/modular_musicflamingo.py
|
Thanks for the suggestion @eustlb, I followed option 1. Audio Flamingo Next is no longer added as a separate Transformers architecture. I removed the AF-Next model/config/processor/tests/docs and switched the AF-Next conversion path to use the existing MusicFlamingo classes with I kept the AF-Next converter under MusicFlamingo for reproducibility, and reconverted the AF-Next checkpoints with this setup. |
| tokenizer=AutoTokenizer.from_pretrained(str(llm_dir), chat_template=tokenizer_chat_template, use_fast=True), | ||
| chat_template=processor_chat_template, | ||
| ) | ||
| processor.tokenizer.model_max_length = 32768 |
There was a problem hiding this comment.
FYI checkpoint is actually using this: https://huggingface.co/nvidia/audio-flamingo-3-hf/blob/main/config.json#L66
ebezzam
left a comment
There was a problem hiding this comment.
@eustlb they've gone forward with the first option 🤗
The model type is updated in the checkpoint: https://huggingface.co/nvidia/audio-flamingo-next-hf/commit/1574fdfdb77dee40f7373e6e0faa16f70c224743
I left some comments on the other changes if we can get your approval?
There was a problem hiding this comment.
@eustlb ok to add the conversion script for the new checkpoint? https://huggingface.co/nvidia/audio-flamingo-next-hf
| tokenizer=AutoTokenizer.from_pretrained(str(llm_dir), chat_template=tokenizer_chat_template, use_fast=True), | ||
| chat_template=processor_chat_template, | ||
| ) | ||
| processor.tokenizer.model_max_length = 32768 |
There was a problem hiding this comment.
similarly, now matching checkpoint: https://huggingface.co/nvidia/music-flamingo-2601-hf/blob/main/config.json#L76
|
@lashahub, @Sreyan88 one other comment: can you replace the |
|
Thanks for the review @ebezzam, I've updated the path placeholders. |
| self.rope_parameters = { | ||
| "rope_type": "default", | ||
| "rope_theta": kwargs.get("rope_theta", 1200), | ||
| "partial_rotary_factor": kwargs.get("partial_rotary_factor", 0.2), | ||
| } |
There was a problem hiding this comment.
rope_theta and partial_rotary_factor are not exposed kwargs, API is to directly pass rope_parameters
| self.rope_parameters = { | |
| "rope_type": "default", | |
| "rope_theta": kwargs.get("rope_theta", 1200), | |
| "partial_rotary_factor": kwargs.get("partial_rotary_factor", 0.2), | |
| } | |
| self.rope_parameters = { | |
| "rope_type": "default", | |
| "rope_theta": 1200.0, | |
| "partial_rotary_factor": 0.2, | |
| } |
|
[For maintainers] Suggested jobs to run (before merge) run-slow: audioflamingo3, musicflamingo |
* Music flamingo * Fix pos embeddings * Method arg docstrings * Add tests & docs * Fix AF3 dtype bug * Fix the MF performance issue * Fix pos embeddings * Fix embeddings & format * Remove external deps * Update processor token names * Cleanup * Simplify RotaryEmbedding to lang-only * Reuse AF3 config classes * Trim+rename rotary embedding * Call parent _init_weights first and drop rotary einsum * Precompute rotary cache at init * Use modular processor pattern for MusicFlamingo * Remove audio-only inference example * Refactor Audio Feature Casting Path * Clarify private source repo * Clean up modular * Move config to modular * Formatting * Remove dummy * Derive musicflamingo timing and rotary config * Llama style rotary embeddings * Added reproducer comments * Expose _init_weights for modular. * Satisfy repo checks * Align MusicFlamingo rotary with Llama style * Move MusicFlamingo _init_weights to encoder * Keep old behavior * Move MusicFlamingo rotary settings into encoder rope_parameters * Use AutoConfig in AF3/MF * Align MusicFlamingo RoTE with Llama RoPE conventions * Update outdated fixtures * init_weights without changing others * FIx import * Remove backward compat * Regenerate modeling for MF * Fix AF3 batch inference bug * Simplify config and nit. * Conform more to transformers convention, e.g. removing unused code paths. * Add another possible AF3 prefix. * Use auto_docstring and update docstrings. * Nits * Nit for review * Shift RoTE to main model so that encoder can be directly used from AF3. * Refactoring nit. * Fix init * Fix some failing tests * Fix AF3 & MF and add batching tests * Fix audio embedding masking (bad post length) * Nits and remove since same as GLM was bug in post length computation * Simplify MF as AF3, and style checks. * New config after merge and modular update. * Address music flamingo tests, and some cleanup. * style check * Regenerate config. * Update fixtures. * Nits * Nit * Add AudioFlamingoNext alias model * Regenerate AF-Next files * Improve RoTE config * Refine MusicFlamingo rotary time handling * Simplification, and update AF3 processor for better modular * Fix torch export * Simplify modular, including upstreaming input_ids input to get_audio_features * Remove upstreaming of input_ids to get_audio_features, and remove audio_rotary_dim. * Switch to MoonshineRotaryEmbedding, and cleanup. * Remove hardcoded MusicFlamingo partial_rotary_factor * Update fixtures * Compile re.sub * Update src/transformers/models/musicflamingo/modular_musicflamingo.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/models/musicflamingo/modular_musicflamingo.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Style * Update fixtures. * Conditional torch import for processor. * Merge MF & convert modular * 30 mins in AF-Next * Regen * Fix AF-Next converter * AF-Next readme * Add tests * Update AF-Next docs * Fix MusicFlamingo and AFNext context metadata and rope defaults * Update fixtures * Address reviews * Add reproducer * Update AF-Next converter * Remove AF-Next * Keep AF-Next converter * Update src/transformers/models/musicflamingo/modular_musicflamingo.py * make --------- Co-authored-by: Eric B <ebezzam@gmail.com> Co-authored-by: Eric Bezzam <4757445+ebezzam@users.noreply.github.com> Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> Co-authored-by: eustlb <94853470+eustlb@users.noreply.github.com>
* Music flamingo * Fix pos embeddings * Method arg docstrings * Add tests & docs * Fix AF3 dtype bug * Fix the MF performance issue * Fix pos embeddings * Fix embeddings & format * Remove external deps * Update processor token names * Cleanup * Simplify RotaryEmbedding to lang-only * Reuse AF3 config classes * Trim+rename rotary embedding * Call parent _init_weights first and drop rotary einsum * Precompute rotary cache at init * Use modular processor pattern for MusicFlamingo * Remove audio-only inference example * Refactor Audio Feature Casting Path * Clarify private source repo * Clean up modular * Move config to modular * Formatting * Remove dummy * Derive musicflamingo timing and rotary config * Llama style rotary embeddings * Added reproducer comments * Expose _init_weights for modular. * Satisfy repo checks * Align MusicFlamingo rotary with Llama style * Move MusicFlamingo _init_weights to encoder * Keep old behavior * Move MusicFlamingo rotary settings into encoder rope_parameters * Use AutoConfig in AF3/MF * Align MusicFlamingo RoTE with Llama RoPE conventions * Update outdated fixtures * init_weights without changing others * FIx import * Remove backward compat * Regenerate modeling for MF * Fix AF3 batch inference bug * Simplify config and nit. * Conform more to transformers convention, e.g. removing unused code paths. * Add another possible AF3 prefix. * Use auto_docstring and update docstrings. * Nits * Nit for review * Shift RoTE to main model so that encoder can be directly used from AF3. * Refactoring nit. * Fix init * Fix some failing tests * Fix AF3 & MF and add batching tests * Fix audio embedding masking (bad post length) * Nits and remove since same as GLM was bug in post length computation * Simplify MF as AF3, and style checks. * New config after merge and modular update. * Address music flamingo tests, and some cleanup. * style check * Regenerate config. * Update fixtures. * Nits * Nit * Add AudioFlamingoNext alias model * Regenerate AF-Next files * Improve RoTE config * Refine MusicFlamingo rotary time handling * Simplification, and update AF3 processor for better modular * Fix torch export * Simplify modular, including upstreaming input_ids input to get_audio_features * Remove upstreaming of input_ids to get_audio_features, and remove audio_rotary_dim. * Switch to MoonshineRotaryEmbedding, and cleanup. * Remove hardcoded MusicFlamingo partial_rotary_factor * Update fixtures * Compile re.sub * Update src/transformers/models/musicflamingo/modular_musicflamingo.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Update src/transformers/models/musicflamingo/modular_musicflamingo.py Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> * Style * Update fixtures. * Conditional torch import for processor. * Merge MF & convert modular * 30 mins in AF-Next * Regen * Fix AF-Next converter * AF-Next readme * Add tests * Update AF-Next docs * Fix MusicFlamingo and AFNext context metadata and rope defaults * Update fixtures * Address reviews * Add reproducer * Update AF-Next converter * Remove AF-Next * Keep AF-Next converter * Update src/transformers/models/musicflamingo/modular_musicflamingo.py * make --------- Co-authored-by: Eric B <ebezzam@gmail.com> Co-authored-by: Eric Bezzam <4757445+ebezzam@users.noreply.github.com> Co-authored-by: Arthur <48595927+ArthurZucker@users.noreply.github.com> Co-authored-by: eustlb <94853470+eustlb@users.noreply.github.com>
This PR adds
AudioFlamingoNextas a separate model name that inherits directly fromMusicFlamingo#43538 and keeps the same architecture and behavior.Changes:
audioflamingonextmodel files