Commit c9bd9ca
committed
[Relax][Frontend][TFLite] Support dynamic RANGE scalar bounds
Previously convert_range raised OpNotImplemented when start/limit/delta
were runtime (non-constant) scalar tensors, so any TFLite model that
computes RANGE bounds at runtime failed to import. This was one of the
"partial implementation" items tracked in #19412.
relax.op.arange only takes compile-time PrimExpr bounds, and its struct-info
length formula (InferTypeArange) has no negative-step branch, so feeding
symbolic bounds straight in would mis-declare descending ranges. Instead,
compute the element count in-graph and lift it to one symbolic output
dimension via relax.op.tensor_to_shape + match_cast (the bridge already used
by _get_shape_expr_from_tensor), so the declared and runtime lengths match by
construction. Values are rebuilt as arange(0, count) * delta + start. One
unified path covers both dtypes:
- int: count = -floor_divide(start - limit, delta), exact and sign-agnostic
(no float-precision loss), equal to ceil((limit - start) / delta);
- float: count = ceil((limit - start) / delta).
No new Relax op is needed.
Replace the "not supported" test with a compile-and-run test covering
ascending/descending integer and float dynamic bounds.1 parent 15f62fe commit c9bd9ca
2 files changed
Lines changed: 110 additions & 31 deletions
File tree
- python/tvm/relax/frontend/tflite
- tests/python/relax
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1532 | 1532 | | |
1533 | 1533 | | |
1534 | 1534 | | |
1535 | | - | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
1536 | 1542 | | |
1537 | 1543 | | |
1538 | 1544 | | |
| |||
1541 | 1547 | | |
1542 | 1548 | | |
1543 | 1549 | | |
1544 | | - | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
1545 | 1562 | | |
1546 | | - | |
1547 | | - | |
1548 | | - | |
1549 | | - | |
1550 | | - | |
1551 | | - | |
1552 | | - | |
1553 | | - | |
1554 | | - | |
1555 | | - | |
| 1563 | + | |
1556 | 1564 | | |
1557 | 1565 | | |
1558 | | - | |
1559 | 1566 | | |
1560 | 1567 | | |
1561 | 1568 | | |
1562 | 1569 | | |
1563 | | - | |
1564 | | - | |
1565 | | - | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
1566 | 1576 | | |
1567 | | - | |
1568 | | - | |
1569 | | - | |
1570 | | - | |
1571 | | - | |
| 1577 | + | |
| 1578 | + | |
1572 | 1579 | | |
1573 | | - | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
1574 | 1606 | | |
1575 | | - | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
1576 | 1630 | | |
1577 | 1631 | | |
1578 | 1632 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
717 | 717 | | |
718 | 718 | | |
719 | 719 | | |
720 | | - | |
721 | | - | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
722 | 731 | | |
723 | 732 | | |
724 | 733 | | |
725 | 734 | | |
726 | | - | |
727 | | - | |
728 | | - | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
729 | 738 | | |
730 | 739 | | |
731 | 740 | | |
732 | | - | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
733 | 758 | | |
734 | | - | |
735 | | - | |
| 759 | + | |
| 760 | + | |
736 | 761 | | |
737 | 762 | | |
738 | 763 | | |
| |||
0 commit comments