Skip to content

[Tracing] Raise _is_compiling_flag while tracing #1388

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kylesayrs
Copy link
Collaborator

@kylesayrs kylesayrs commented Apr 27, 2025

Purpose

  • Reduce model support burden by skipping untraceable code which has been marked by implementers using is_torchdynamo_compiling and other checks

transformers/models/llava/modeling_llava.py

if not is_torchdynamo_compiling() and inputs_embeds[special_image_mask].numel() != image_features.numel():
    n_image_tokens = (input_ids == self.config.image_token_id).sum()
    n_image_features = image_features.shape[0] * image_features.shape[1]
    raise ValueError(
        f"Image features and image tokens do not match: tokens: {n_image_tokens}, features {n_image_features}"
    )

torch/compiler/init.py

def is_compiling() -> bool:
    """
    Indicates whether a graph is executed/traced as part of torch.compile() or torch.export().

    Example::

        >>> def forward(self, x):
        >>>     if not torch.compiler.is_compiling():
        >>>        pass # ...logic that is not needed in a compiled/traced graph...
        >>>
        >>>     # ...rest of the function...
    """

Changes

  • Set _is_compiling_flag to True while tracing

Testing

Signed-off-by: Kyle Sayers <[email protected]>
Copy link

👋 Hi! Thank you for contributing to llm-compressor. Please add the ready label when the PR is ready for review.

Note: This is required to complete the testing suite, please only add the label once the PR is code complete and local testing has been performed.

@kylesayrs kylesayrs marked this pull request as ready for review April 27, 2025 16:00
@kylesayrs kylesayrs added the ready When a PR is ready for review label Apr 27, 2025
Copy link
Collaborator

@brian-dellabetta brian-dellabetta left a comment

Choose a reason for hiding this comment

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

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready When a PR is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants