Repository navigation
[dynamo] Raise a typed, guard-naming error when package guard serialization fails - #195287
bobrenjc93 wants to merge 15 commits into
Conversation
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
…zation fails
When a guard cannot be serialized into a compile package, the failure surface
was untyped in both directions: serialize_guards raised a bare PackageError
whose message named only the guard TYPE, and on the non-strict path the
CheckFunctionManager swallowed it entirely, leaving guards_state None so
convert_frame raised a bare AssertionError("check_fn.guards_state must not
be None"). Consumers that need to react to serialization failures
(torch.compiler.precompile does today) were left string-matching that
assertion message to distinguish it from every other AssertionError.
serialize_guards now raises GuardSerializationError (a PackageError subclass
carrying guard_type and the guard's source name, with a message-compatible
rendering so existing matchers keep working); the non-strict
CheckFunctionManager records the swallowed error as
guards_serialization_failure; and convert_frame raises a typed PackageError
CHAINED to that cause instead of the bare AssertionError (aot_compile's
sibling assertion is converted the same way for consistency). Consumers can
now catch PackageError and inspect __cause__ for the exact guard instead of
parsing message text.
The stored exception is traceback-stripped (its whole cause/context chain)
before being recorded: a live __traceback__ would pin the guard-build frames
-- the GuardBuilder holding the user frame's scopes, the OutputGraph -- on
the long-lived CheckFunctionManager, defeating the deliberate anti-leak
cleanup at the end of __init__ and leaking one build's state per suppressed
failure in a long-running job. The formatted traceback that bypass_package
logs is captured before stripping, and a test pins __traceback__ is None on
the chained cause.
Authored with an AI assistant.
Test Plan:
```
python test/dynamo/test_guard_serialization.py # 61 tests, OK (1 skipped; 1 new, 1 extended)
python test/dynamo/test_aot_compile.py # 42 tests, OK
python test/dynamo/test_package.py # 64 tests, OK (23 skipped, 1 expected failure)
lintrunner <touched files> # ok
```
Co-Authored-By: Claude Fable 5 <[email protected]>
ghstack-source-id: d12a9d2
Pull-Request: #195287
…zation fails
When a guard cannot be serialized into a compile package, the failure surface
was untyped in both directions: serialize_guards raised a bare PackageError
whose message named only the guard TYPE, and on the non-strict path the
CheckFunctionManager swallowed it entirely, leaving guards_state None so
convert_frame raised a bare AssertionError("check_fn.guards_state must not
be None"). Consumers that need to react to serialization failures
(torch.compiler.precompile does today) were left string-matching that
assertion message to distinguish it from every other AssertionError.
serialize_guards now raises GuardSerializationError (a PackageError subclass
carrying guard_type and the guard's source name, with a message-compatible
rendering so existing matchers keep working); the non-strict
CheckFunctionManager records the swallowed error as
guards_serialization_failure; and convert_frame raises a typed PackageError
CHAINED to that cause instead of the bare AssertionError (aot_compile's
sibling assertion is converted the same way for consistency). Consumers can
now catch PackageError and inspect __cause__ for the exact guard instead of
parsing message text.
The stored exception is traceback-stripped (its whole cause/context chain)
before being recorded: a live __traceback__ would pin the guard-build frames
-- the GuardBuilder holding the user frame's scopes, the OutputGraph -- on
the long-lived CheckFunctionManager, defeating the deliberate anti-leak
cleanup at the end of __init__ and leaking one build's state per suppressed
failure in a long-running job. The formatted traceback that bypass_package
logs is captured before stripping, and a test pins __traceback__ is None on
the chained cause.
Authored with an AI assistant.
Test Plan:
```
python test/dynamo/test_guard_serialization.py # 61 tests, OK (1 skipped; 1 new, 1 extended)
python test/dynamo/test_aot_compile.py # 42 tests, OK
python test/dynamo/test_package.py # 64 tests, OK (23 skipped, 1 expected failure)
lintrunner <touched files> # ok
```
Co-Authored-By: Claude Fable 5 <[email protected]>
ghstack-source-id: d12a9d2
Pull-Request: #195287
|
Claude finished @bobrenjc93's task in 53s —— View job The typed-error direction is reasonable, but the PR is justified by a consumer that does not exist ( Full reviewPR Review: #195287SummaryIntroduces Code Quality
API Design
Backward Compatibility
Testing
RecommendationRequest Changes Blocking: the |
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
|
@pytorchbot label "release notes: dynamo" |
Stack from ghstack (oldest at bottom):
When a guard cannot be serialized into a compile package, the failure surface
was untyped in both directions: serialize_guards raised a bare PackageError
whose message named only the guard TYPE, and on the non-strict path the
CheckFunctionManager swallowed it entirely, leaving guards_state None so
convert_frame raised a bare AssertionError("check_fn.guards_state must not be
None"). A consumer that reacts to serialization failures (the precompile
consumer added later in this stack) could then only distinguish that failure
from any other AssertionError by matching the message text.
serialize_guards now raises GuardSerializationError (a PackageError subclass
carrying guard_type and the guard's source name, with a message-compatible
rendering so existing matchers keep working); the non-strict CheckFunctionManager
records the swallowed error as guards_serialization_failure; and convert_frame
raises a typed PackageError CHAINED to that cause instead of the bare
AssertionError. Consumers can now catch PackageError and inspect cause for
the exact guard instead of parsing message text. aot_compile builds guards with
strict_error=True, so a serialization failure raises there directly and its
guards_state-None assertion stays a plain defensive AssertionError (there is no
swallowed cause to chain to).
Two failure modes that previously escaped the typed surface (and therefore also
skipped the non-strict swallow, surfacing as InternalTorchDynamoError) are
closed: the unserializable TYPE_MATCH/BUILTIN_MATCH branch (a class defined in
local scope) raised a bare TypeError and now raises GuardSerializationError with
the same actionable message, and pickle_guards_state converted only
AttributeError, so a TypeError or PicklingError from an unpicklable guarded
value (e.g. a threading.Lock) propagated raw; the except is broadened to cover
them (still chaining the original error as cause). Both paths are pinned by
non-strict package tests asserting the typed chain.
The stored exception is traceback-stripped before being recorded: the walk
follows cause only (every link we own is chained with
raise ... from, andcontext may belong to an exception the caller is handling), guarded against
a cyclic explicit-cause chain. A live traceback
would pin the guard-build frames -- the GuardBuilder holding the user frame's
scopes, the OutputGraph -- on the long-lived CheckFunctionManager, defeating the
deliberate anti-leak cleanup at the end of init and leaking one build's
state per suppressed failure in a long-running job. The formatted traceback that
bypass_package logs is captured before stripping, and a test pins traceback
is None on the chained cause.
Authored with an AI assistant.
Test Plan:
Design note on the non-strict path. When guard serialization fails with
strict_precompile off, CheckFunctionManager records the failure and marks the
package entry bypassed, and convert_frame then raises a typed PackageError
chained to the specific guard. Continuing to compile without the package entry
was considered instead: the bypass machinery (bypass_package,
CompilePackage.bypass_current_entry) suggests it, but this frame has always
hard-failed here (upstream raised a bare AssertionError), and package consumers
(torch.compiler.precompile in particular) rely on a raise they can classify.
Raising typed is the conservative choice; honoring the bypass end to end is a
separate change.
The SymInt reducer now raises PackageError rather than RuntimeError so every
serialization failure in the pickler is typed uniformly, and the up-front check
tests the guard's unserializable flag regardless of its own type, since
BUILTIN_MATCH, SEQUENCE_LENGTH, export-mode TENSOR_MATCH and
FAKE_SCRIPT_TYPE_MATCH all set it (the first three by running TYPE_MATCH on the
same guard), so a local-scope sequence type or fake script type is reported as
a GuardSerializationError too, even when a guard filter has dropped the sibling
TYPE_MATCH guard. The three TYPE_MATCH-family guard types stay exempt from the
derived-type check because BUILTIN_MATCH derives an ID_MATCH on the
builtins-dict entry, which serializes. On the non-strict path
the recorded exception chain has its frames released (walking cause only,
so an unrelated in-flight exception's traceback is never touched) and the
formatted traceback is attached as an exception note on Python 3.11+.
Co-Authored-By: Claude Fable 5.1 [email protected]
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @chauhang @amjames @jataylo @azahed98