Skip to content

canvas_engineering.cortex

Named spatial zones (cortices) for grouping regions that share a preferred local attention backend. When the AttentionDispatcher is constructed with a CortexRegistry, intra-cortex edges substitute the cortex's declared local_backend for the resolved attention fn.

canvas_engineering.cortex.CortexSpec dataclass

Declares a named spatial zone on the canvas.

Parameters:

Name Type Description Default
name str

Unique identifier for this cortex.

required
bounds Tuple[int, ...]

Spatial-temporal extent as flat tuple (t0, t1, s0_lo, s0_hi, ...). Length = 2 + 2 * n_spatial_dims.

(0, 1, 0, 1, 0, 1)
tile Tuple[int, ...]

Preferred tiling per spatial dimension. E.g. (4, 4) for 2D.

(4, 4)
local_backend str

Attention backend for intra-cortex connections. Default "local_attention".

'local_attention'
shared_cache bool

Whether regions in this cortex share a KV cache during inference. Default True.

True

canvas_engineering.cortex.CortexRegistry

Manages cortex assignments for regions.

Regions can be assigned to at most one cortex. The registry tracks which cortex each region belongs to and provides queries for co-located region groups.

cortex_names property

All registered cortex names, sorted.

n_assigned property

Number of regions with cortex assignments.

assign(region, cortex_name)

Assign a region to a cortex.

Raises KeyError if the cortex is not registered. Raises ValueError if the region is already assigned to a different cortex.

cortex_for(region)

Get the cortex assigned to a region, or None.

regions_in(cortex_name)

Get all regions assigned to a cortex, sorted alphabetically.

register(spec)

Register a cortex specification.

Raises ValueError if a cortex with the same name already exists.

same_cortex(a, b)

Check if two regions are in the same cortex.

summary()

Human-readable summary.

unassign(region)

Remove a region's cortex assignment.

unregister(name)

Remove a cortex and all its region assignments.