framework-integrations
Use optional einops backends, Array API functions, framework layers, EinMix, and framework-specific diagnostics without overclaiming accelerator support.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- framework-integrations
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use optional einops backends, Array API functions, framework layers, EinMix, and framework-specific diagnostics without overclaiming accelerator support.
- disable-model-invocation
- true
02 资源文件 5
- 参考文档references/backends-and-array-api.md6.0 KB
- 参考文档references/layers-and-einmix.md6.0 KB
- 参考文档references/troubleshooting.md5.9 KB
- 脚本scripts/array_api_smoke.py7.4 KB
- 脚本scripts/layer_smoke.py11.6 KB
03 SKILL.md 正文
Framework Integrations
Use this sub-skill when a task asks how einops works with tensor libraries,
Array API objects, framework layers, EinMix, torch scripting/compilation, or
missing optional backend diagnostics. Core shape recipes stay in
tensor-operations; named einsum, pack,
and unpack stay in
named-einsum-and-packing.
When To Load
- A user has a NumPy, PyTorch, TensorFlow/Keras, JAX, CuPy, Paddle, OneFlow,
PyTensor, MLX, tinygrad, or Array API tensor and wants the right
einopsentry point. - A user asks whether
einopssupports a backend, symbolic tensors, framework layers, gradients, tracing, scripting, ortorch.compile. - A user wants
einops.layers.torch.Rearrange,einops.layers.tensorflow.Reduce, Flax modules, Paddle/OneFlow layers, orEinMixin model code. - A user hits
Tensor type unknown to einops, missing optional framework imports, Keras serialization questions, Array API limitations, or accelerator confusion.
Boundary Rules
Stay here for framework integration. Route away for:
- Plain reshapes, reductions, repeats,
parse_shape, and pattern grammar:tensor-operations. - Named-axis contractions or reversible packing:
named-einsum-and-packing. - Repository CI, package tests, notebook/docs checks, or release workflows:
repo-development.
Operational Guidance
-
Start from the public package install:
pip install einopseinopsitself declares no runtime dependencies. Install tensor frameworks separately, in versions appropriate for the user's project. -
Import the framework before passing its tensors to
einops. Backends are lazy and are only registered when their framework module is already imported.import torch from einops import rearrange x = torch.randn(2, 3, 4) y = rearrange(x, "batch channel time -> batch time channel") -
Use the regular top-level functions for most tensor objects. Use
einops.array_apionly when the tensor follows the Python Array API standard and exposes__array_namespace__. -
In model definitions, prefer framework layers when the transform should be a serializable or traceable layer:
from einops.layers.torch import Rearrange, Reduce -
Use
EinMixwhen a linear layer plus rearrangement/einsum weight management is the real abstraction, not merely when a simple reshape is needed. -
Treat accelerator support honestly.
einopsdelegates tensor computation to the installed framework. A CPU smoke check proves pattern logic, not CUDA, ROCm, MPS, or vendor accelerator runtime.
Reference Map
references/backends-and-array-api.md: supported backend names, lazy dispatch model, Array API variants, optional dependency policy, and accelerator honesty.references/layers-and-einmix.md: layer imports, framework-specific constructor patterns,EinMixsignatures, restrictions, and model recipes.references/troubleshooting.md: missing optional dependencies, unknown tensor type, Array API problems, TensorFlow layer-version notes, torch compile/script behavior, andEinMixerrors.scripts/array_api_smoke.py: safe Array API diagnostic adapted from repository tests; runs with NumPy 2.x by default.scripts/layer_smoke.py: safe layer/EinMixdiagnostic with pure-Python default checks and optional framework probes.
Quick Diagnostics
Check a framework tensor failure:
import torch # or tensorflow, jax.numpy, cupy, paddle, oneflow, pytensor, mlx.core
from einops import rearrange
# If this still raises "Tensor type unknown to einops", inspect the tensor type
# and whether the framework import matches the object being passed.
Run bundled checks after installing public dependencies:
python sub-skills/framework-integrations/scripts/array_api_smoke.py --help
python sub-skills/framework-integrations/scripts/array_api_smoke.py
python sub-skills/framework-integrations/scripts/layer_smoke.py --help
python sub-skills/framework-integrations/scripts/layer_smoke.py
python sub-skills/framework-integrations/scripts/layer_smoke.py --framework torch
If an optional framework is absent, the scripts report a clear skip/failure message instead of assuming the source checkout has that framework installed.
Evidence Summary
This sub-skill distills public evidence from README.md, einops/_backends.py,
einops/_torch_specific.py, einops/array_api.py, einops/layers/*,
einops/tests/test_array_api.py, einops/tests/test_layers.py,
einops/tests/test_other.py, and the EinMix tutorial headings and examples.
Installed-package inspection verified core imports and signatures; optional
framework runtime verification is deliberately left to the user's installed
framework environment.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).