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(pmap(f))` causes inefficient behavior

See original GitHub issue

Combining jit with pmap produces some undesirable and surprising behaviors.

As one example, any lazy intermediate constants used by the function get instantiated and copied to every device. For instance:

@jax.jit
@jax.pmap
def foo(x):
  z = jnp.zeros((500_000_000,))
  return jax.lax.tie_in(z, x)

foo(jnp.arange(16).reshape((8, 2)))

This causes 2GB of data to be allocated on each device (and, right now, if this is the only computation you run, this can be verified by looking at list(list(jax.pxla.parallel_callable.__closure__[1].cell_contents.items())[0][1].values())[-1][0].__closure__[0].cell_contents, but that might break).

Relatedly, the jit causes the return value to be copied back to a single host instead of staying as a ShardedDeviceArray.

Ideally, adding jit would not make behavior worse. But having a warning when such a situation occurs would also be useful here, since pmap on its own does the right thing.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jakevdpcommented, May 18, 2022

Good idea - I updated some of the documentation in #10757

1reaction
mkuneschcommented, Aug 12, 2021

Since the original issue has been addressed by #3426 and there is a warning for jit of pmap now I’ll close this issue. Please feel free to reopen or file a new issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

JAX Frequently Asked Questions (FAQ)
JAX code is Just-In-Time (JIT) compiled.​​ Keep in mind that the first time you run JAX code, it will be slower because it...
Read more >
Troubleshooting and tips — Numba 0.50.1 documentation
The compiled code is too slow¶. The most common reason for slowness of a compiled JIT function is that compiling in nopython mode...
Read more >
Possible to use `pmap` within likelihood computation?
I get the Using jit-of-pmap can lead to inefficient data movement warning with the pmap 'd HMC version and run about 4x slower...
Read more >
Chapter 2—How Stimulants Affect the Brain and Behavior
In addition, stimulant use causes the brain to release norepinephrine, ... Combining PET with the radiotracer [ 18F]-fluorodeoxyglucose—which is used to ...
Read more >
Performance Tips · The Julia Language
This makes it difficult for the compiler to optimize code using global variables. ... @elapsed f(x)) julia> map(fmt, [copy_cols, copy_rows, copy_col_row, ...
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