Skip to content

[Bugfix] [pytorch] Patch AOTAutogradCache._get_shape_env #17142

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

Merged
merged 1 commit into from
Apr 26, 2025

Conversation

jamesjwu
Copy link
Contributor

@jamesjwu jamesjwu commented Apr 24, 2025

Description

After https://github.com/pytorch/pytorch/pull/151563/files, VLLM needs to patch an extra _get_shape_env() function when running inductor, as AOTAutogradCache now uses its own shape env function. The implementation is technically shared at torch._inductor.codecache.GuardedCache._get_shape_env, but adding it like this preserves backward compatibility with PyTorch 2.6.

Test Plan

The following program now runs when linking VLLM with pytorch main

from vllm import LLM, SamplingParams
import argparse

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description='Script with a boolean flag')
    parser.add_argument('--model',
                        type=str,
                        default="facebook/opt-125m",
                        help='Model to use for generation')
    args = parser.parse_args()
    prompts = [
        "Hello, my name is",
        "The president of the United States is",
        "The capital of France is",
        "The future of AI is",
    ]
    sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
    model = args.model

    compilation_config = {
        'level': 3,
        'compile_sizes': [1],
    }
    llm = LLM(model=model, compilation_config=compilation_config)
    outputs = llm.generate(prompts, sampling_params)

    for output in outputs:
        prompt = output.prompt
        generated_text = output.outputs[0].text
        print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

Copy link

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

🚀

@jamesjwu jamesjwu changed the title Patch AOTAutogradCache._get_shape_env [Bugfix] Patch AOTAutogradCache._get_shape_env Apr 24, 2025
@jamesjwu jamesjwu changed the title [Bugfix] Patch AOTAutogradCache._get_shape_env [Bugfix] [pytorch] Patch AOTAutogradCache._get_shape_env Apr 24, 2025
Copy link
Collaborator

@zou3519 zou3519 left a comment

Choose a reason for hiding this comment

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

LGTM assuming the tests pass

Copy link
Collaborator

@houseroad houseroad left a comment

Choose a reason for hiding this comment

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

Can we add some unittest in the following PR to ensure we catch the issue in future?

@houseroad
Copy link
Collaborator

could you fix the pre-commit?

@jamesjwu
Copy link
Contributor Author

  • Fixed the pre-commit and gated the change to be backward compatible
  • Will think about how to better unit test this as a followup: the thing is, the failure only happens on the latest version of torch (which VLLM does not pin), so in a way, all the existing unit tests would fail anyway once the pin updates. In fact, the unit test probably belongs on pytorch side, not here.

@houseroad houseroad added the ready ONLY add when PR is ready to merge/full CI is needed label Apr 25, 2025
@DarkLight1337 DarkLight1337 merged commit a6e72e1 into vllm-project:main Apr 26, 2025
59 checks passed
jikunshang pushed a commit to jikunshang/vllm that referenced this pull request Apr 29, 2025
lk-chen pushed a commit to lk-chen/vllm that referenced this pull request Apr 29, 2025
adobrzyn pushed a commit to HabanaAI/vllm-fork that referenced this pull request Apr 30, 2025
RichardoMrMu pushed a commit to RichardoMrMu/vllm that referenced this pull request May 12, 2025
zzzyq pushed a commit to zzzyq/vllm that referenced this pull request May 24, 2025
minpeter pushed a commit to minpeter/vllm that referenced this pull request Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready ONLY add when PR is ready to merge/full CI is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants