Skip to content

Fix deferred rendering of large PRNG key arrays - #80

Open
sylvesterkaczmarek wants to merge 2 commits into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/deferred-prng-key-repr
Open

Fix deferred rendering of large PRNG key arrays#80
sylvesterkaczmarek wants to merge 2 commits into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/deferred-prng-key-repr

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Fixes #71.

Large typed JAX PRNG-key arrays fail in Treescope's deferred representation path because faster_array_repr() sends them through the NumPy truncation path. Typed PRNG keys deliberately cannot be converted directly to NumPy, so deferred rendering raises TypeError instead of showing the array.

This change detects JAX PRNG-key dtypes and renders their underlying jax.random.key_data() instead. The key data is truncated using the same edge-selection logic as normal arrays, with the implementation-specific key-data dimensions retained in full, then formatted using JAX's dtype=key<...> overlaying: representation. This avoids illegal conversion of the typed key array while preserving its key dtype and visible values.

The normal numeric-array representation path is unchanged.

Regression coverage forces the fast representation path for a typed Threefry key array and verifies that the deferred representation retains the key dtype, ellipsis, and visible edge key data.

Signed-off-by: Sylvester Kaczmarek <assistant@SylvesterKaczmarek.com>
Signed-off-by: Sylvester Kaczmarek <assistant@SylvesterKaczmarek.com>
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.

Large arrays of PRNG keys cannot be deferred

1 participant