بنقرة واحدة
add-handler
Add a precise primitive handler to the jaxpr interpreter, replacing a conservative fallback.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
Add a precise primitive handler to the jaxpr interpreter, replacing a conservative fallback.
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
| name | add-handler |
| description | Add a precise primitive handler to the jaxpr interpreter, replacing a conservative fallback. |
| argument-hint | [primitive-name] |
| disable-model-invocation | true |
$ARGUMENTSAdd a precise propagation handler for the $ARGUMENTS primitive,
replacing the conservative fallback.
Do all research in this step using extended planning mode.
Before writing code:
https://docs.jax.dev/en/latest/_autosummary/jax.lax.$ARGUMENTS.htmlsrc/asdex/detection/_interpret/CLAUDE.md for conventions (docstring style, semantic line breaks, handler structure)src/asdex/detection/_interpret/_commons.py to understand available utilities_pad.py, _transpose.py, _reduce.py) as a referencetests/_interpret/test_internals.py for the primitive (search for $ARGUMENTS)src/asdex/detection/_interpret/__init__.py to see the current dispatch and fallback setupUnderstand the primitive's semantics: how do input and output element indices map to each other? What is the Jacobian structure (permutation, selection, block-diagonal, etc.)?
src/asdex/detection/_interpret/_$ARGUMENTS.py with prop_$ARGUMENTS(eqn, state_indices),
which mutates state_indices in place (returns None)._interpret/CLAUDE.md.state_consts
(see _propagate_const_unary / _propagate_const_binary in _commons.py)
so downstream handlers can stay precise.[] to the output variable and return early,
before any coordinate-mapping logic that would crash on zero-sized shapes.In src/asdex/detection/_interpret/__init__.py:
case "$ARGUMENTS": branch in _prop_dispatch calling the handler"$ARGUMENTS" is listed in the conservative fallback case group, remove it.
(Primitives not listed there currently hit the case _: _prop_throw_error default,
so there is nothing to remove.)In tests/_interpret/test_internals.py:
np.ones) to the precise pattern@pytest.mark.fallback marker and TODO commentsCreate tests/_interpret/test_$ARGUMENTS.py with thorough tests:
(3,4) op (3,1))(3,4) not (4,4)) so dimension mix-ups are caughtjnp functions that lower to this primitive)(np.abs(jax.jacobian(f)(x)) > 1e-10) using assert_array_equal.
Choose test functions that avoid local sparsity (e.g. multiply by zero) so the
numerical Jacobian matches the structural pattern.Run in order:
uv run ruff check src/asdex/detection/_interpret/_$ARGUMENTS.py
uv run pytest tests/_interpret/test_$ARGUMENTS.py -v
uv run pytest tests/_interpret/test_internals.py -v
uv run pytest tests/ -x
Reread the JAX docs for the primitive: fetch https://docs.jax.dev/en/latest/_autosummary/jax.lax.$ARGUMENTS.html
Try to break the implementation by testing inputs the handler might not expect:
(3,4) not (4,4)) so that dimension transposition bugs are caught.{i} per element (e.g. from a prior broadcast or reduction) to verify .copy() and set merging behave correctly._conservative_indices() would produce. If the handler silently falls back on any shape the primitive supports, investigate.
If the fallback cannot be fixed immediately, you must add a @pytest.mark.fallback test with a TODO(primitive) comment showing the precise expected pattern.
Catching conservative patterns is extremely valuable for future development.For each new test, verify the expected output by hand or against jax.jacobian.
Update and re-verify the handler if any test reveals a bug.
Review the implementation with fresh eyes and look for opportunities to reduce complexity:
np.arange, np.flip, np.transpose, np.indices, or np.ravel_multi_index,
then index into in_indices in a single list comprehension.
See _rev.py, _reshape.py, _concatenate.py, and _broadcast.py for examples._flat_to_coords, _row_strides, and _numel may no longer be needed.After any change, re-run verification (step 6).
src/asdex/detection/_interpret/CLAUDE.md: add the new module to the file listing