计划执行与检查节点
executing-plans
按既定实施计划完成工作,保持过程检查和反馈。
named-einsum-and-packing【效率与协作】Use einops.einsum, pack, and unpack for named-axis contractions and reversible heterogeneous tensor packing.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task needs named-axis tensor contractions or
reversible packing of tensors with heterogeneous middle structure. It covers
einops.einsum, einops.pack, and einops.unpack as public runtime APIs.
PS) through transformer/model flows.packed_shapes.->, tensors-first call order, unsupported
grouped einsum axes, invalid * packing patterns, bad packed_shapes, or
-1 inference.tensor-operations.EinMix and einops.layers.* belong to
sibling sub-skill framework-integrations.repo-development.from einops import einsum, pack, unpack
einsum(*tensors_and_pattern) takes one or more tensors first and the pattern
string last. This is the reverse of numpy.einsum(pattern, *tensors).pack(tensors, pattern) returns (packed_tensor, packed_shapes).unpack(tensor, packed_shapes, pattern) returns a list of tensors.See references/api-reference.md for signatures, parameters, return contracts, limitations, and error behavior.
einsum as einsum(tensor1, tensor2, ..., "axes -> axes").
A non-string last argument is a call-order bug.-> in einsum; implicit-output NumPy-style
shorthand is intentionally rejected.batch, query, head, and
channel. Internally they are compacted to backend single-letter einsum
symbols, but user code should stay named and readable.einsum supports ellipsis and repeated axes on an input term for diagonal or
trace-style operations. It does not support grouped axes like (h w),
singleton (), or anonymous numeric axes like 2.pack/unpack, not manual concatenate/slice/reshape, when tensors have
heterogeneous axes in the packed position or when the inverse split must be
carried safely through later code.*, for example "batch * channel".packed_shapes (PS) next to the packed tensor. Treat it as part of the
data contract, especially across model calls that change only non-packed axes
such as channel -> channel_out.unpack, use at most one -1 across the entire packed_shapes
argument, and validate round trips when shapes are computed dynamically.PS instead of special-cased away.scores = einsum(
queries, keys,
"batch query head channel, batch key head channel -> batch head query key",
)
...) carries arbitrary leading, middle, or trailing dimensions.packed, ps = pack([class_token_bc, image_tokens_bhwc, text_tokens_btc], "batch * channel")
class_out, image_out, text_out = unpack(processed_packed, ps, "batch * channel_out")
* match leading axes of every input.* match trailing axes of every input.PS entry.PS entries are shapes that replace * during unpack; () means the item
contributed one element with no explicit packed axes.Use references/workflows.md for these recipes:
einsum.tensor-operations.packed_shapes.pack([x], "* ...") style flows.PS bookkeeping.Use references/troubleshooting.md for the failure matrix and fixes for common error fragments.
The scripts are deterministic, NumPy-only checks derived from public behavior covered by the repository tests and examples. They do not import repo tests or require a source checkout.
scripts/einsum_smoke.py checks named einsum,
attention, ellipsis, traces, and expected unsupported-syntax errors.scripts/packing_smoke.py checks trivial packing,
heterogeneous round trips, class-token and multimodal flows, multi-output
unpacking, auto-batching, zero-length cases, and expected packing errors.Run from the sub-skill directory or pass the script path explicitly:
python scripts/einsum_smoke.py --help
python scripts/einsum_smoke.py
python scripts/packing_smoke.py --help
python scripts/packing_smoke.py
When a user reports a broken named-axis contraction or packing flow:
einsum) or reversible
shape bookkeeping (pack/unpack). Do not solve a packing problem with a
lossy manual slice unless reversibility is irrelevant.einsum; sequence of
tensors before pattern for pack; packed tensor, PS, then pattern for
unpack.einsum, one-star no-arrow
pattern for pack/unpack.einsum, remove unsupported groups, singletons, and anonymous axes by
doing explicit reshapes or singleton insertion outside einsum.pack/unpack, inspect the PS entries and the product they imply for
the packed axis; then run a minimal round-trip assertion.