Skip to content

[SOT] Add dynamic shape test when UNSAFE_CACHE_FASTPATH=1 #73519

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 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def lookup(
try:
with EventGuard("try guard"):
guard_result = guard_fn(frame)
if enable_strict_guard:
if enable_strict_guard and (not enable_unsafe_cache_fastpath):
assert mirror_guard_result == guard_result, (
"faster guard result is not equal to guard result, "
f"guard_expr: {getattr(guard_fn, 'expr', 'None')} \n"
Expand All @@ -253,10 +253,11 @@ def lookup(
2,
f"[Cache] Cache hit, Guard is \n{getattr(guard_fn, 'expr', 'None')}\n",
)
# TODO(zrr1999): cache_index should be equal to index when enable_strict_guard.
assert (
cache_index is None or index == cache_index
), f"cache_index({cache_index}) is not equal to index({index})"
if not enable_unsafe_cache_fastpath:
# TODO(zrr1999): cache_index should be equal to index when enable_strict_guard.
assert (
cache_index is None or index == cache_index
), f"cache_index({cache_index}) is not equal to index({index})"

if enable_unsafe_cache_fastpath:
if index == 0:
Expand Down Expand Up @@ -296,7 +297,7 @@ def lookup(
2,
self.analyse_guard_error(guard_fn, frame),
)
if enable_strict_guard:
if enable_strict_guard and (not enable_unsafe_cache_fastpath):
assert type(e) == type(mirror_guard_error) and str(
e
) == str(mirror_guard_error), (
Expand Down
14 changes: 13 additions & 1 deletion test/sot/test_guard_fastpath_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,25 @@ def test_guard(self):
add.__code__
)
)
for _ in range(33):
# The test needs to consider the issue of dynamic shapes: when the input shape changes,
# the previous cache may become invalid.
self.assert_results(add, 1, paddle.ones([32, 4]))
for _ in range(34):
self.assert_results(add, 1, paddle.ones([4]))
self.assertTrue(
OpcodeExecutorCache().is_fastpath_threshold_reached(
add.__code__
)
)
# NOTE: Once fastpath is enabled, the cache will not be rebuilt even if the shape changes again afterwards.
# This is the "UNSAFE" aspect of the environment variable `ENV_SOT_UNSAFE_CACHE_FASTPATH`.
self.assert_results(add, 1, paddle.ones([31, 4]))
self.assertTrue(
OpcodeExecutorCache().is_fastpath_threshold_reached(
add.__code__
)
)

self.assertFalse(
OpcodeExecutorCache().is_fastpath_threshold_reached(
subtract.__code__
Expand Down
Loading