Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix output labels for AudioFlamingo3 (and related) models#47112

Merged
ebezzam merged 5 commits into
huggingface:mainfrom
ebezzam:af3_output_labels_fix
Jul 7, 2026
Merged

Fix output labels for AudioFlamingo3 (and related) models#47112
ebezzam merged 5 commits into
huggingface:mainfrom
ebezzam:af3_output_labels_fix

Conversation

@ebezzam

@ebezzam ebezzam commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

CI

What does this PR do?

Fix bug in prepared output labels, as mentioned here, after this refactor I think?

Script comparing before/after fix

from transformers import AudioFlamingo3ForConditionalGeneration, AutoProcessor


model_id = "nvidia/audio-flamingo-3-hf"
processor = AutoProcessor.from_pretrained(model_id)
model = AudioFlamingo3ForConditionalGeneration.from_pretrained(model_id, device_map="auto")
model.train()

conversation = [
    [
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Transcribe the input speech."},
                {
                    "type": "audio",
                    "path": "https://huggingface.co/datasets/nvidia/AudioSkills/resolve/main/assets/WhDJDIviAOg_120_10.mp3",
                },
            ],
        },
        {
            "role": "assistant",
            "content": [
                {
                    "type": "text",
                    "text": "The transcription of the audio is 'summer follows spring the days grow longer and the nights are warm'.",
                }
            ],
        },
    ],
    [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "This track feels really peaceful and introspective. What elements make it feel so calming and meditative?",
                },
                {
                    "type": "audio",
                    "path": "https://huggingface.co/datasets/nvidia/AudioSkills/resolve/main/assets/FPSbCAANfbJLVSwD.mp3",
                },
            ],
        },
        {
            "role": "assistant",
            "content": [
                {"type": "text", "text": "The transcription of the audio is 'some transcription of the audio'."}
            ],
        },
    ],
]

inputs = processor.apply_chat_template(
    conversation,
    tokenize=True,
    add_generation_prompt=True,
    return_dict=True,
    processor_kwargs={"output_labels": True},
).to(model.device, dtype=model.dtype)

# What the model is actually trained to predict: decode the unmasked label positions
for i, labels in enumerate(inputs["labels"]):
    print(f"Labels {i}:", repr(processor.tokenizer.decode(labels[labels != -100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$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!'
Loss: 14.966017723083496

AFTER

Labels 0: "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\nTranscribe the input speech.<|im_end|>\n<|im_start|>assistant\nThe transcription of the audio is 'summer follows spring the days grow longer and the nights are warm'.<|im_end|>\n<|im_start|>assistant\n"
Labels 1: "<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\nThis track feels really peaceful and introspective. What elements make it feel so calming and meditative?<|im_end|>\n<|im_start|>assistant\nThe transcription of the audio is 'some transcription of the audio'.<|im_end|>\n<|im_start|>assistant\n"
Loss: 5.149610996246338

"""

@ebezzam ebezzam changed the title Fix output labels. Fix output labels for AudioFlamingo3 (and related) models Jul 6, 2026
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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 ebezzam requested a review from zucchini-nlp July 6, 2026 15:59
model_inputs = super().__call__(audio=audio, text=text, **kwargs)

if output_labels:
labels = model_inputs.pop("mm_token_type_ids")

@ebezzam ebezzam Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fix. the other two are generated via modular

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily here but I expect quite a few to do the same ish re shifting based on the input --> maybe a util?

Comment on lines -108 to +109
labels = model_inputs.pop("mm_token_type_ids")
mm_token_type_ids = model_inputs.pop("mm_token_type_ids")
labels = model_inputs["input_ids"].clone()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg, right! Thanks for catching that

@zucchini-nlp

zucchini-nlp commented Jul 6, 2026

Copy link
Copy Markdown
Member

should we add a test in processor tester? would be nice so we can catch bugs early on

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!


@property
def audio_ids(self):
def audio_token_ids(self):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

audio_token_ids is expected here

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still be a bit careful and make some BC deprecation

@ebezzam ebezzam added this pull request to the merge queue Jul 6, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jul 6, 2026

@vasqu vasqu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just nits but overall looks good, thanks 🙏

model_inputs = super().__call__(audio=audio, text=text, **kwargs)

if output_labels:
labels = model_inputs.pop("mm_token_type_ids")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessarily here but I expect quite a few to do the same ish re shifting based on the input --> maybe a util?


@property
def audio_ids(self):
def audio_token_ids(self):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we still be a bit careful and make some BC deprecation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit if we are already testing audio flamingo and music flamingo we should also glm asr imo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GLM ASR doesn't have processor tests 🥲 but adding some!

@ebezzam ebezzam enabled auto-merge July 7, 2026 13:44
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: audioflamingo3, glmasr, musicflamingo

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 28810434165:1
Result: success | Jobs: 3 | Tests: 152 | Failures: 0 | Duration: 7m 35s

@ebezzam ebezzam added this pull request to the merge queue Jul 7, 2026
Merged via the queue into huggingface:main with commit 080fe1e Jul 7, 2026
32 checks passed
@ebezzam ebezzam deleted the af3_output_labels_fix branch July 7, 2026 13:57
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

Successfully merging this pull request may close these issues.

4 participants