Skip to content

Fix typo in MusicgenForCausalLM.generate()#46974

Merged
zucchini-nlp merged 2 commits into
huggingface:mainfrom
jiqing-feng:musicgen
Jul 21, 2026
Merged

Fix typo in MusicgenForCausalLM.generate()#46974
zucchini-nlp merged 2 commits into
huggingface:mainfrom
jiqing-feng:musicgen

Conversation

@jiqing-feng

@jiqing-feng jiqing-feng commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

CI

input_ids_length is an int (the sequence length), not a tensor, so calling
.shape[1] on it makes MusicgenForCausalLM.generate() always raise
AttributeError: 'int' object has no attribute 'shape'. It should reference
input_ids instead, matching generation/utils.py and the already-correct
musicgen_melody copy.

-            input_ids_length.shape[1] != input_ids_length
+            input_ids.shape[1] != input_ids_length
             and model_input_name == "inputs_embeds"
             and not self.config.is_encoder_decoder
         ):
-            max_cache_length += input_ids_length.shape[1]
+            max_cache_length += input_ids.shape[1]

Reproduction

import torch
from transformers import MusicgenForConditionalGeneration

dec = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-medium").decoder
pad = dec.config.pad_token_id
ids = torch.full((dec.config.num_codebooks, 8), pad, dtype=torch.long)
# before the fix: AttributeError: 'int' object has no attribute 'shape'
dec.generate(input_ids=ids, max_new_tokens=16, pad_token_id=pad,
             decoder_start_token_id=pad, num_return_sequences=1)

Signed-off-by: jiqing-feng <[email protected]>
@jiqing-feng
jiqing-feng marked this pull request as ready for review June 30, 2026 04:55
@github-actions
github-actions Bot requested a review from eustlb June 30, 2026 04:55
Comment thread src/transformers/models/musicgen/modeling_musicgen.py Outdated
@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: musicgen

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 28421284920:2
Result: success | Jobs: 6 | Tests: 753 | Failures: 0 | Duration: 4m 22s

@zucchini-nlp zucchini-nlp left a comment

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.

Thanks

@zucchini-nlp

Copy link
Copy Markdown
Member

run-slow: musicgen

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/musicgen"]
quantizations: []

@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.

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN b75d0b3f workflow commit (merge commit)
PR 208dd06e branch commit (from PR)
main 29985e67 base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

@zucchini-nlp
zucchini-nlp added this pull request to the merge queue Jul 21, 2026
Merged via the queue into huggingface:main with commit c22f7f7 Jul 21, 2026
38 checks passed
SangbumChoi added a commit to SangbumChoi/transformers that referenced this pull request Jul 22, 2026
* upstream/main: (39 commits)
  Remove deprecated training args and `is_fast` property (huggingface#46917)
  Consistent output shape from `get_image_features` (huggingface#46405)
  Fix multi-device mxfp4 dequantization race in `_convert_moe_packed_tensors` (huggingface#47423)
  fix failed test cases for qwen3_omni_moe model (huggingface#47449)
  Fix Hunyuan-VL PIL image resize parity with reference preprocessing (huggingface#47233)
  Move `value` padding into the attention interfaces that need it (huggingface#47451)
  Simplify function dispatch for linear attention (huggingface#47450)
  [cache] Allow sliding window layers to be roll-backed for speculative decoding (huggingface#47447)
  Fix double-shifted training loss in GitForCausalLM (huggingface#47395)
  Fix CohereASR training-loss double-shift (same as Moonshine fix huggingface#46784) (huggingface#46895)
  Warn when `group_by_length` is silently ignored for iterable datasets (huggingface#47379)
  Update bug report list (huggingface#46607)
  Fix shape mismatch in KyutaiSpeechToText `generate()` last window (huggingface#46952)
  Optimize flash attention max seqlen computation in vision attention (huggingface#47170)
  fix: remove unreachable return in special token builder (huggingface#47420)
  Add Harry to slow CI (huggingface#47454)
  BLT: vectorize patch length processing (huggingface#47385)
  Fix `TrackioCallback` fails to log evaluation metrics after training ends (huggingface#46935)
  [Kimi] add integration tests (huggingface#47383)
  Fix typo in `MusicgenForCausalLM.generate()` (huggingface#46974)
  ...
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.

3 participants