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

Skip to content

Check docstring inside modular files as well#38988

Open
Cyrilvallez wants to merge 17 commits into
mainfrom
check-docstring
Open

Check docstring inside modular files as well#38988
Cyrilvallez wants to merge 17 commits into
mainfrom
check-docstring

Conversation

@Cyrilvallez

@Cyrilvallez Cyrilvallez commented Jun 23, 2025

Copy link
Copy Markdown
Member

What does this PR do?

We should check docstring in modular files as well! Otherwise, most of the time if the docstring is wrong in modular, e.g. in a Config, make fix-copies will apply modular with wrong docstring, then check_docstring will fix it, but we still have inconsistency between the modular (which was not fixed automatically) and the modeling which has been fixed! Thus reapplying the modular later will lead to wrong docstrings again.
This PR solves this circular inconsistency, and improves the overall modular workflow.

Also fixes some bad modulars at the same time (use relative imports everywhere, and remove bad inheritance of BambaCache)

cc @yonigozlan as you touched it a lot quite recently, and cc @ArthurZucker

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

Comment on lines 99 to +100
# Adapted from transformers.models.jamba.modeling_jamba.HybridMambaAttentionDynamicCache for the v2 mixer
class HybridMambaAttentionDynamicCache(modeling_jamba.HybridMambaAttentionDynamicCache):
class HybridMambaAttentionDynamicCache(HybridMambaAttentionDynamicCache):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should never have been here

Comment on lines 44 to +43
auto_docstring,
is_torch_flex_attn_available,
logger,
logging,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

logger does not exist

Comment on lines 48 to +49
)
from ..paligemma.modeling_paligemma import (
PaligemmaCausalLMOutputWithPast,
PaliGemmaCausalLMOutputWithPast,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

PaligemmaCausalLMOutputWithPast does not exist - missing an uppercase for the correct one

Comment on lines -225 to +226
# Adapted from transformers.models.jamba.modeling_jamba.HybridMambaAttentionDynamicCache for the v2 mixer
class HybridMambaAttentionDynamicCache(modeling_jamba.HybridMambaAttentionDynamicCache):
class HybridMambaAttentionDynamicCache(DynamicCache):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should never have been here

@yonigozlan yonigozlan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice! Just raised a potential issue with check_auto_docstrings

Comment on lines +278 to +283
r"""
pixel_attention_mask (`torch.Tensor` of shape `(batch_size, image_size, image_size)`, *optional*):
Mask to avoid performing attention on padding pixel indices.
image_hidden_states (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
The hidden states of the image encoder after modality projection.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we really need this here? It's the same as Idefics3

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Actually I had to add it because the class explicitly was overrideing @auto_docstring, so check_auto_docstrings was adding empty placeholders -> this is why I thought that check_auto_docstrings was correctly working, but maybe my change is not enough? In any case, I removed both the docstring and decorator now, as it's indeed redundant from Idefics3

Comment thread Makefile
Comment on lines 88 to -93
python utils/check_copies.py --fix_and_overwrite
python utils/check_docstrings.py --fix_and_overwrite
python utils/check_modular_conversion.py --fix_and_overwrite
python utils/check_dummies.py --fix_and_overwrite
python utils/check_pipeline_typing.py --fix_and_overwrite
python utils/check_doctest_list.py --fix_and_overwrite
python utils/check_docstrings.py --fix_and_overwrite

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Agreed on changing the order here on principle, although it will kind of break check_auto_docstrings (included in python utils/check_docstrings.py --fix_and_overwrite command), as there is the same issue you described in this PR for check_auto_docstrings, but it's only fixed for check_docstrings here.
So for models with modular, check_auto_docstrings will overwrite the docstring in the modeling files if there's any issue, which will then be overridden by modular, making it as if nothing has changed after fix-copies even if there is something wrong with auto_docstring.
This is really more of an issue with check_auto_docstrings not checking the modular files for now, as there is some more difficult logic to handle compared to modeling files. It's on my to-do list, but seeing as this will break check_auto_docstrings, maybe for the scope of this PR, we can at least split python utils/check_docstrings.py --fix_and_overwrite in two to separate check_docstrings and check_auto_docstrings, and place python utils/check_auto_docstrings.py --fix_and_overwrite after modular conversion.
Wdyt @Cyrilvallez ?

@Cyrilvallez Cyrilvallez Jun 24, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Humm, I thought I added sufficient code here for check_auto_docstring to check modular files as well - at least, it worked well on your above comment (see my answer as well) - but maybe it's not enough based on your most recent changes?

@Cyrilvallez

Copy link
Copy Markdown
Member Author

We discussed offline with @yonigozlan:

  • this fix works nicely for the check without auto-docstring, as classes inherit docs from parent, so even if doc is not present but expected to be "recopied automatically" by modular, the check passes as the __doc__ attribute is inherited
  • For check_auto_docstring it's in general not an issue either, as there are 2 scenarios: either we inherit from an upstream class, and we don't need the decorator explicitly as it will be inherited automatically, or we use it explicitly but we also overwrite the doc in this case anyway, so the check will pass (only if explicitly adding the decorator but without the doc then the test will complain, but IMO it is right to complain in that case, even if the doc could be inherited -> why overwrite the decorator then if everything is the same as upstream??)

In any case, @yonigozlan said he wanted to refactor check_auto_docstring to use the __doc__ attribute and make it more robust

@github-actions

github-actions Bot commented Jul 9, 2025

Copy link
Copy Markdown
Contributor

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

run-slow: aya_vision, bamba, biogpt, colpali, colqwen2, conditional_detr, data2vec, deformable_detr, dinov2_with_registers, dpt, falcon_h1, gemma3, gemma3n, got_ocr2, granitemoehybrid, grounding_dino

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