Repository navigation
[no-ci] [dynamo] Let an explicit package's recompile_limit lift the accumulated cap - #198091
Closed
bobrenjc93 wants to merge 4 commits into
Closed
bobrenjc93 wants to merge 4 commits into
bobrenjc93 wants to merge 4 commits into
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198091
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Sep 22, 2026
Closed
Closed
Closed
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
Contributor
Author
|
Abandoning this stack for now; it may be reopened later. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack from ghstack (oldest at bottom):
Problem. An explicit capture is a caller asking Dynamo to record up to N variants of a frame into a
CompilePackage, and the per-regionrecompile_limitpassed totorch._dynamo.optimizeis how it states N. Butexceeds_recompile_limitin cache_size.py applies two caps, not one: besides the per-region limit it stops compiling once the code object's total entry count across all regions, or the frame'sframe_compile_id, reachesconfig.accumulated_recompile_limit. That second cap is a process-wide safety net against runaway recompilation in ordinarytorch.compile, and it knows nothing about the capture. When it is lower than the requested N (a test or a deployment that pins it low, or a large capture on the default of 256), the capture silently stops short, the package records fewer variants than asked for, and nothing tells the caller that its own budget was never the binding one.Fix.
ConvertFrameAssert.__call__already wraps the compile of a frame inconfig.patch(recompile_limit=...)when a per-region limit was given. This commit extends that patch, for an explicit package only, to also setaccumulated_recompile_limitto the larger of the ambient value and the requested limit. The patch is the same context manager around the same_compilecall, so it covers both accumulated checks inexceeds_recompile_limit(the total-entry count and theframe_compile_idcheck), lasts only for the compile of that frame, and never lowers the cap. A package that is not an explicit capture, or an explicit capture with norecompile_limit, is unaffected: theaccumulated_recompile_limitvalue written into the patch is the ambient one.Summary. The design point is that the two limits mean different things:
recompile_limitis a per-frame budget the user chose, while the accumulated cap is a global guard for code the user did not annotate, so only a caller that has opted in (an explicit capture that names its budget) should be able to move it, and only for its own compiles. Usingmaxrather than replacing the value keeps a deliberately high ambient cap in force, and keeping the lift inside the existing per-frameconfig.patchmeans a plaintorch.compileframe in the same process, or the same package's compile without a limit, still sees the ambient cap. The alternative from the source PR of also subtracting the explicit region's own entries from the per-code total was left out: main'sexceeds_recompile_limitcomparesframe_compile_idagainst the same cap, so a lower total alone would never let another variant through, and the region registry it relied on does not exist on main. A frame that still hits a limit is not bypassed and keeps the variants it captured; commit 10 above records which frame that was on the package. Nothing changes fortorch.compilewithout a package or for a serving package. Carved out of #195913.An explicit capture's budget beats a lower accumulated cap
The same script with a non-explicit
CompilePackage(fn)andrecompile_limit=2, or with an explicit package and norecompile_limit, compiles once under a cap of 1: neither path has opted in to lifting it.test_explicit_package_recompile_limit_lifts_the_accumulated_capin test/dynamo/test_package.py pins the plain-compiles-once and explicit-compiles-twice claims together with the two recorded guarded codes.Test Plan:
The new test fails on the parent (the explicit capture stops at one variant) and passes here.
Authored with an AI assistant.
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