Commit 9c7de8a
authored
Stack from [ghstack](https://github.com/ezyang/ghstack) (oldest at
bottom):
* #883
* #882
* __->__ #881
The torchscript ONNX graph generator creates numeric value names by
default (`0`, `1`). These are not legal ONNX tensor names, since ONNX
requires the names to be valid C variable names. This change updates the
names by prepending a prefix `_val_` or `_const_` to make them valid
ONNX names. It also improves readability by making the names less likely
to be confused with shape values.
I decided to use the `_` prefix to reduce the chance of name collision
with FX names.
After:
```
<
ir_version: 8,
opset_import: ["" : 18],
producer_name: "pytorch",
producer_version: "2.1.0"
>
torch_jit (float[5,5,5,5] input_0, int64[2] input_1_3) => (float[5,5,5,2] _val_10) {
_val_2 = Transpose <perm = [0, 1, 2, 3]> (input_0)
_val_3 = Max (input_1_3)
_val_4 = Shape <start = 0> (_val_3)
_val_5 = Expand (input_1_3, _val_4)
_const_6 = Constant <value = int64 {-1}> ()
_val_7 = Unsqueeze (_val_5, _const_6)
_val_8 = Concat <axis = -1> (_val_7)
_val_9 = GatherND <batch_dims = 0> (_val_2, _val_8)
_val_10 = Transpose <perm = [0, 1, 2, 3]> (_val_9)
}
```
Before:
```
<
ir_version: 8,
opset_import: ["" : 18],
producer_name: "pytorch",
producer_version: "2.1.0"
>
torch_jit (float[5,5,5,5] input_0, int64[2] input_1_3) => (float[5,5,5,2] 10) {
2 = Transpose <perm = [0, 1, 2, 3]> (input_0)
3 = Max (input_1_3)
4 = Shape <start = 0> (3)
5 = Expand (input_1_3, 4)
6 = Constant <value = int64 {-1}> ()
7 = Unsqueeze (5, 6)
8 = Concat <axis = -1> (7)
9 = GatherND <batch_dims = 0> (2, 8)
10 = Transpose <perm = [0, 1, 2, 3]> (9)
}
```
1 parent 06a0a5c commit 9c7de8a
1 file changed
Lines changed: 25 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
79 | 91 | | |
80 | 92 | | |
81 | 93 | | |
| |||
454 | 466 | | |
455 | 467 | | |
456 | 468 | | |
| 469 | + | |
457 | 470 | | |
458 | 471 | | |
459 | 472 | | |
| |||
475 | 488 | | |
476 | 489 | | |
477 | 490 | | |
478 | | - | |
| 491 | + | |
479 | 492 | | |
480 | 493 | | |
481 | 494 | | |
482 | 495 | | |
483 | 496 | | |
| 497 | + | |
| 498 | + | |
484 | 499 | | |
485 | 500 | | |
486 | 501 | | |
| |||
524 | 539 | | |
525 | 540 | | |
526 | 541 | | |
527 | | - | |
528 | | - | |
529 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
530 | 551 | | |
531 | 552 | | |
532 | 553 | | |
| |||
0 commit comments