Budget
Budget management for FLOP counting. BudgetContext is the core context
manager that tracks operation costs and enforces limits.
Quick example
import mechestim as me
# Explicit budget with namespace
with me.BudgetContext(flop_budget=10**7, namespace="forward") as budget:
W = me.ones((256, 256))
x = me.ones((256,))
h = me.einsum('ij,j->i', W, x)
print(f"Used: {budget.flops_used:,} / {budget.flop_budget:,}")
# Session-wide summary across all namespaces
me.budget_summary()
# Programmatic access
data = me.budget_summary_dict()
API Reference
mechestim._budget.BudgetContext
Context manager for FLOP budget enforcement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flop_budget
|
int
|
Maximum number of FLOPs allowed. Must be > 0. |
required |
flop_multiplier
|
float
|
Multiplier applied to all FLOP costs. Default 1. |
1.0
|
Source code in src/mechestim/_budget.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
__call__(func)
deduct(op_name, *, flop_cost, subscripts, shapes)
Deduct FLOPs from the budget.
Source code in src/mechestim/_budget.py
summary()
Return a pretty-printed FLOP budget summary.
Source code in src/mechestim/_budget.py
mechestim._budget.OpRecord
Bases: NamedTuple
Record of a single counted operation.
Source code in src/mechestim/_budget.py
mechestim._budget.budget(flop_budget, flop_multiplier=1.0, quiet=False, namespace=None)
Create a BudgetContext usable as both a context manager and decorator.
Source code in src/mechestim/_budget.py
mechestim._budget.budget_summary_dict(by_namespace=False)
Return aggregated budget data across all recorded contexts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
by_namespace
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with keys |
Source code in src/mechestim/_budget.py
mechestim._budget.budget_reset()
mechestim._display.render_budget_summary()
Return a Rich renderable if Rich is installed, otherwise plain text.
mechestim._display.budget_summary()
Print or return the session-wide budget summary.
Source code in src/mechestim/_display.py
mechestim._display.budget_live()
Return a live-updating budget display context manager.