Commit 57716e4
committed
fix(pi07): emit obs_history_is_pad at inference; address review nits
Follow-up to the review on PR #253.
Main change — emit obs_history_is_pad from _build_history_batch.
Previously the inference path never threaded the mask through
select_action -> sample_actions -> embed_prefix, so the encoder fell
back to "all history padded except current" via embed_prefix's
zeros + state_mask[:, -1] = True branch and the encoder's matching
None-fallback. That fixed the start-of-episode contamination but
silently masked genuine mid-episode history once the buffer filled.
_build_history_batch already owns the idx < 0 decision for each slot;
emitting obs_history_is_pad = (i*interval - missing < 0) for i in
range(n_hist) costs nothing and lets the encoder use real
mid-episode history while still masking only the truly-padded
start-of-episode slots. Threaded through PI07LowLevelPolicy.
sample_actions and PI07LowLevelFlowMatching.sample_actions to reach
embed_prefix with the live mask.
The encoder's None-fallback and embed_prefix's zeros-then-current
branch are both kept as defensive: anything that bypasses
_build_history_batch (direct sample_actions calls in tests, etc.)
still gets a safe default that matches training-time augmentations.
Nits from review:
- Removed redundant .clone() in embed_prefix's state_mask path and in
_build_temporal_attn_mask's key_valid path. Both ~obs_history_is_pad
expressions already allocate fresh tensors, so subsequent
[:, -1] = True writes can't reach the caller's obs_history_is_pad.
Kept the regression tests that pinned the no-mutation property.
- Rewrote the SpaceTimeEncoderLayerWrapper.forward docstring to drop
the misleading "ignored by vanilla layers via SiglipEncoder's
positional dispatch" claim — the encoder now branches on isinstance
and never calls SiglipEncoder.forward, so vanilla layers simply
aren't passed temporal_attn_mask.
Skipped the repeat_interleave perf nit: the suggested expand+reshape
materializes anyway because SDPA flattens (B, N) into one dim. Real
fix is a deeper refactor of the temporal Q/K/V layout; deferred.
New tests in TestBuildHistoryBatchEmitsObsHistoryIsPad
(test_pi07_cpu.py) — pin the (B, T) mask shape, the first-step
all-but-current pattern, the buffer-full all-False pattern, the
partial-fill mid-episode pattern, batch broadcasting, and slot-by-slot
agreement with the actual zero-fill of state and camera tensors.1 parent 9e702dd commit 57716e4
3 files changed
Lines changed: 183 additions & 10 deletions
File tree
- src/opentau/policies/pi07/low_level
- tests/policies
Lines changed: 46 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
430 | 430 | | |
431 | 431 | | |
432 | 432 | | |
433 | | - | |
434 | | - | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
435 | 439 | | |
436 | 440 | | |
437 | 441 | | |
438 | 442 | | |
439 | 443 | | |
440 | 444 | | |
441 | 445 | | |
442 | | - | |
443 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
444 | 449 | | |
445 | 450 | | |
446 | 451 | | |
| |||
465 | 470 | | |
466 | 471 | | |
467 | 472 | | |
| 473 | + | |
| 474 | + | |
468 | 475 | | |
469 | 476 | | |
470 | 477 | | |
| |||
490 | 497 | | |
491 | 498 | | |
492 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
493 | 515 | | |
494 | 516 | | |
495 | 517 | | |
| |||
564 | 586 | | |
565 | 587 | | |
566 | 588 | | |
567 | | - | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
568 | 595 | | |
569 | 596 | | |
570 | 597 | | |
| |||
616 | 643 | | |
617 | 644 | | |
618 | 645 | | |
| 646 | + | |
619 | 647 | | |
620 | 648 | | |
621 | 649 | | |
| |||
1299 | 1327 | | |
1300 | 1328 | | |
1301 | 1329 | | |
1302 | | - | |
| 1330 | + | |
1303 | 1331 | | |
1304 | 1332 | | |
1305 | 1333 | | |
| |||
1308 | 1336 | | |
1309 | 1337 | | |
1310 | 1338 | | |
1311 | | - | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
1312 | 1342 | | |
1313 | 1343 | | |
1314 | 1344 | | |
| |||
1754 | 1784 | | |
1755 | 1785 | | |
1756 | 1786 | | |
| 1787 | + | |
1757 | 1788 | | |
1758 | 1789 | | |
1759 | 1790 | | |
| |||
1778 | 1809 | | |
1779 | 1810 | | |
1780 | 1811 | | |
| 1812 | + | |
| 1813 | + | |
| 1814 | + | |
| 1815 | + | |
| 1816 | + | |
| 1817 | + | |
| 1818 | + | |
1781 | 1819 | | |
1782 | 1820 | | |
1783 | 1821 | | |
| |||
1801 | 1839 | | |
1802 | 1840 | | |
1803 | 1841 | | |
| 1842 | + | |
1804 | 1843 | | |
1805 | 1844 | | |
1806 | 1845 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
291 | 291 | | |
292 | 292 | | |
293 | 293 | | |
294 | | - | |
295 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
296 | 298 | | |
297 | 299 | | |
298 | 300 | | |
| |||
506 | 508 | | |
507 | 509 | | |
508 | 510 | | |
| 511 | + | |
| 512 | + | |
509 | 513 | | |
510 | | - | |
511 | 514 | | |
512 | 515 | | |
513 | 516 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1529 | 1529 | | |
1530 | 1530 | | |
1531 | 1531 | | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
| 1568 | + | |
| 1569 | + | |
| 1570 | + | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
| 1574 | + | |
| 1575 | + | |
| 1576 | + | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 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 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
0 commit comments