Skip to content

[Bug] Fix torch dynamo warning Dynamo detected a call to a functools.lru_cache#29038

Merged
youkaichao merged 3 commits intomainfrom
wentao-fix-torch-dynamo-warning
Nov 20, 2025
Merged

[Bug] Fix torch dynamo warning Dynamo detected a call to a functools.lru_cache#29038
youkaichao merged 3 commits intomainfrom
wentao-fix-torch-dynamo-warning

Conversation

@yewentao256
Copy link
Copy Markdown
Member

@yewentao256 yewentao256 commented Nov 19, 2025

Purpose

(EngineCore_DP0 pid=2798273) /home/wentao/.venv/lib/python3.12/site-packages/torch/_dynamo/variables/functions.py:1692: UserWarning: Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.
(EngineCore_DP0 pid=2798273)   torch._dynamo.utils.warn_once(msg)
(EngineCore_DP1 pid=2798274) /home/wentao/.venv/lib/python3.12/site-packages/torch/_dynamo/variables/functions.py:1692: UserWarning: Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.
(EngineCore_DP1 pid=2798274)   torch._dynamo.utils.warn_once(msg)
(EngineCore_DP6 pid=2798279) /home/wentao/.venv/lib/python3.12/site-packages/torch/_dynamo/variables/functions.py:1692: UserWarning: Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.
(EngineCore_DP6 pid=2798279)   torch._dynamo.utils.warn_once(msg)
(EngineCore_DP2 pid=2798275) /home/wentao/.venv/lib/python3.12/site-packages/torch/_dynamo/variables/functions.py:1692: UserWarning: Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.
(EngineCore_DP2 pid=2798275)   torch._dynamo.utils.warn_once(msg)
(EngineCore_DP3 pid=2798276) /home/wentao/.venv/lib/python3.12/site-packages/torch/_dynamo/variables/functions.py:1692: UserWarning: Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.
(EngineCore_DP3 pid=2798276)   torch._dynamo.utils.warn_once(msg)
(EngineCore_DP7 pid=2798280) /home/wentao/.venv/lib/python3.12/site-packages/torch/_dynamo/variables/functions.py:1692: UserWarning: Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.
(EngineCore_DP7 pid=2798280)   torch._dynamo.utils.warn_once(msg)
(EngineCore_DP5 pid=2798278) /home/wentao/.venv/lib/python3.12/site-packages/torch/_dynamo/variables/functions.py:1692: UserWarning: Dynamo detected a call to a `functools.lru_cache`-wrapped function. Dynamo ignores the cache wrapper and directly traces the wrapped function. Silent incorrectness is only a *potential* risk, not something we have observed. Enable TORCH_LOGS="+dynamo" for a DEBUG stack trace.

The warning is from @cache in batch invariant variable, this PR fixes that

Test

All batch invariant unit tests pass

Signed-off-by: yewentao256 <zhyanwentao@126.com>
@mergify mergify bot added the v1 label Nov 19, 2025
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request successfully resolves a torch.dynamo warning by replacing a functools.cache decorator with a module-level variable. While this fixes the warning, the changes to the test suite to accommodate this are not ideal. Specifically, the modification in conftest.py introduces a global side effect by setting an environment variable at the module level, which breaks test isolation. I've provided a critical suggestion to revert to a pytest fixture, using monkeypatch.setattr to ensure test isolation and proper setup/teardown. A related high-severity suggestion is made in test_batch_invariance.py to align with this improved testing pattern, making the test cleaner and more robust.

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Signed-off-by: yewentao256 <zhyanwentao@126.com>
@ZJY0516
Copy link
Copy Markdown
Member

ZJY0516 commented Nov 20, 2025

cc @zou3519 and link #28867

@yewentao256 yewentao256 added the ready ONLY add when PR is ready to merge/full CI is needed label Nov 20, 2025
Copy link
Copy Markdown
Member

@youkaichao youkaichao left a comment

Choose a reason for hiding this comment

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

thanks for the fix!

@youkaichao youkaichao merged commit 2c52c7f into main Nov 20, 2025
48 checks passed
@youkaichao youkaichao deleted the wentao-fix-torch-dynamo-warning branch November 20, 2025 08:52
@zou3519
Copy link
Copy Markdown
Collaborator

zou3519 commented Nov 20, 2025

Nice, thanks for fixing this.

lpapavassiliou pushed a commit to lpapavassiliou/vllm that referenced this pull request Nov 24, 2025
….lru_cache` (vllm-project#29038)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
RunkaiTao pushed a commit to RunkaiTao/vllm that referenced this pull request Nov 24, 2025
….lru_cache` (vllm-project#29038)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
Signed-off-by: Runkai Tao <rt572@physics.rutgers.edu>
devpatelio pushed a commit to SumanthRH/vllm that referenced this pull request Nov 29, 2025
….lru_cache` (vllm-project#29038)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
kitaekatt pushed a commit to kitaekatt/vllm that referenced this pull request Dec 1, 2025
….lru_cache` (vllm-project#29038)

Signed-off-by: yewentao256 <zhyanwentao@126.com>
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 v1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants