Compile, optimize, estimate¶
Lowering a graph to one ANE program, the accuracy-preserving autotuner, and the
measurement-free cost model. All are reached from the top level (af.compile, af.tune,
af.estimate, ...).
aneforge - a graph->compile->run frontend for the Apple Neural Engine. fp16 compute over the unentitled Espresso e5rt runtime; see docs/developer/overview.md.
Model ¶
A compiled, fused ANE program. Call it with the input array(s), in af.input order.
Source code in aneforge/_compile.py
SegmentedModel ¶
A compiled plan: e5rt program segments interleaved with native-ANE sub-program calls (NETPLIST_OPS).
Source code in aneforge/_compile.py
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 | |
PrecisionWarning ¶
CrossChipFP16Warning ¶
Bases: UserWarning
Emitted by cross_compile_check when a graph compiles for a different-family target but an op's fp16 value can diverge.
DispatchFloorWarning ¶
CompileBackoffError ¶
compile ¶
compile(out: Tensor, int8: bool = False, build_dir=None, opt: 'str | int | None' = 'routes', compress: str | None = None, compress_atol: float = 0.05, block_size: int = 32, validate: bool = False, target=None, _check_precision: bool = True)
Lower out into ONE fused ANE program (or a segmented plan if it has af.sdpa nodes).
Source code in aneforge/_compile.py
tune ¶
tune(out, budget: int = 8, inputs=None, prune_factor: float = 1.5, reps: int = 20, atol: float = _ACCURACY_TOL, min_lossy_speedup: float = _MIN_LOSSY_SPEEDUP, verbose: bool = False, target_error: float | None = None)
Return the fastest CORRECT compiled Model for out (enumerate, prune, measure, validate, cache); target_error switches to the precision-aware path.
Source code in aneforge/_optimize.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 | |
tune_precision ¶
tune_precision(out, target_error: float | None = None, cost_budget_us: float | None = None, inputs=None, reps: int = 20, verbose: bool = False)
Precision-aware tune: select the numerics-aware rewrite set under an explicit error or cost budget, returning (model, report).
Source code in aneforge/_optimize.py
estimate ¶
Estimate the compiled latency (us) of the graph rooted at out; target switches to the analytic per-chip model.
Source code in aneforge/_cost.py
estimate_provenance ¶
Is estimate(out, target=...) silicon-anchored or extrapolated for target?
Source code in aneforge/_cost.py
project_peak ¶
Measurement-free fp16 peak projection for any ANE target, anchored to measured M1.
Source code in aneforge/_cost.py
precision_risk ¶
Heuristic fp16-cancellation risk for the graph rooted at out: {graph_error, nodes, hotspots}.