Skip to content

perf(typing): replace inspect.stack with bounded frame walk#998

Open
Bartok9 wants to merge 1 commit into
Physical-Intelligence:mainfrom
Bartok9:salvage/openpi-534-stack-walk
Open

perf(typing): replace inspect.stack with bounded frame walk#998
Bartok9 wants to merge 1 commit into
Physical-Intelligence:mainfrom
Bartok9:salvage/openpi-534-stack-walk

Conversation

@Bartok9

@Bartok9 Bartok9 commented Jul 11, 2026

Copy link
Copy Markdown

Summary

  • Replace inspect.stack() in the jaxtyping dataclass annotation patch with a bounded sys._getframe walk (max 20 frames).

Motivation

Deep call stacks make inspect.stack() costly on inference paths. #534 proposed a lighter walk; this rebases that idea onto current main (which already uses .get(\"__name__\") safely).

Salvage of #534 by @dcw02 — rebased to main.

Verification

  • Same skip modules: jax._src.tree_util, flax.nnx.transforms.compilation
  • On frame walk failure, falls through to original typechecking (safe)

Attribution

Salvage of #534 by @dcw02 — rebased to main

Salvage of Physical-Intelligence#534 by @dcw02 — rebased to main.

inspect.stack() is expensive on hot juax typing paths; walk at most 20
frames via sys._getframe while preserving the JAX/Flax skip set.
@jimmyt857 jimmyt857 removed their request for review July 11, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant