Commit eea8ff2
Fix torch.full with dynamic tensor fill_value in torch.compile (pytorch#166554)
Fixes pytorch#166253
## Summary
When `torch.full` is called with a 0-D tensor as `fill_value` inside a `torch.compile`'d function, the value was being incorrectly cached, causing subsequent calls with different values to return the first value.
## Root Cause
The Dynamo handler for `torch.full` was calling `aten._local_scalar_dense` to convert tensor fill_values to Python scalars at compile time, which baked the value into the compiled graph as a constant.
## Solution
Modified the Dynamo handler to decompose `torch.full(size, tensor_fill_value)` into `empty(size).fill_(tensor_fill_value)` when `fill_value` is a `TensorVariable`, keeping the fill value dynamic in the compiled graph.
## Testing
Added test case that verifies torch.full works correctly with dynamic tensor fill_values across multiple calls and dtypes.
Pull Request resolved: pytorch#166554
Approved by: https://github.com/Lucaskabela1 parent 11f73d7 commit eea8ff2
File tree
2 files changed
+63
-5
lines changed- test/dynamo
- torch/_dynamo/variables
2 files changed
+63
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5241 | 5241 | | |
5242 | 5242 | | |
5243 | 5243 | | |
| 5244 | + | |
| 5245 | + | |
| 5246 | + | |
| 5247 | + | |
| 5248 | + | |
| 5249 | + | |
| 5250 | + | |
| 5251 | + | |
| 5252 | + | |
| 5253 | + | |
| 5254 | + | |
| 5255 | + | |
| 5256 | + | |
| 5257 | + | |
| 5258 | + | |
| 5259 | + | |
| 5260 | + | |
| 5261 | + | |
| 5262 | + | |
| 5263 | + | |
| 5264 | + | |
| 5265 | + | |
| 5266 | + | |
| 5267 | + | |
| 5268 | + | |
| 5269 | + | |
| 5270 | + | |
| 5271 | + | |
| 5272 | + | |
| 5273 | + | |
| 5274 | + | |
| 5275 | + | |
| 5276 | + | |
| 5277 | + | |
| 5278 | + | |
| 5279 | + | |
| 5280 | + | |
| 5281 | + | |
| 5282 | + | |
| 5283 | + | |
| 5284 | + | |
| 5285 | + | |
| 5286 | + | |
| 5287 | + | |
| 5288 | + | |
| 5289 | + | |
| 5290 | + | |
| 5291 | + | |
| 5292 | + | |
| 5293 | + | |
| 5294 | + | |
| 5295 | + | |
| 5296 | + | |
| 5297 | + | |
| 5298 | + | |
| 5299 | + | |
| 5300 | + | |
5244 | 5301 | | |
5245 | 5302 | | |
5246 | 5303 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
834 | 834 | | |
835 | 835 | | |
836 | 836 | | |
837 | | - | |
838 | | - | |
839 | | - | |
840 | | - | |
841 | | - | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
842 | 841 | | |
| 842 | + | |
| 843 | + | |
843 | 844 | | |
844 | 845 | | |
845 | 846 | | |
| |||
0 commit comments