transformers - ✅(Solved) Fix Wrong docstring for position_ids [2 pull requests, 3 comments, 4 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#44373Fetched 2026-04-08 00:28:53
View on GitHub
Comments
3
Participants
4
Timeline
9
Reactions
0
Timeline (top)
commented ×3cross-referenced ×2labeled ×1mentioned ×1

Fix Action

Fixed

PR fix notes

PR #44547: Fix position_ids docstring in modeling_flash_attention_utils.py

Description (problem / solution / changelog)

Fixes #44373

Summary

  • Corrected the docstring for position_ids parameter in prepare_fa_kwargs_from_position_ids and _prepare_from_posids which incorrectly described attention mask semantics ("Boolean or int tensor... 1 means valid and 0 means not valid")
  • The docstring now accurately describes position indices behavior

Testing

  • Docstring-only change, no code behavior affected

This contribution was developed with AI assistance (Claude Code).

Changed files

  • src/transformers/modeling_flash_attention_utils.py (modified, +2/-2)

PR #44590: Fix incorrect docstring for position_ids

Description (problem / solution / changelog)

Fixes incorrect documentation for position_ids in masking_utils.py.

The docstring previously described position_ids as torch.Tensor.
This PR updates it to torch.LongTensor and aligns the description with the standard wording used across the Transformers codebase.

Fixes #44373

What does this PR do?

<!-- Congratulations! You've made it this far! You're not quite done yet though. Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution. Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change. Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost. --> <!-- Remove if not applicable -->

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline, Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the documentation guidelines, and here are tips on formatting docstrings.
  • Did you write any new necessary tests?

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.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @ If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**. Please tag fewer than 3 people. Models: - text models: @ArthurZucker @Cyrilvallez - vision models: @yonigozlan @molbap - audio models: @eustlb @ebezzam @vasqu - multimodal models: @zucchini-nlp - graph models: @clefourrier Library: - generate: @zucchini-nlp (visual-language models) or @gante (all others) - continuous batching: @remi-or @ArthurZucker @McPatate - pipelines: @Rocketknight1 - tokenizers: @ArthurZucker and @itazap - trainer: @SunMarc - attention: @vasqu @ArthurZucker @CyrilVallez - model loading (from pretrained, etc): @CyrilVallez - distributed: @3outeille @ArthurZucker - CIs: @ydshieh Integrations: - ray/raytune: @richardliaw, @amogkam - Big Model Inference: @SunMarc - quantization: @SunMarc - kernels: @drbh - peft: @BenjaminBossan @githubnemo Devices/Backends: - AMD ROCm: @ivarflakstad - Intel XPU: @IlyasMoutawwakil - Ascend NPU: @ivarflakstad Documentation: @stevhliu Research projects are not maintained and should be taken as is. -->

Changed files

  • src/transformers/masking_utils.py (modified, +2/-2)
RAW_BUFFERClick to expand / collapse

extent analysis

Fix Plan

Fix Name

Update docstring for attention_mask and position_ids in modeling_flash_attention_utils.py

Steps

1. Update docstring for attention_mask

def attention_mask(input_ids: torch.Tensor, attention_mask: torch.Tensor) -> torch.Tensor:
    """
    Compute the masked attention weights.

    Args:
        input_ids (torch.Tensor): The input token ids.
        attention_mask (torch.Tensor): The attention mask.

    Returns:
        torch.Tensor: The masked attention weights.
    """

2. Update docstring for position_ids

def position_ids_from_input_ids(input_ids: torch.Tensor) -> torch.Tensor:
    """
    Create position ids from input ids.

    Args:
        input_ids (torch.Tensor): The input token ids.

    Returns:
        torch.Tensor: The position ids.
    """

3. Update the docstring for the attention_mask parameter in the attention_mask function

def attention_mask(input_ids: torch.Tensor, attention_mask: torch.Tensor) -> torch.Tensor:
    """
    Compute the masked attention weights.

    Args:
        input_ids (torch.Tensor): The input token ids.
        attention_mask (torch.Tensor): The attention mask to be used in the attention mechanism.

    Returns:
        torch.Tensor: The masked attention weights.
    """

4. Update the docstring for the position_ids parameter in the position_ids_from_input_ids function

def position_ids_from_input_ids(input_ids: torch.Tensor) -> torch.Tensor:
    """
    Create position ids from input ids.

    Args:
        input_ids (torch.Tensor): The input token ids.

    Returns:
        torch.Tensor: The position ids.
    """

Verification

  • Run python setup.py to rebuild the documentation.
  • Verify that the updated docstrings are

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING