question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

JIT invariance problem for large Python integers as arguments to function

See original GitHub issue
In [1]: import jax, jax.numpy as jnp

In [2]: jnp.multiply(2 ** 100, 3.)  # doesn't crash
   ...:
WARNING:absl:No GPU/TPU found, falling back to CPU. (Set TF_CPP_MIN_LOG_LEVEL=0 and rerun for more info.)
Out[2]: DeviceArray(3.8029518e+30, dtype=float32)

In [3]: jax.jit(jnp.multiply)(2 ** 100, 3.)
...
OverflowError                             Traceback (most recent call last)
<ipython-input-3-2aed3283764c> in <module>
----> 1 jax.jit(jnp.multiply)(2 ** 100, 3.)

~/p/jax/jax/_src/dtypes.py in _scalar_type_to_dtype(typ, value)
    125   if typ is int and value is not None:
    126     if value < np.iinfo(dtype).min or value > np.iinfo(dtype).max:
--> 127       raise OverflowError(f"Python int {value} too large to convert to {dtype}")
    128   return dtype
    129

OverflowError: Python int 1267650600228229401496703205376 too large to convert to int32

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
jakevdpcommented, May 7, 2021

If we’re going to pursue plan 2, then in this case I think we can leave this issue open for now and reduce churn. This seems like a pretty low-priority JIT invariance case, with an already good error message and a pretty clear fix (manually casting the input to the desired type)

0reactions
jakevdpcommented, Jun 29, 2022

I think the issue has been fixed:

In [1]: import jax, jax.numpy as jnp                                                                                                                                                                                                                                                                            

In [2]: jnp.multiply(2 ** 100, 3.)                                                                                                                                                                                                                                                                              
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-2-b332690c3005> in <module>
----> 1 jnp.multiply(2 ** 100, 3.)

    [... skipping hidden 6 frame]

~/github/google/jax/jax/_src/dtypes.py in _scalar_type_to_dtype(typ, value)
    149   if typ is int and value is not None:
    150     if value < np.iinfo(dtype).min or value > np.iinfo(dtype).max:
--> 151       raise OverflowError(f"Python int {value} too large to convert to {dtype}")
    152   return dtype
    153 

OverflowError: Python int 1267650600228229401496703205376 too large to convert to int32
Read more comments on GitHub >

github_iconTop Results From Across the Web

Python Numba module gives me a wrong answer when using ...
The problem is that for integer representations for numbers, there are upper and lower limits of what can be represented.
Read more >
Automatic parallelization with @jit - Numba
Setting the parallel option for jit() enables a Numba transformation pass that attempts to automatically parallelize and perform other optimizations on (part of) ......
Read more >
PEP 484 – Type Hints - Python Enhancement Proposals
For example, here is a simple function whose argument and return type are ... For example, the type “sequence of integers” can be...
Read more >
Dr.Jit: A Just-In-Time Compiler for Differentiable Rendering
Jit executes a rendering algorithm, it generates a trace: a large graph comprised of arithmetic, loops, ray tracing operations, and polymorphic calls that ......
Read more >
Release Notes — Numba 0.56.4+0.g288a38bbd.dirty-py3.7 ...
Numba imports more quickly in environments with large numbers of packages as it now uses ... List ignores ctor arguments with JIT disabled...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found