Commit 896bb1c
authored
Fix meshgrid converter to handle non-1D inputs (apple#2665)
The meshgrid op converter raises ValueError when inputs have rank > 1.
This happens when converting models that use torch.linspace(...) / scalar
before torch.meshgrid(), because the MIL real_div op can broadcast the
1D linspace result with a 0D scalar divisor to produce a higher-rank tensor.
This pattern is common in deformable attention modules (DINO,
Deformable-DETR, RF-DETR) where coordinate grids are created via:
grid_y = torch.linspace(0.5, h - 0.5, steps=h) / h
grid_x = torch.linspace(0.5, w - 0.5, steps=w) / w
grid_y, grid_x = torch.meshgrid(grid_y, grid_x, indexing='ij')
Instead of rejecting non-1D inputs, flatten them to 1D with
mb.reshape(shape=[-1]) before meshgrid processing.1 parent 01eedb0 commit 896bb1c
2 files changed
Lines changed: 65 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6457 | 6457 | | |
6458 | 6458 | | |
6459 | 6459 | | |
6460 | | - | |
6461 | | - | |
6462 | 6460 | | |
6463 | 6461 | | |
6464 | 6462 | | |
6465 | 6463 | | |
| 6464 | + | |
| 6465 | + | |
| 6466 | + | |
| 6467 | + | |
| 6468 | + | |
| 6469 | + | |
| 6470 | + | |
| 6471 | + | |
| 6472 | + | |
| 6473 | + | |
| 6474 | + | |
| 6475 | + | |
| 6476 | + | |
| 6477 | + | |
| 6478 | + | |
| 6479 | + | |
6466 | 6480 | | |
6467 | 6481 | | |
6468 | 6482 | | |
| 6483 | + | |
6469 | 6484 | | |
6470 | 6485 | | |
6471 | 6486 | | |
| |||
Lines changed: 48 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11312 | 11312 | | |
11313 | 11313 | | |
11314 | 11314 | | |
| 11315 | + | |
| 11316 | + | |
| 11317 | + | |
| 11318 | + | |
| 11319 | + | |
| 11320 | + | |
| 11321 | + | |
| 11322 | + | |
| 11323 | + | |
| 11324 | + | |
| 11325 | + | |
| 11326 | + | |
| 11327 | + | |
| 11328 | + | |
| 11329 | + | |
| 11330 | + | |
| 11331 | + | |
| 11332 | + | |
| 11333 | + | |
| 11334 | + | |
| 11335 | + | |
| 11336 | + | |
| 11337 | + | |
| 11338 | + | |
| 11339 | + | |
| 11340 | + | |
| 11341 | + | |
| 11342 | + | |
| 11343 | + | |
| 11344 | + | |
| 11345 | + | |
| 11346 | + | |
| 11347 | + | |
| 11348 | + | |
| 11349 | + | |
| 11350 | + | |
| 11351 | + | |
| 11352 | + | |
| 11353 | + | |
| 11354 | + | |
| 11355 | + | |
| 11356 | + | |
| 11357 | + | |
| 11358 | + | |
| 11359 | + | |
| 11360 | + | |
| 11361 | + | |
| 11362 | + | |
11315 | 11363 | | |
11316 | 11364 | | |
11317 | 11365 | | |
| |||
0 commit comments