Commit be9b80c
authored
Prevent packed weight cache file from growing on reload (pytorch#20833)
Summary:
On each NGTTS model reload, the cache file grew by ~24KB and the
timestamp updated, even though all named entries were cache hits. Three
independent causes:
1. Unnamed constants (not registered in `NamedDataMap`) always miss
`look_up` and go through `reserve_space` file-backed path, extending the
file with data that can never be found by name on subsequent loads.
2. After `load_packed_cache`, `mmap_regions_synced_` was 0 while
`mmap_regions_` was 1, causing `finalize_for_runtime` to msync the
read-only loaded region on every reload — updating the file mtime.
3. XNNPACK internally re-packs certain weights (e.g., for different
runtime contexts) by calling `reserve_space` without going through
`look_up` first. On a warm cache this extends the file with data already
present in the loaded cache.
Fix:
- `last_lookup_unnamed_`: set in `look_up` when the kernel pointer is
not in the name map. `reserve_space` checks this flag and routes to
heap.
- `mmap_regions_synced_`: initialized in `load_packed_cache` to match
`mmap_regions_.size()`, preventing spurious msync on loaded regions.
- `loaded_from_disk_`: set after `load_packed_cache` succeeds.
`reserve_space` routes to heap when the cache is warm — all named
entries are already in the file, so any new `reserve_space` call is a
re-pack that does not need to persist.
Differential Revision: D1113543751 parent 3d9936e commit be9b80c
2 files changed
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
| 343 | + | |
343 | 344 | | |
344 | 345 | | |
| 346 | + | |
345 | 347 | | |
346 | 348 | | |
347 | 349 | | |
| |||
375 | 377 | | |
376 | 378 | | |
377 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
378 | 383 | | |
379 | 384 | | |
380 | 385 | | |
| |||
753 | 758 | | |
754 | 759 | | |
755 | 760 | | |
| 761 | + | |
| 762 | + | |
756 | 763 | | |
757 | 764 | | |
758 | 765 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
226 | 239 | | |
227 | 240 | | |
228 | 241 | | |
| |||
0 commit comments