Commit 34e6dc4
authored
Fix
* Fix run_with_cache(device=...) permanently moving the model
The single-device branch moved the model and inputs to cache_device
with no restore, leaving non-CPU models silently migrated and
cfg.device stale. The move was redundant since make_cache_hook already
offloads each captured activation, matching ActivationCache.to and the
legacy get_caching_hooks contract.
Flatten the conditional, add a regression test asserting
original_model.to is not invoked, and document the device kwarg.
* Retire cache_dict workaround in return_cache device offload
With the run_with_cache model-move fixed, TransformerBridge.generate
return_cache device offload can use a run_with_cache(device=device)
passthrough. The offload now happens at capture time, reducing peak
memory. Drop the cache_dict direct-write and its justifying comment,
simplify the offload test to a device-landing check.run_with_cache(device=...) permanently moving the model (#1345)1 parent 84e90e1 commit 34e6dc4
3 files changed
Lines changed: 64 additions & 44 deletions
File tree
- tests/integration/model_bridge
- transformer_lens/model_bridge
Lines changed: 12 additions & 19 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | 13 | | |
16 | 14 | | |
17 | 15 | | |
| |||
149 | 147 | | |
150 | 148 | | |
151 | 149 | | |
152 | | - | |
153 | | - | |
| 150 | + | |
| 151 | + | |
154 | 152 | | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
167 | 163 | | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | 164 | | |
172 | 165 | | |
173 | 166 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1968 | 1968 | | |
1969 | 1969 | | |
1970 | 1970 | | |
| 1971 | + | |
| 1972 | + | |
1971 | 1973 | | |
1972 | 1974 | | |
1973 | 1975 | | |
| |||
2075 | 2077 | | |
2076 | 2078 | | |
2077 | 2079 | | |
2078 | | - | |
2079 | | - | |
2080 | | - | |
2081 | | - | |
2082 | | - | |
2083 | | - | |
2084 | | - | |
2085 | | - | |
2086 | | - | |
2087 | | - | |
2088 | | - | |
2089 | | - | |
2090 | | - | |
2091 | | - | |
2092 | | - | |
2093 | | - | |
2094 | | - | |
2095 | | - | |
2096 | | - | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
| 2087 | + | |
| 2088 | + | |
| 2089 | + | |
| 2090 | + | |
| 2091 | + | |
| 2092 | + | |
2097 | 2093 | | |
2098 | 2094 | | |
2099 | 2095 | | |
| |||
2858 | 2854 | | |
2859 | 2855 | | |
2860 | 2856 | | |
2861 | | - | |
2862 | | - | |
2863 | | - | |
2864 | | - | |
2865 | | - | |
2866 | | - | |
| 2857 | + | |
2867 | 2858 | | |
2868 | 2859 | | |
2869 | 2860 | | |
| |||
0 commit comments