[dynamo][precompile] Prune only the guarded codes that name a missing backend when writing a cache entry
- Dominant language
- Python
- Stars
- 103k
- Forks
- 29.5k
- PR merge metrics
- PR metrics pending
Description
Follow-up to https://github.com/pytorch/pytorch/pull/196756.
Today `PrecompileCacheEntry.from_cache_entry` flags a whole `_DynamoCodeCacheEntry` as bypassed as soon as ONE of its backend artifacts is missing at save time, and (since #196756) `CompilePackage.initialize` loads such an entry without its stale guarded codes and backend ids so the entry stops growing and the next save is installable.
That discards every compiled variant of the code object, although only the variants whose bytecode names the missing backend were unusable. A narrower fix is a per-guarded-code prune at write time: for each guarded code, run `_backend_ids_from_code(SerializedCode.to_code_object(gc.dynamo_code))` and drop only the ones that hit a missing id, keeping the entry installable for the other variants and never writing the stale bytes to disk.
Tracking issue so the load-side reset in #196756 does not become the permanent answer.
cc @chauhang @penguinwu @voznesenskym @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @kadeng @amjames @jataylo @azahed98
Contributor guide
Research direction
Start by reading PrecompileCacheEntry.from_cache_entry and CompilePackage.initialize, then trace _backend_ids_from_code and SerializedCode.to_code_object. Compare the load-side change in PR #196756 with the write path. Done means only guarded codes that name missing backend IDs are pruned, while other compiled variants remain installable and stale bytes are not written.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100